AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Is this O.K. ? (Something like a Domination System) (https://forums.alliedmods.net/showthread.php?t=127792)

nicolazo103 05-24-2010 22:04

Is this O.K. ? (Something like a Domination System)
 
Well, i havenīt made a plugin for a long time, so i donīt remember almost anything. I would want to know if this code will work and what could i improve?

Code:
#include <amxmodx> #include <hamsandwich> new Author [] = "Larz" new Plugin [] = "Domination System" new Domination new Kill[33][33] public plugin_init() {     register_plugin(Plugin, "0.1b", Author)         Domination = register_cvar("amx_allow_domination_system", "1")         RegisterHam(Ham_Killed, "player", "fw_HamKilled") } public fw_HamKilled(victim, attacker, shouldgib) {     if(!get_pcvar_num(Domination))         return PLUGIN_HANDLED         Kill[attacker][victim]++         new attackername[32], victimname[32]         get_user_name(attacker, attackername, 31)     get_user_name(victim, victimname, 31)         set_hudmessage(200, 100, 0, -50.0, -80.0, 1, 5.0, 12.0, 0.2, 0.3, 4)     show_hudmessage(victim, "You were killed by %s (%i)", attackername, Kill[attacker][victim])         if(Kill[attacker][victim] == 3)     {         set_hudmessage(200, 100, 0, -50.0, -80.0, 1, 5.0, 12.0, 0.2, 0.3, 4)         show_hudmessage(0, "%s is dominating %s (%i kill%w)", attackername, victimname, Kill[attacker][victim], Kill[attacker][victim]==1?"":"s")     }     if(Kill[attacker][victim] > 3)     {         set_hudmessage(200, 100, 0, -50.0, -80.0, 1, 5.0, 12.0, 0.2, 0.3, 4)         show_hudmessage(victim, "You have been killed again by %s (%i)", attackername, Kill[attacker][victim])     }     if(Kill[victim][attacker] == 3)     {         set_hudmessage(200, 100, 0, -50.0, -80.0, 1, 5.0, 12.0, 0.2, 0.3, 4)         show_hudmessage(0, "%s got revenge on %s after %i kill%w)", attackername, victimname, Kill[attacker][victim], Kill[attacker][victim]==1?"":"s")     }             Kill[victim][attacker] = 0         return HAM_IGNORED }

Kreation 05-24-2010 22:52

Re: Is this O.K. ? (Something like a Domination System)
 
Why do you have the "Kill" variable with 2 brackets. Why not just use one, because I'm not 100% but if you have the two like you have there that it will reset the "Kill" for both the attacker and the victim at the end of the function.

wrecked_ 05-24-2010 23:11

Re: Is this O.K. ? (Something like a Domination System)
 
Quote:

Originally Posted by Kreation (Post 1190361)
Why do you have the "Kill" variable with 2 brackets. Why not just use one, because I'm not 100% but if you have the two like you have there that it will reset the "Kill" for both the attacker and the victim at the end of the function.

No. If you're iff-y on that subject with the brackets and values being reset, look at my tutorial on catching the damage done per round.

On-Topic: When you're setting all of these hud messages, you're using the same channel (4) for each of them. You can only have one message per channel. This means some messages might be overriden or something of galactic proportions could occur. You should use -1 for the channel, since this uses the next available channel.

You also have a typo in your second and fourth if() statements when formatting your message. It should be %s, not %w. I fat finger those, too; don't cry.

Also, change your third if() statement to an else if(), since you can't have a value that's 3 and greater than 3 at the same time.

nicolazo103 05-25-2010 12:44

Re: Is this O.K. ? (Something like a Domination System)
 
Thanks a lot wrecked :D
one More Thing:

Code:
#include <amxmodx> #include <fvault> #include <hamsandwich> new Author [] = "Larz | TheÜberRazorBack" new Plugin [] = "Domination System" new Domination, SaveStats, Method new Kill[33][33], Dominations[33], Dominated[33], Revenges[33] public plugin_init() {     register_plugin(Plugin, "0.1b", Author)     register_clcmd("say /mydomstats", "showtats")         Domination = register_cvar("amx_allow_domination_system", "1")     SaveStats = register_cvar("amx_save_domination_stats", "1")     Method = register_cvar("amx_save_method", "1")         RegisterHam(Ham_Killed, "player", "fw_HamKilled") } public client_connect(id) Load(id) public fw_HamKilled(victim, attacker, shouldgib) {     if(!get_pcvar_num(Domination))         return PLUGIN_HANDLED         Kill[attacker][victim]++         new attackername[32], victimname[32]         get_user_name(attacker, attackername, 31)     get_user_name(victim, victimname, 31)         set_hudmessage(200, 100, 0, -50.0, -80.0, 1, 5.0, 12.0, 0.2, 0.3, -1)     show_hudmessage(victim, "You were killed by %s (%i)", attackername, Kill[attacker][victim])         if(Kill[attacker][victim] == 3)     {         set_hudmessage(200, 100, 0, -50.0, -80.0, 1, 5.0, 12.0, 0.2, 0.3, 4)         show_hudmessage(0, "%s is dominating %s (%i kill%s)", attackername, victimname, Kill[attacker][victim], Kill[attacker][victim]==1?"":"s")                 Dominations[attacker]++         Dominated[victim]++                 Save(attacker)         Save(victim)     }     else if(Kill[attacker][victim] > 3)     {         set_hudmessage(200, 100, 0, -50.0, -80.0, 1, 5.0, 12.0, 0.2, 0.3, 2)         show_hudmessage(victim, "You have been killed again by %s (%i)", attackername, Kill[attacker][victim])     }     if(Kill[victim][attacker] == 3)     {         set_hudmessage(200, 100, 0, -50.0, -80.0, 1, 5.0, 12.0, 0.2, 0.3, 3)         show_hudmessage(0, "%s got revenge on %s after %i kill%s)", attackername, victimname, Kill[attacker][victim], Kill[attacker][victim]==1?"":"s")                 Revenges[attacker]++         Save(attacker)     }             Kill[victim][attacker] = 0         return HAM_IGNORED } public Save(id) {     if(!get_pcvar_num(SaveStats))         return PLUGIN_HANDLED         new AuthID[32], Data[40], Key[32]         if(!get_pcvar_num(Method)) {         get_user_name(id, AuthID, 32)         formatex(Key, 32, "^"%s^"", AuthID)     }     else         get_user_authid(id, Key, 32)         formatex(Data, 39, "%s %s %s", Dominations[id], Dominated[id], Revenges[id])         fvault_set_data("DomSystem", Key, Data)         return PLUGIN_HANDLED } public Load(id) {     if(!get_pcvar_num(SaveStats))         return PLUGIN_HANDLED         new AuthID[33], Data[40], Key[33]         if(!get_pcvar_num(Method))     {         get_user_name(id, AuthID, 32)         formatex(Key, 32, "^"%s^"", AuthID)     }     else         get_user_authid(id, Key, 32)         if(fvault_get_data("DomSystem", Key, Data, 39))     {         parse(Data, Dominations, 32, Dominated, 32, Revenges, 32)             }     return PLUGIN_HANDLED } public showtats(id) {     if(!get_pcvar_num(SaveStats))         return PLUGIN_HANDLED         set_hudmessage(200, 100, 0, -50.0, -80.0, 1, 5.0, 12.0, 0.2, 0.3, -1)     show_hudmessage(id, "# Dominations: %i ^n # Dominated: %i ^n Revenges: %i", Dominations[id], Dominated[id], Revenges[id])     return PLUGIN_HANDLED }


All times are GMT -4. The time now is 05:22.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.