SHOW:
|
|
- or go back to the newest paste.
| 1 | #include <sourcemod> | |
| 2 | #include <sdktools> | |
| 3 | ||
| 4 | #define MAXLIST 11 | |
| 5 | ||
| 6 | #pragma newdecls required | |
| 7 | #pragma semicolon 1 | |
| 8 | ||
| 9 | static bool ignoreNextDamageDealt[MAXPLAYERS+1] = false; | |
| 10 | ||
| 11 | static const char gModelsItemsList[MAXLIST][] = | |
| 12 | {
| |
| 13 | "models/weapons/melee/v_katana.mdl", //0 | |
| 14 | "models/weapons/melee/v_fireaxe.mdl", //1 | |
| 15 | "models/weapons/melee/v_machete.mdl", //2 | |
| 16 | "models/weapons/melee/v_crowbar.mdl", //3 | |
| 17 | "models/v_models/v_knife_t.mdl", //4 | |
| 18 | "models/weapons/melee/v_frying_pan.mdl", //5 | |
| 19 | "models/weapons/melee/v_bat.mdl", //6 | |
| 20 | "models/weapons/melee/v_cricket_bat.mdl", //7 | |
| 21 | "models/weapons/melee/v_tonfa.mdl", //8 | |
| 22 | "models/weapons/melee/v_electric_guitar.mdl", //9 | |
| 23 | "models/weapons/melee/v_golfclub.mdl" //10 | |
| 24 | }; | |
| 25 | ||
| 26 | static const char gGeneralMelee[MAXLIST - 6][] = | |
| 27 | {
| |
| 28 | "katana", | |
| 29 | "fireaxe", | |
| 30 | "machete", | |
| 31 | "crowbar", | |
| 32 | "knife" | |
| 33 | }; | |
| 34 | ||
| 35 | static const float gMeleeModifier[MAXLIST - 5] = | |
| 36 | {
| |
| 37 | 1.0, | |
| 38 | 1.0, | |
| 39 | 0.99, | |
| 40 | 0.9, | |
| 41 | 0.7, | |
| 42 | 0.6 | |
| 43 | }; | |
| 44 | ||
| 45 | public void OnPluginStart() | |
| 46 | {
| |
| 47 | HookEvent("infected_hurt", iInfectedHurt);
| |
| 48 | } | |
| 49 | ||
| 50 | public Action iInfectedHurt(Event event, const char[] name, bool dontBroadcast) | |
| 51 | {
| |
| 52 | char weaponname[56]; | |
| 53 | ||
| 54 | int attacker = GetClientOfUserId(event.GetInt("attacker"));
| |
| 55 | int entity = event.GetInt("entityid");
| |
| 56 | ||
| 57 | if (!attacker || !IsValidEntity(entity) || ignoreNextDamageDealt[attacker]) return; | |
| 58 | ||
| 59 | int dmg_health = GetEventInt(event,"amount"); | |
| 60 | int eventhealth = GetEntProp(entity, Prop_Data, "m_iHealth"); | |
| 61 | int damagedelta; | |
| 62 | ||
| 63 | int iCurrentWeapon = GetEntPropEnt(attacker, Prop_Send, "m_hActiveWeapon"); | |
| 64 | ||
| 65 | if(!IsValidEntity(iCurrentWeapon)) return; | |
| 66 | ||
| 67 | GetEntityClassname(iCurrentWeapon, weaponname, sizeof(weaponname)); | |
| 68 | - | if (strcmp(weaponname, "weapon_melee") == 0) |
| 68 | + | if (strcmp(weaponname, "weapon_melee") != 0) return; |
| 69 | - | GetEntPropString(iCurrentWeapon, Prop_Data, "m_strMapSetScriptName", weaponname, sizeof(weaponname)); |
| 69 | + | |
| 70 | ||
| 71 | - | if(!weaponname[0]) |
| 71 | + | char ModelName[128], sExplodeString[MAXLIST - 6][36]; |
| 72 | int iNum; | |
| 73 | - | char ModelName[128], sExplodeString[MAXLIST - 6][36]; |
| 73 | + | for(int i; i < MAXLIST; i++) |
| 74 | - | int iNum; |
| 74 | + | |
| 75 | - | GetEntPropString(iCurrentWeapon, Prop_Data, "m_ModelName", ModelName, sizeof ModelName); |
| 75 | + | if(strcmp(ModelName, gModelsItemsList[i]) == 0) |
| 76 | - | for(int i; i < MAXLIST; i++) |
| 76 | + | |
| 77 | iNum = ExplodeString(gModelsItemsList[i], "/", sExplodeString, sizeof sExplodeString, sizeof sExplodeString[]); | |
| 78 | - | if(strcmp(ModelName, gModelsItemsList[i]) == 0) |
| 78 | + | ReplaceString(sExplodeString[iNum - 1], sizeof sExplodeString[], "v_", ""); |
| 79 | - | {
|
| 79 | + | if(StrContains(sExplodeString[iNum - 1], "knife") > 0) |
| 80 | - | iNum = ExplodeString(gModelsItemsList[i], "/", sExplodeString, sizeof sExplodeString, sizeof sExplodeString[]); |
| 80 | + | ReplaceString(sExplodeString[iNum - 1], sizeof sExplodeString[], "_t.mdl", ""); |
| 81 | - | ReplaceString(sExplodeString[iNum - 1], sizeof sExplodeString[], "v_", ""); |
| 81 | + | else |
| 82 | - | if(StrContains(sExplodeString[iNum - 1], "knife") > 0) |
| 82 | + | ReplaceString(sExplodeString[iNum - 1], sizeof sExplodeString[], ".mdl", ""); |
| 83 | - | ReplaceString(sExplodeString[iNum - 1], sizeof sExplodeString[], "_t.mdl", ""); |
| 83 | + | TrimString(sExplodeString[iNum - 1]); |
| 84 | - | else |
| 84 | + | Format(weaponname, sizeof weaponname, "%s", sExplodeString[iNum - 1]); |
| 85 | - | ReplaceString(sExplodeString[iNum - 1], sizeof sExplodeString[], ".mdl", ""); |
| 85 | + | |
| 86 | - | TrimString(sExplodeString[iNum - 1]); |
| 86 | + | |
| 87 | - | Format(weaponname, sizeof weaponname, "%s", sExplodeString[iNum - 1]); |
| 87 | + | |
| 88 | - | break; |
| 88 | + | |
| 89 | - | } |
| 89 | + | |
| 90 | ||
| 91 | for(int i; i < 5; i++) | |
| 92 | {
| |
| 93 | if(strcmp(weaponname, gGeneralMelee[i]) == 0) | |
| 94 | {
| |
| 95 | damagedelta = RoundToNearest((dmg_health * gMeleeModifier[i]) - dmg_health); | |
| 96 | break; | |
| 97 | } | |
| 98 | } | |
| 99 | ||
| 100 | if(damagedelta > 0) | |
| 101 | applyDamage(damagedelta, entity, attacker); | |
| 102 | else | |
| 103 | {
| |
| 104 | int health = eventhealth - damagedelta; | |
| 105 | ||
| 106 | if (health < 1) | |
| 107 | {
| |
| 108 | damagedelta += (health - 1); | |
| 109 | health = 1; | |
| 110 | } | |
| 111 | SetEntProp(entity, Prop_Data, "m_iHealth", health); | |
| 112 | SetEventInt(event, "amount", damagedelta); | |
| 113 | } | |
| 114 | } | |
| 115 | ||
| 116 | static void applyDamage(int damage, int victim, int attacker) | |
| 117 | {
| |
| 118 | Handle dataPack = CreateDataPack(); | |
| 119 | WritePackCell(dataPack, damage); | |
| 120 | WritePackCell(dataPack, victim); | |
| 121 | WritePackCell(dataPack, attacker); | |
| 122 | ||
| 123 | CreateTimer(0.1, timer_stock_applyDamage, dataPack); | |
| 124 | ignoreNextDamageDealt[attacker] = true; | |
| 125 | CreateTimer(0.2, timer_resetStop, attacker); | |
| 126 | } | |
| 127 | ||
| 128 | public Action timer_resetStop(Handle timer, any client) | |
| 129 | {
| |
| 130 | ignoreNextDamageDealt[client] = false; | |
| 131 | } | |
| 132 | ||
| 133 | public Action timer_stock_applyDamage(Handle timer, Handle dataPack) | |
| 134 | {
| |
| 135 | ResetPack(dataPack); | |
| 136 | int damage = ReadPackCell(dataPack); | |
| 137 | int victim = ReadPackCell(dataPack); | |
| 138 | int attacker = ReadPackCell(dataPack); | |
| 139 | CloseHandle(dataPack); | |
| 140 | ||
| 141 | float victimPos[3]; char strDamage[16], strDamageTarget[16]; | |
| 142 | ||
| 143 | if (victim < 20 && IsClientInGame(victim)) | |
| 144 | {
| |
| 145 | GetClientEyePosition(victim, victimPos); | |
| 146 | } | |
| 147 | else if (IsValidEntity(victim)) | |
| 148 | {
| |
| 149 | GetEntityAbsOrigin(victim, victimPos); | |
| 150 | } | |
| 151 | else return; | |
| 152 | ||
| 153 | IntToString(damage, strDamage, sizeof(strDamage)); | |
| 154 | Format(strDamageTarget, sizeof(strDamageTarget), "hurtme%d", victim); | |
| 155 | ||
| 156 | int entPointHurt = CreateEntityByName("point_hurt");
| |
| 157 | if(!entPointHurt) return; | |
| 158 | ||
| 159 | DispatchKeyValue(victim, "targetname", strDamageTarget); | |
| 160 | DispatchKeyValue(entPointHurt, "DamageTarget", strDamageTarget); | |
| 161 | DispatchKeyValue(entPointHurt, "Damage", strDamage); | |
| 162 | DispatchKeyValue(entPointHurt, "DamageType", "0"); | |
| 163 | DispatchSpawn(entPointHurt); | |
| 164 | ||
| 165 | TeleportEntity(entPointHurt, victimPos, NULL_VECTOR, NULL_VECTOR); | |
| 166 | AcceptEntityInput(entPointHurt, "Hurt", (attacker && attacker < 20 && IsClientInGame(attacker)) ? attacker : -1); | |
| 167 | ||
| 168 | DispatchKeyValue(entPointHurt, "classname", "point_hurt"); | |
| 169 | DispatchKeyValue(victim, "targetname", "null"); | |
| 170 | AcceptEntityInput(entPointHurt, "kill"); | |
| 171 | } | |
| 172 | stock void GetEntityAbsOrigin( int entity, float origin[3]) | |
| 173 | {
| |
| 174 | if (entity > 0 && IsValidEntity(entity)) | |
| 175 | {
| |
| 176 | float mins[3], maxs[3]; | |
| 177 | GetEntPropVector(entity,Prop_Send,"m_vecOrigin",origin); | |
| 178 | GetEntPropVector(entity,Prop_Send,"m_vecMins",mins); | |
| 179 | GetEntPropVector(entity,Prop_Send,"m_vecMaxs",maxs); | |
| 180 | ||
| 181 | origin[0] += (mins[0] + maxs[0]) * 0.5; | |
| 182 | origin[1] += (mins[1] + maxs[1]) * 0.5; | |
| 183 | origin[2] += (mins[2] + maxs[2]) * 0.5; | |
| 184 | } | |
| 185 | } |