Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- namespace Oxide.Plugins
- {
- [Info("EmptyPlugin", "Vlad-00003", "1.0.0")]
- [Description("Testing plugin")]
- /*
- * Author info:
- * E-mail: Vlad-00003@mail.ru
- * Vk: vk.com/vlad_00003
- * Русский текст для поддержки юникода. Иногда студия меняет кодировку в случае,
- * если нет неподдерживаемых ASCII символов.
- */
- internal class EmptyPlugin : RustPlugin
- {
- private void OnEntityDeath(BaseEntity ent, HitInfo info)
- {
- if (info == null || !(ent is BuildingBlock))
- return;
- PrintWarning("Ent {0} died. Weapon: {1}", ent, GetWeaponInfo(info));
- }
- private readonly Dictionary<string, string> _entityToItem = new Dictionary<string, string>();
- private void OnServerInitialized()
- {
- foreach (var def in ItemManager.GetItemDefinitions())
- {
- var projectile = def.GetComponent<ItemModProjectile>();
- if (projectile != null) //Объект, который создаётся при броске\выстреле. Ракеты\пули тут.
- {
- //У hammer есть projectileObject, но он null. Не спрашивай.
- if(projectile.projectileObject.isValid)
- _entityToItem[projectile.projectileObject.resourcePath] = def.shortname;
- }
- //У оружия ближнего боя есть и HeldEntity и Projectile, т.к. их можно метать. Нам нужны оба варианта
- var modEntity = def.GetComponent<ItemModEntity>();
- if (modEntity == null)
- continue;
- // Это HeldEntity. При ударе в ближнем бою, без броска - используется именно он. Хотя при таком ударе мы всё ещё получаем Item через AttackEntity
- _entityToItem[modEntity.entityPrefab.resourcePath] = def.shortname;
- //Исключительно взрывчатка и, почему-то, fun.casetterecorder
- var thrown = GameManager.server.FindPrefab(modEntity.entityPrefab.resourcePath).GetComponent<ThrownWeapon>();
- if (thrown)
- _entityToItem[thrown.prefabToThrow.resourcePath] = def.shortname;
- }
- }
- private string GetWeaponInfo(HitInfo hitInfo)
- {
- //Заглушка. Предмет всё равно есть в словаре, но если можно вытащить из предмета - зачем лезть в словарь?
- var weaponItem = hitInfo.Weapon?.GetCachedItem();
- if (weaponItem != null)
- return weaponItem.info.shortname;
- //Хотя у нас всё равно есть словарь, так что можно и удалить строки выше
- string shortName;
- if (_entityToItem.TryGetValue(hitInfo.WeaponPrefab.PrefabName, out shortName))
- {
- return shortName;
- }
- return string.Empty;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement