Veteran Member
|
07-10-2012
, 03:52
Re: [TF2] Class Damage Modifier
|
#5
|
Spoiler
Nice plugin, but a couple of things I wanted to point out which aren't critical, but just bother me a bit
You may want to add a loop in PluginStart to hook all players to account for late loading.
That one is something you'll probably want to do. The rest of these are basically just suggestions of what I'd do.
Ok first off...lolwut?
PHP Code:
//... new Handle:Version; //... public OnPluginStart() { //... HookConVarChange(Version, CVarChange); }
public CVarChange(Handle:convar, const String:oldValue[], const String:newValue[]) { if(convar == Version) { SetConVarString(Version, PLUGIN_VERSION); } }
Anyway...
You should move the enabled check to before the attacker validity check.
Then, If you're doing this for each class:
PHP Code:
CheckCommandAccess(attacker, "dmgmod_flag", ADMFLAG_GENERIC, false)
Why not check it once then return?
In fact, because of short-circuiting, you could move all of those to the same check:
PHP Code:
if(!GetConVarBool(cvarEnabled) || !IsValidClient(attacker) || (GetConVarBool(cvarAdminOnly) && !CheckCommandAccess(attacker, "dmgmod_flag", ADMFLAG_GENERIC, false))) { return Plugin_Continue; }
Also, why check if the damage <= 1.0? What if people want to lower damage with this with 0.5(half damage)?
I'd personally remove that altogether and have it just multiply the damage. Your cvars already limit it to a min of 0.0, so no need to check < 0.0 either. As for disabling, 1.0 is already 'disabled' really since it won't change the damage at all, and having it just multiply the damage by 1 seems faster than specifically checking for it just to return as normal.
Next point, I'd suggest checking and storing the attacker's class at the start rather than having to do it for each class.
Further, You could change the class checks into a switch for faster computing.
Actually, if you change the cvars a bit...
You know what? I'm rambling on a bit, let me just show an example, eh?
PHP Code:
new Handle:cvarEnabled; new Handle:cvarAdminOnly; new Handle:cvarClass[10];
public OnPluginStart() { CreateConVar("sm_dmgmod_version", PLUGIN_VERSION, "Class Damage Modifier Version.", FCVAR_REPLICATED | FCVAR_PLUGIN | FCVAR_SPONLY | FCVAR_DONTRECORD);
cvarEnabled = CreateConVar("sm_dmgmod_enabled", "1", "Enable Class Damage Modifier.\n0 = Disabled\n1 = Enabled", FCVAR_NONE, true, 0.0, true, 1.0); cvarAdminOnly = CreateConVar("sm_dmgmod_admins", "0", "Damage Increase for Admins Only.\n0 = Disabled\n1 = Enabled", FCVAR_NONE, true, 0.0, true, 1.0); cvarClass[1] = CreateConVar("sm_dmgmod_scout", "1.0", "Damage Increase for Scouts. (By Percentage)", FCVAR_NONE, true, 0.0, true, 10.0); cvarClass[3] = CreateConVar("sm_dmgmod_soldier", "1.0", "Damage Increase for Soldiers. (By Percentage)", FCVAR_NONE, true, 0.0, true, 10.0); cvarClass[7] = CreateConVar("sm_dmgmod_pyro", "1.0", "Damage Increase for Pyros. (By Percentage)", FCVAR_NONE, true, 0.0, true, 10.0); cvarClass[4] = CreateConVar("sm_dmgmod_demoman", "1.0", "Damage Increase for Demomans. (By Percentage)", FCVAR_NONE, true, 0.0, true, 10.0); cvarClass[6] = CreateConVar("sm_dmgmod_heavy", "1.0", "Damage Increase for Heavy. (By Percentage)", FCVAR_NONE, true, 0.0, true, 10.0); cvarClass[9] = CreateConVar("sm_dmgmod_engineer", "1.0", "Damage Increase for Engineers. (By Percentage)", FCVAR_NONE, true, 0.0, true, 10.0); cvarClass[5] = CreateConVar("sm_dmgmod_medic", "1.0", "Damage Increase for Medics. (By Percentage)", FCVAR_NONE, true, 0.0, true, 10.0); cvarClass[2] = CreateConVar("sm_dmgmod_sniper", "1.0", "Damage Increase for Snipers. (By Percentage)", FCVAR_NONE, true, 0.0, true, 10.0); cvarClass[8] = CreateConVar("sm_dmgmod_spy", "1.0", "Damage Increase for Spys. (By Percentage)", FCVAR_NONE, true, 0.0, true, 10.0); //Late loading for(new i = 1; i <= MaxClients; i++) { SDKHook(i, SDKHook_OnTakeDamage, OnTakeDamage); } }
public OnClientPutInServer(client) { SDKHook(client, SDKHook_OnTakeDamage, OnTakeDamage); }
public Action:OnTakeDamage(victim, &attacker, &inflictor, &Float:damage, &damagetype) { if(!GetConVarBool(cvarEnabled) || !IsValidClient(attacker) || (GetConVarBool(cvarAdminOnly) && !CheckCommandAccess(attacker, "dmgmod_flag", ADMFLAG_GENERIC, false))) { return Plugin_Continue; }
new Float:dmgmult = GetConVarFloat(cvarClass[TF2_GetPlayerClass(attacker)]); damage *= dmgmult; return Plugin_Changed; }
Edit: Hiding this long post.
Last edited by Tylerst; 03-01-2013 at 20:40.
|
|