FlacoBey

Untitled

Jan 9th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.10 KB | None | 0 0
  1. #pragma semicolon 1
  2. #include <sourcemod>
  3. #include <sdktools>
  4.  
  5. static Handle:trieModdedWeapons                     =   INVALID_HANDLE;
  6.  
  7. static      damageModEnabled                        =   1;
  8. static      damageModEnabledForCI                   =   1;
  9. static bool:ignoreNextDamageDealt[MAXPLAYERS+1]     =   false;
  10.  
  11. public OnPluginStart()
  12. {
  13.     RegAdminCmd("sm_damage_weaponmulti", CmdSetWeaponMultiplier, ADMFLAG_CHEATS);
  14.     HookEvent("infected_hurt", _DM_InfectedHurt_Event);
  15.     trieModdedWeapons = CreateTrie();
  16. }
  17.  
  18. public Action:_DM_InfectedHurt_Event(Handle:event, const String:name[], bool:dontBroadcast)
  19. {
  20.     decl Float:multiplierWeapon, String:weaponname[64];
  21.    
  22.     new attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
  23.     new entity = (GetEventInt(event, "entityid"));
  24.    
  25.     if (!attacker || !IsValidEntity(entity) || ignoreNextDamageDealt[attacker]) return;
  26.    
  27.     decl String:entname[32];
  28.     GetEdictClassname(entity, entname, sizeof(entname));
  29.    
  30.     new dmg_health = GetEventInt(event,"amount");
  31.     new eventhealth = GetEntProp(entity, Prop_Data, "m_iHealth");
  32.     new damagedelta;
  33.    
  34.     if (dmg_health < 1 || eventhealth < 1) return;
  35.    
  36.     GetClientWeapon(attacker, weaponname, sizeof(weaponname));
  37.    
  38.     if (StrEqual(weaponname, "weapon_melee"))
  39.     {
  40.         if (StrEqual(entname, "infected", false) && !damageModEnabledForCI) return;
  41.    
  42.         GetEntPropString(GetPlayerWeaponSlot(attacker, 1), Prop_Data, "m_strMapSetScriptName", weaponname, sizeof(weaponname));
  43.     }
  44.    
  45.     if(GetTrieValue(trieModdedWeapons, weaponname, multiplierWeapon))
  46.     {
  47.         damagedelta = RoundToNearest((dmg_health * multiplierWeapon) - dmg_health);
  48.        
  49.         switch (damagedelta > 0)
  50.         {
  51.             case true:
  52.             {
  53.                 applyDamage(damagedelta, entity, attacker);
  54.             }
  55.             case false:
  56.             {
  57.                 new health = eventhealth - damagedelta;
  58.            
  59.                 if (health < 1)
  60.                 {
  61.                     damagedelta += (health - 1);
  62.                     health = 1;
  63.                 }
  64.                
  65.                 SetEntProp(entity, Prop_Data, "m_iHealth", health);
  66.                 SetEventInt(event, "amount", damagedelta);
  67.                
  68.             }
  69.         }
  70.     }
  71. }
  72.  
  73. public Action:CmdSetWeaponMultiplier(client, args)
  74. {
  75.     if (!damageModEnabled) return Plugin_Handled;
  76.    
  77.     decl String:weapon[64], String:multiplier[20];
  78.    
  79.     if (args == 2)
  80.     {
  81.         GetCmdArg(1, weapon, sizeof(weapon));
  82.         GetCmdArg(2, multiplier, sizeof(multiplier));
  83.        
  84.         SetTrieValue(trieModdedWeapons, weapon, StringToFloat(multiplier));
  85.         ReplyToCommand(client, "Successfully set damage of weapon: %s to %.2f!", weapon, StringToFloat(multiplier));
  86.     }
  87.     else if (client)
  88.     {
  89.         decl String:weaponname[64];
  90.         GetClientWeapon(client, weaponname, sizeof(weaponname));
  91.        
  92.         if (StrEqual(weaponname, "weapon_melee"))
  93.         {
  94.             GetEntPropString(GetPlayerWeaponSlot(client, 1), Prop_Data, "m_strMapSetScriptName", weaponname, sizeof(weaponname));
  95.         }
  96.        
  97.         ReplyToCommand(client,"Usage: sm_damage_weapon <weapon> <multiplier> - your current weapon is %s", weaponname);
  98.     }
  99.     else ReplyToCommand(client,"Usage: sm_damage_weapon <weapon> <multiplier>");
  100.    
  101.     return Plugin_Handled;
  102. }
  103.  
  104. static applyDamage(damage, victim, attacker)
  105. {
  106.     new Handle:dataPack = CreateDataPack();
  107.     WritePackCell(dataPack, damage);  
  108.     WritePackCell(dataPack, victim);
  109.     WritePackCell(dataPack, attacker);
  110.    
  111.     CreateTimer(0.1, timer_stock_applyDamage, dataPack);
  112.     ignoreNextDamageDealt[attacker] = true;
  113.     CreateTimer(0.2, timer_resetStop, attacker);
  114. }
  115.  
  116. public Action:timer_resetStop(Handle:timer, any:client)
  117. {
  118.     ignoreNextDamageDealt[client] = false;
  119. }
  120.  
  121. public Action:timer_stock_applyDamage(Handle:timer, Handle:dataPack)
  122. {
  123.     ResetPack(dataPack);
  124.     new damage = ReadPackCell(dataPack);  
  125.     new victim = ReadPackCell(dataPack);
  126.     new attacker = ReadPackCell(dataPack);
  127.     CloseHandle(dataPack);  
  128.  
  129.     decl Float:victimPos[3], String:strDamage[16], String:strDamageTarget[16];
  130.    
  131.     if (victim < 20 && IsClientInGame(victim))
  132.     {
  133.         GetClientEyePosition(victim, victimPos);
  134.     }
  135.     else if (IsValidEntity(victim))
  136.     {
  137.         GetEntityAbsOrigin(victim, victimPos);
  138.     }
  139.     else return;
  140.    
  141.     IntToString(damage, strDamage, sizeof(strDamage));
  142.     Format(strDamageTarget, sizeof(strDamageTarget), "hurtme%d", victim);
  143.    
  144.     new entPointHurt = CreateEntityByName("point_hurt");
  145.     if(!entPointHurt) return;
  146.  
  147.     DispatchKeyValue(victim, "targetname", strDamageTarget);
  148.     DispatchKeyValue(entPointHurt, "DamageTarget", strDamageTarget);
  149.     DispatchKeyValue(entPointHurt, "Damage", strDamage);
  150.     DispatchKeyValue(entPointHurt, "DamageType", "0");
  151.     DispatchSpawn(entPointHurt);
  152.  
  153.     TeleportEntity(entPointHurt, victimPos, NULL_VECTOR, NULL_VECTOR);
  154.     AcceptEntityInput(entPointHurt, "Hurt", (attacker && attacker < 20 && IsClientInGame(attacker)) ? attacker : -1);
  155.  
  156.     DispatchKeyValue(entPointHurt, "classname", "point_hurt");
  157.     DispatchKeyValue(victim, "targetname", "null");
  158.     RemoveEdict(entPointHurt);
  159. }
  160.  
  161. stock GetEntityAbsOrigin(entity,Float:origin[3])
  162. {
  163.     if (entity > 0 && IsValidEntity(entity))
  164.     {
  165.         decl Float:mins[3], Float:maxs[3];
  166.         GetEntPropVector(entity,Prop_Send,"m_vecOrigin",origin);
  167.         GetEntPropVector(entity,Prop_Send,"m_vecMins",mins);
  168.         GetEntPropVector(entity,Prop_Send,"m_vecMaxs",maxs);
  169.        
  170.         origin[0] += (mins[0] + maxs[0]) * 0.5;
  171.         origin[1] += (mins[1] + maxs[1]) * 0.5;
  172.         origin[2] += (mins[2] + maxs[2]) * 0.5;
  173.     }
  174. }
Advertisement
Add Comment
Please, Sign In to add comment