|
| 1 | +methodmap AMSSettings < StringMap { |
| 2 | + public AMSSettings(const FF2Prep player, Handle pContext, const char[] plugin, const char[] ability, const char[] prefix) { |
| 3 | + StringMap ams = new StringMap(); |
| 4 | + |
| 5 | + ams.SetValue("this", pContext); |
| 6 | + ams.SetString("this_plugin", plugin); |
| 7 | + ams.SetString("prefix", prefix); |
| 8 | + ams.SetString("ability", ability); |
| 9 | + ams.SetValue("cooldown", GetGameTime() + player.GetArgF(plugin, ability, "initial cd", 1001, 0.0)); |
| 10 | + ams.SetValue("abilitycd", player.GetArgF(plugin, ability, "ability cd", 1002, 10.0)); |
| 11 | + |
| 12 | + char str[128]; player.GetArgS(plugin, ability, "this_name", 1003, str, sizeof(str)); |
| 13 | + ams.SetString("this_name", str); |
| 14 | + |
| 15 | + player.GetArgS(plugin, ability, "display_desc", 1004, str, sizeof(str)); |
| 16 | + ams.SetString("display_desc", str); |
| 17 | + |
| 18 | + ams.SetValue("this_cost", player.GetArgF(plugin, ability, "cost", 1005, 25.0)); |
| 19 | + ams.SetValue("this_end", player.GetArgI(plugin, ability, "can end", 1006, 0)); |
| 20 | + |
| 21 | + return view_as<AMSSettings>(ams); |
| 22 | + } |
| 23 | + |
| 24 | + public bool IsValid() { |
| 25 | + return this != null; |
| 26 | + } |
| 27 | + |
| 28 | + public bool GetPrefix(char[] prefix, int size) { |
| 29 | + return this.GetString("prefix", prefix, size); |
| 30 | + } |
| 31 | + |
| 32 | + public float GetCurrentCooldown() { |
| 33 | + float cd; |
| 34 | + return this.GetValue("cooldown", cd) ? cd:0.0; |
| 35 | + } |
| 36 | + public void SetCurrentCooldown(float cd) { |
| 37 | + this.SetValue("cooldown", cd + GetGameTime()); |
| 38 | + } |
| 39 | + public void AddCooldown() |
| 40 | + { |
| 41 | + float cd; |
| 42 | + this.GetValue("abilitycd", cd); |
| 43 | + this.SetCurrentCooldown(cd); |
| 44 | + } |
| 45 | + |
| 46 | + public bool CanEnd() |
| 47 | + { |
| 48 | + bool canend; this.GetValue("this_end", canend); |
| 49 | + return canend; |
| 50 | + } |
| 51 | + |
| 52 | + public float GetCost() { |
| 53 | + float cost; |
| 54 | + this.GetValue("this_cost", cost); |
| 55 | + return cost; |
| 56 | + } |
| 57 | + public float SetCost(float cost) { |
| 58 | + this.SetValue("this_cost", cost); |
| 59 | + } |
| 60 | + |
| 61 | +} |
| 62 | + |
| 63 | +FF2Parse GlobalAMS[MAXCLIENTS]; |
| 64 | +AMSSettings AMS_Settings[MAXCLIENTS][MAXABILITIES]; |
| 65 | + |
| 66 | +public AMSResult Handle_AMSPreAbility(int client, int index) |
| 67 | +{ |
| 68 | + Call_StartForward(AMSForward[hPreAbility]); |
| 69 | + Call_PushCell(client); |
| 70 | + int idx = index; |
| 71 | + Call_PushCellRef(idx); |
| 72 | + AMSResult action = AMS_Ignore; |
| 73 | + Call_PushCellRef(action); |
| 74 | + Action result = Plugin_Continue; |
| 75 | + Call_Finish(result); |
| 76 | + if(result == Plugin_Stop) { |
| 77 | + return AMS_Deny; |
| 78 | + } |
| 79 | + else if(result != Plugin_Continue) { |
| 80 | + index = idx; |
| 81 | + } |
| 82 | + if(result == Plugin_Handled && action != AMS_Ignore) { |
| 83 | + return action; |
| 84 | + } |
| 85 | + return AMS_CanInvoke(client, index); |
| 86 | +} |
| 87 | + |
| 88 | +static AMSResult AMS_CanInvoke(int client, int index) |
| 89 | +{ |
| 90 | + AMSResult AMSAction = AMS_Accept; |
| 91 | + Handle hPlugin; |
| 92 | + Function hFunc; |
| 93 | + if(AMS_GetThisFunction(client, index, "%s_CanInvoke", hPlugin, hFunc)) { |
| 94 | + Call_StartFunction(hPlugin, hFunc); |
| 95 | + Call_PushCell(client); |
| 96 | + Call_PushCell(index); |
| 97 | + Call_Finish(AMSAction); |
| 98 | + } |
| 99 | + if(AMSAction == AMS_Overwrite) { |
| 100 | + if(AMS_GetThisFunction(client, index, "%s_Overwrite", hPlugin, hFunc)) { |
| 101 | + Call_StartFunction(hPlugin, hFunc); |
| 102 | + Call_PushCell(client); |
| 103 | + Call_PushCell(index); |
| 104 | + Call_Finish(); |
| 105 | + } |
| 106 | + } else if(AMSAction == AMS_Accept) { |
| 107 | + AMS_Settings[client][index].AddCooldown(); |
| 108 | + } |
| 109 | + return AMSAction; |
| 110 | +} |
| 111 | + |
| 112 | +static void AMS_DoInvoke(int client, int index) |
| 113 | +{ |
| 114 | + Handle hPlugin; |
| 115 | + Function hFunc; |
| 116 | + if(AMS_GetThisFunction(client, index, "%s_Invoke", hPlugin, hFunc)) { |
| 117 | + Call_StartFunction(hPlugin, hFunc); |
| 118 | + Call_PushCell(client); |
| 119 | + Call_PushCell(index); |
| 120 | + Call_Finish(); |
| 121 | + |
| 122 | + static char buffer[64]; |
| 123 | + GlobalAMS[client].GetString("cast-particle", buffer, sizeof(buffer)); |
| 124 | + if(!IsEmptyString(buffer)) { |
| 125 | + CreateTimedParticle(client, buffer, 1.0); |
| 126 | + } |
| 127 | + } |
| 128 | +} |
| 129 | + |
| 130 | +public void Handle_AMSOnAbility(int client, int index) |
| 131 | +{ |
| 132 | + Call_StartForward(AMSForward[hOnAbility]); |
| 133 | + Call_PushCell(client); |
| 134 | + Call_PushCell(index); |
| 135 | + static char plugin[64]; AMS_Settings[client][index].GetString("this_plugin", plugin, sizeof(plugin)); |
| 136 | + Call_PushString(plugin); |
| 137 | + AMS_Settings[client][index].GetString("ability", plugin, sizeof(plugin)); |
| 138 | + Call_PushString(plugin); |
| 139 | + Call_Finish(); |
| 140 | + |
| 141 | + AMS_DoInvoke(client, index); |
| 142 | +} |
| 143 | + |
| 144 | +public void Handle_AMSOnEnd(int client, int index) |
| 145 | +{ |
| 146 | + Call_StartForward(AMSForward[hPreForceEnd]); |
| 147 | + Call_PushCell(client); |
| 148 | + int idx = index; |
| 149 | + Call_PushCellRef(idx); |
| 150 | + AMSResult action = AMS_Ignore; |
| 151 | + Call_PushCellRef(action); |
| 152 | + Action result = Plugin_Continue; |
| 153 | + Call_Finish(result); |
| 154 | + if(result == Plugin_Stop || action <= AMS_Deny) { |
| 155 | + return; |
| 156 | + } |
| 157 | + else if(result != Plugin_Continue) { |
| 158 | + index = idx; |
| 159 | + } |
| 160 | + |
| 161 | + Handle hPlugin; |
| 162 | + Function hFunc; |
| 163 | + if(AMS_GetThisFunction(client, index, "%s_EndAbility", hPlugin, hFunc)) { |
| 164 | + Call_StartFunction(hPlugin, hFunc); |
| 165 | + Call_PushCell(client); |
| 166 | + Call_PushCell(index); |
| 167 | + Call_Finish(); |
| 168 | + } |
| 169 | +} |
| 170 | + |
| 171 | +static bool AMS_GetThisFunction(int client, int index, const char[] format, Handle &IPlugin, Function &Func) |
| 172 | +{ |
| 173 | + |
| 174 | + if(!AMS_Settings[client][index].GetValue("this", IPlugin) || IPlugin == null) { |
| 175 | + return false; |
| 176 | + } |
| 177 | + |
| 178 | + static char func[32], prefix[8]; |
| 179 | + if(!AMS_Settings[client][index].GetPrefix(prefix, sizeof(prefix))) { |
| 180 | + return false; |
| 181 | + } |
| 182 | + |
| 183 | + FormatEx(func, sizeof(func), format, prefix); |
| 184 | + Func = GetFunctionByName(IPlugin, func); |
| 185 | + return Func != INVALID_FUNCTION; |
| 186 | +} |
| 187 | + |
| 188 | +static stock void CreateTimedParticle(int client, char[] particle, float duration) |
| 189 | +{ |
| 190 | + int entity = CreateEntityByName("info_particle_system"); |
| 191 | + |
| 192 | + float vecPos[3]; GetEntPropVector(client, Prop_Send, "m_vecOrigin", vecPos); |
| 193 | + TeleportEntity(entity, vecPos, NULL_VECTOR, NULL_VECTOR); |
| 194 | + |
| 195 | + static char buffer[64]; |
| 196 | + FormatEx(buffer, sizeof(buffer), "target%i", client); |
| 197 | + DispatchKeyValue(client, "targetname", buffer); |
| 198 | + |
| 199 | + DispatchKeyValue(entity, "targetname", "tf2particle"); |
| 200 | + DispatchKeyValue(entity, "parentname", buffer); |
| 201 | + DispatchKeyValue(entity, "effect_name", particle); |
| 202 | + DispatchSpawn(entity); |
| 203 | + |
| 204 | + SetVariantString(buffer); |
| 205 | + AcceptEntityInput(entity, "SetParent", entity, entity); |
| 206 | + |
| 207 | + SetEntPropEnt(entity, Prop_Send, "m_hOwnerEntity", client); |
| 208 | + ActivateEntity(entity); |
| 209 | + AcceptEntityInput(entity, "start"); |
| 210 | + |
| 211 | + CreateTimer(duration, Timer_KillEntity, EntIndexToEntRef(entity), TIMER_FLAG_NO_MAPCHANGE); |
| 212 | +} |
| 213 | + |
| 214 | +public Action Timer_KillEntity(Handle timer, any EntRef) |
| 215 | +{ |
| 216 | + int entity = EntRefToEntIndex(EntRef); |
| 217 | + if(IsValidEntity(entity)) |
| 218 | + RemoveEntity(entity); |
| 219 | +} |
0 commit comments