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][] = |
| 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] = |
| 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 | - | |
| 66 | + | |
| 67 | GetEntityClassname(iCurrentWeapon, weaponname, sizeof(weaponname)); | |
| 68 | - | if (strcmp(weaponname, "weapon_melee") != 0) return; |
| 68 | + | if (strcmp(weaponname, "weapon_melee") == 0) |
| 69 | - | |
| 69 | + | GetEntPropString(iCurrentWeapon, Prop_Data, "m_strMapSetScriptName", weaponname, sizeof weaponname); |
| 70 | - | |
| 70 | + | else return; |
| 71 | - | char ModelName[128], sExplodeString[MAXLIST - 6][36]; |
| 71 | + | |
| 72 | - | int iNum; |
| 72 | + | |
| 73 | - | for(int i; i < MAXLIST; i++) |
| 73 | + | if(weaponname[0] == 0) |
| 74 | {
| |
| 75 | - | if(strcmp(ModelName, gModelsItemsList[i]) == 0) |
| 75 | + | char ModelName[128], sExplodeString[MAXLIST - 6][36]; |
| 76 | int iNum; | |
| 77 | - | iNum = ExplodeString(gModelsItemsList[i], "/", sExplodeString, sizeof sExplodeString, sizeof sExplodeString[]); |
| 77 | + | for(int i; i < MAXLIST; i++) |
| 78 | - | ReplaceString(sExplodeString[iNum - 1], sizeof sExplodeString[], "v_", ""); |
| 78 | + | {
|
| 79 | - | if(StrContains(sExplodeString[iNum - 1], "knife") > 0) |
| 79 | + | if(strcmp(ModelName, gModelsItemsList[i]) == 0) |
| 80 | - | ReplaceString(sExplodeString[iNum - 1], sizeof sExplodeString[], "_t.mdl", ""); |
| 80 | + | {
|
| 81 | - | else |
| 81 | + | iNum = ExplodeString(gModelsItemsList[i], "/", sExplodeString, sizeof sExplodeString, sizeof sExplodeString[]); |
| 82 | - | ReplaceString(sExplodeString[iNum - 1], sizeof sExplodeString[], ".mdl", ""); |
| 82 | + | ReplaceString(sExplodeString[iNum - 1], sizeof sExplodeString[], "v_", ""); |
| 83 | - | TrimString(sExplodeString[iNum - 1]); |
| 83 | + | if(StrContains(sExplodeString[iNum - 1], "knife") > 0) |
| 84 | - | Format(weaponname, sizeof weaponname, "%s", sExplodeString[iNum - 1]); |
| 84 | + | ReplaceString(sExplodeString[iNum - 1], sizeof sExplodeString[], "_t.mdl", ""); |
| 85 | else | |
| 86 | ReplaceString(sExplodeString[iNum - 1], sizeof sExplodeString[], ".mdl", ""); | |
| 87 | TrimString(sExplodeString[iNum - 1]); | |
| 88 | - | |
| 88 | + | Format(weaponname, sizeof weaponname, "%s", sExplodeString[iNum - 1]); |
| 89 | break; | |
| 90 | - | |
| 90 | + | } |
| 91 | } | |
| 92 | } | |
| 93 | ||
| 94 | damagedelta = RoundToNearest((dmg_health * gMeleeModifier[5]) - dmg_health); | |
| 95 | ||
| 96 | for(int i; i < 5; i++) | |
| 97 | {
| |
| 98 | if(strcmp(weaponname, gGeneralMelee[i]) == 0) | |
| 99 | - | |
| 99 | + | |
| 100 | damagedelta = RoundToNearest((dmg_health * gMeleeModifier[i]) - dmg_health); | |
| 101 | break; | |
| 102 | } | |
| 103 | } | |
| 104 | ||
| 105 | - | |
| 105 | + | |
| 106 | applyDamage(damagedelta, entity, attacker); | |
| 107 | else | |
| 108 | {
| |
| 109 | int health = eventhealth - damagedelta; | |
| 110 | ||
| 111 | if (health < 1) | |
| 112 | {
| |
| 113 | damagedelta += (health - 1); | |
| 114 | health = 1; | |
| 115 | } | |
| 116 | SetEntProp(entity, Prop_Data, "m_iHealth", health); | |
| 117 | SetEventInt(event, "amount", damagedelta); | |
| 118 | } | |
| 119 | } | |
| 120 | ||
| 121 | static void applyDamage(int damage, int victim, int attacker) | |
| 122 | {
| |
| 123 | Handle dataPack = CreateDataPack(); | |
| 124 | WritePackCell(dataPack, damage); | |
| 125 | WritePackCell(dataPack, victim); | |
| 126 | WritePackCell(dataPack, attacker); | |
| 127 | ||
| 128 | CreateTimer(0.1, timer_stock_applyDamage, dataPack); | |
| 129 | ignoreNextDamageDealt[attacker] = true; | |
| 130 | CreateTimer(0.2, timer_resetStop, attacker); | |
| 131 | } | |
| 132 | ||
| 133 | public Action timer_resetStop(Handle timer, any client) | |
| 134 | {
| |
| 135 | ignoreNextDamageDealt[client] = false; | |
| 136 | } | |
| 137 | ||
| 138 | public Action timer_stock_applyDamage(Handle timer, Handle dataPack) | |
| 139 | {
| |
| 140 | ResetPack(dataPack); | |
| 141 | int damage = ReadPackCell(dataPack); | |
| 142 | int victim = ReadPackCell(dataPack); | |
| 143 | int attacker = ReadPackCell(dataPack); | |
| 144 | CloseHandle(dataPack); | |
| 145 | ||
| 146 | float victimPos[3]; char strDamage[16], strDamageTarget[16]; | |
| 147 | ||
| 148 | if (victim < 20 && IsClientInGame(victim)) | |
| 149 | {
| |
| 150 | GetClientEyePosition(victim, victimPos); | |
| 151 | } | |
| 152 | else if (IsValidEntity(victim)) | |
| 153 | {
| |
| 154 | GetEntityAbsOrigin(victim, victimPos); | |
| 155 | } | |
| 156 | else return; | |
| 157 | ||
| 158 | IntToString(damage, strDamage, sizeof(strDamage)); | |
| 159 | Format(strDamageTarget, sizeof(strDamageTarget), "hurtme%d", victim); | |
| 160 | ||
| 161 | int entPointHurt = CreateEntityByName("point_hurt");
| |
| 162 | if(!entPointHurt) return; | |
| 163 | ||
| 164 | DispatchKeyValue(victim, "targetname", strDamageTarget); | |
| 165 | DispatchKeyValue(entPointHurt, "DamageTarget", strDamageTarget); | |
| 166 | DispatchKeyValue(entPointHurt, "Damage", strDamage); | |
| 167 | DispatchKeyValue(entPointHurt, "DamageType", "0"); | |
| 168 | DispatchSpawn(entPointHurt); | |
| 169 | ||
| 170 | TeleportEntity(entPointHurt, victimPos, NULL_VECTOR, NULL_VECTOR); | |
| 171 | AcceptEntityInput(entPointHurt, "Hurt", (attacker && attacker < 20 && IsClientInGame(attacker)) ? attacker : -1); | |
| 172 | ||
| 173 | DispatchKeyValue(entPointHurt, "classname", "point_hurt"); | |
| 174 | DispatchKeyValue(victim, "targetname", "null"); | |
| 175 | AcceptEntityInput(entPointHurt, "kill"); | |
| 176 | } | |
| 177 | ||
| 178 | stock void GetEntityAbsOrigin( int entity, float origin[3]) | |
| 179 | {
| |
| 180 | if (entity > 0 && IsValidEntity(entity)) | |
| 181 | {
| |
| 182 | float mins[3], maxs[3]; | |
| 183 | GetEntPropVector(entity,Prop_Send,"m_vecOrigin",origin); | |
| 184 | GetEntPropVector(entity,Prop_Send,"m_vecMins",mins); | |
| 185 | GetEntPropVector(entity,Prop_Send,"m_vecMaxs",maxs); | |
| 186 | ||
| 187 | origin[0] += (mins[0] + maxs[0]) * 0.5; | |
| 188 | origin[1] += (mins[1] + maxs[1]) * 0.5; | |
| 189 | origin[2] += (mins[2] + maxs[2]) * 0.5; | |
| 190 | } | |
| 191 | } |