AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   DOD FF MANAGER: maybe a nice plugin if you can help me :) (https://forums.alliedmods.net/showthread.php?t=5785)

Colt 09-12-2004 16:36

DOD FF MANAGER: maybe a nice plugin if you can help me :)
 
3 Attachment(s)
Hello everybody! I've noticed it is boring that some unmatured players shoot their allies without being punished :evil: (if their is only a TA and not a TK). So I've decided to create an original system to manage the friendly fire in DOD:

At the start, each player gets 25 credits (by default).
Then each time he shoots an ally, he losses:
-1 for TA >9 Hp with grenade
-2 for TA >9Hp with rocket-launcher or with mortar
-3 for TA >9Hp normal or a kill with mortar
-4 for a TK normal
-5 for a TA melee
-6 for a TK melee
-7 for a spawn TA
-8 for a spawn TK

Victim gets a menu which allow to give back credits and to slap the attacker. The last 2 actions are stored to forgive later by writting:
"forgivetk" or "forgive" or "pardonner" or "pardon"

Attacker is slayed if he attacks allies at respawn.

When credits<5, the player is slayed as an ultime warning.

When credits<0, the player is banned for a defined time.

There is a STEAM_ID memory to prevent players to disconnect and reconnect in the aim they get back all their credits.


Some screenshots:

http://colt77.free.fr/dodffm1.jpg
http://colt77.free.fr/dodffm2.jpg
http://colt77.free.fr/dodffm3.jpg
http://colt77.free.fr/dodffm4.jpg
http://colt77.free.fr/dodffm5.jpg

Some of you have recognized it, that is based on the old pluging DOD TK MANAGER created by Fractal ([email protected]) and improved by SidLuke ([email protected]).
That is why there is some code which is similar (for example the files for credits memory, I am not good enough to make it myself). Of course, I have thanked them in the source, nevertheless I apologize in advance if you think this is insufficient.

So what is the problem? Actually, many :(

1. One time, menus works fine, an other time, it happens nothing when you press a key, or the menu doesn't display at all! I have tried to replace keys (1<<0) ... by 1023, but it changes nothing.

2. One time, credits are well counted, an other time, they are "mad" (for example less than -8 credits for a TK). -> 02/10 FIXED

3. One time, players are slayed when they shoot at spawn, an other, the text is displayed but they are not slayed! (of course they have no immunity I'm not stupid :shock: )

4. I can compile it with 0.20, but I get a bad load error in the server log. So to launch it, I have to compile it with 0.16. I use the Windows Dedicated Server for my tests, before to put it on my team's server (Linux). Notice I have also to use an old version of metamod to prevent a crash of the server :(
-> 29/09 FIXED

Here is the source, I have made my possible to comment it:

29/09: NEW EDITION
Code:

/*
 Introduction
 ------------
 DOD FF MANAGER is a plugin for AMX Mod X
 Author: Colt ([email protected])
 It is based on the DOD TK Manager created by Fractal ([email protected])
 and improved by SidLuke ([email protected]) and I have added many functions.
 A very big thanks to them, who allowed to create a nice protection when FF is ON. 
 
 Description
 -----------
 DOD FF Manager secures a DOD server when Friendy Fire is ON.

 At the start, each player gets 25 credits.
 Then each time he shoots an ally, he losses:
 -1 for TA >9 Hp with grenade
 -2 for TA >9Hp with rocket-launcher or mortar
 -3 for TA >9Hp normal or a kill with mortar
 -4 for a TK normal
 -5 for a TA melee
 -6 for a TK melee
 -7 for a spawn TA
 -8 for a spawn TK
 
 Victim gets a menu which allow to give back credits and
 to slap the attacker.
 The last 2 actions are stored to forgive later by writting:
 "forgivetk" or "forgive" or "pardonner" or "pardon"
 
 Attacker is slayed if he attacks allies at respawn.
 
 When credits<5, the player is slayed as an ultime warning.
 
 When credits<0, the player is banned for a defined time.
 
 There is a STEAM_ID memory to prevent players to disconnect and reconnect
 in the aim they get back all their credits.
 To enable this, a direcctory named logcredits must be created in your AMX MOD X folder.
 
 
  CVAR settings (to put in amxx.cfg)
  ----------------------------------------
 amx_ffm_bantime <x minutes> :        time the player is banned
                                      lwhen he has no credits anymore

 amx_ffm_credits <x> :                number of credits of each player
                                      at the start of a map

 amx_ffm_multiTK <1|0>:                if enabled, when a multi-TK with grenade happens,
                                      only the first TK is counted.

 amx_ffm_protectiontime <x secondes>:  minimum time before the player
                                      is slayed if he attacks allies.
 
 By default, if you don't define theses variables, they will be:

 amx_ffm_bantime = 180
 amx_ffm_credits = 25
 amx_ffm_multiTK = 1
 amx_ffm_protectiontime = 6

*/

Code:
#include <amxmodx> #include <amxmisc> #include <dodx> new Float:g_SpawnTime[33] new g_adminimmunity new g_bantime new g_credits_start new g_player_authid[33][40] new g_player_authenticated[33] new g_credits[33] new g_menu_killerid[33] new g_menu_attackerid[33] new Float:g_LastAttackTime[33] new Last1Attacker = 0 new Last1Victim = 0 new Last2Attacker = 0 new Last2Victim = 0 public plugin_init() {     register_plugin("DoD FF Manager","0.1","Colt")     register_event("ResetHUD","eResetHud","b")         register_cvar("amx_ffm_bantime","180")     register_cvar("amx_ffm_credits","25")     register_cvar("amx_ffm_multiTK","1")     register_cvar("amx_ffm_protectiontime","6.0")     register_clcmd("say","HandleSay")     register_clcmd("say_team","HandleSay")     register_statsfwd(XMF_DAMAGE)     register_statsfwd(XMF_DEATH)     register_menucmd(register_menuid("-1"),1023,"Menu1")     register_menucmd(register_menuid("-2"),1023,"Menu2")     register_menucmd(register_menuid("-3"),1023,"Menu3")     register_menucmd(register_menuid("-4"),1023,"Menu4")     register_menucmd(register_menuid("-5"),1023,"Menu5")     register_menucmd(register_menuid("-6"),1023,"Menu6")     register_menucmd(register_menuid("-7"),1023,"Menu7")     register_menucmd(register_menuid("-8"),1023,"Menu8")     set_task(0.6,"load_settings")     return PLUGIN_CONTINUE } public load_settings() {     g_credits_start = get_cvar_num("amx_ffm_credits")     g_bantime = get_cvar_num("amx_ffm_bantime")     return PLUGIN_CONTINUE } public client_connect(id) {       g_player_authenticated[id] = 0     return PLUGIN_CONTINUE } public client_putinserver(id) {       get_user_authid(id,g_player_authid[id],39)     g_player_authenticated[id] = 1     g_credits[id] = g_credits_start     if ( is_user_bot(id) )         return PLUGIN_CONTINUE             new cditsFile[64]     format(cditsFile,63,"addons/amxmodx/logcredits/%s.txt",g_player_authid[id])     replace(cditsFile,63,":","_")     replace(cditsFile,63,":","_")     if (file_exists(cditsFile))     {         new currmap[32]         get_mapname(currmap,31)         new text[32]         new a = 0         if (read_file(cditsFile,1,text,31,a) && equali(currmap,text))         {             if (read_file(cditsFile,2,text,31,a))                 g_credits[id] = str_to_num(text)         }         else             delete_file(cditsFile)     }     return PLUGIN_CONTINUE } public client_disconnect(id) {     if ( is_user_bot(id) )         return PLUGIN_CONTINUE     if (g_player_authenticated[id] && g_credits[id] < g_credits_start)     {         new cditsFile[64]         format(cditsFile,63,"addons/amxmodx/logcredits/%s.txt",g_player_authid[id])         replace(cditsFile,63,":","_")         replace(cditsFile,63,":","_")         new currmap[32]         get_mapname(currmap,31)         write_file(cditsFile,currmap,1)         new text[8]         num_to_str(g_credits[id],text,7)         write_file(cditsFile,text,2)     }     return PLUGIN_CONTINUE } public eResetHud(id){     g_SpawnTime[id] = get_gametime()     return PLUGIN_CONTINUE } // protection vs  TA public client_damage(attacker,victim,damage,wpnindex,hitplace,TA){     if ( !TA || !is_user_alive(victim) || damage<10 ) // damage<10: do not punish small TA, very often unvulontarys         return PLUGIN_CONTINUE     new name[32]     new menuBody[192]     new attackerid     new keys = (1<<0)|(1<<1)|(1<<2)|(1<<3) // 4 is "invisible" but used to force menu to quit in 2 situations later     get_user_name(attacker,name,31)     g_menu_attackerid[victim] = attacker     attackerid = get_user_userid(attacker)     Last2Attacker = Last1Attacker     Last2Victim = Last1Victim     Last1Attacker = attacker     Last1Victim = victim         // spawn TA protection     if ( get_gametime() - g_SpawnTime[victim] < get_cvar_float("amx_ffm_protectiontime") || get_gametime() - g_SpawnTime[attacker] < get_cvar_float("amx_ffm_protectiontime")){         g_credits[attacker] = g_credits[attacker]-7         set_task(0.5,"delayedkill",attackerid)         set_hudmessage(255, 0, 255, 0.05, 0.8, 0, 4.0, 11.0, 0.1, 0.5, 8)           show_hudmessage(0,"%s slayed to have wounded an ally at respawn^nand losses 7 credits he has %i remaining!", name, g_credits[attacker])         format(menuBody,120,"-7 credits for %s:^n1. Forgive^n2. Do not forgive",name)         show_menu(victim,keys,menuBody,40)         Check_credits(attacker)         log_message("[FF MANAGER] %s attacked an ally at respawn and gets %i credits!",name, g_credits[attacker])         return PLUGIN_CONTINUE     }   // TA melee protection     if ( xmod_is_melee_wpn(wpnindex) ){         g_credits[attacker] = g_credits[attacker]-4         set_hudmessage(0, 255, 0, 0.05, 0.8, 0, 4.0, 11.0, 0.1, 0.5, 8)         show_hudmessage(0,"%s losses 4 credits to have wounded at melee^nan ally, he has %i remaining!", name, g_credits[attacker])         format(menuBody,120,"-4 credits for %s:^n1. Forgive^n2. Slap 30 Hp and forgive^n3. Do not forgive",name)         show_menu(victim,keys,menuBody,40)         Check_credits(attacker)         return PLUGIN_CONTINUE          }         // TA mortar protection     if ( wpnindex == DODW_MORTAR ){         g_credits[attacker] = g_credits[attacker]-2         set_hudmessage(0, 255, 0, 0.05, 0.8, 0, 4.0, 11.0, 0.1, 0.5, 8)         show_hudmessage(0,"%s losses 2 credits to have wounded an ally with mortar,^nhe has %i remaining!", name, g_credits[attacker])         format(menuBody,120,"-2 credits for %s:^n1. Forgive^n2. Slap 10 Hp and forgive^n3. Do not forgive",name)         show_menu(victim,keys,menuBody,40)         Check_credits(attacker)         return PLUGIN_CONTINUE     }         set_hudmessage(255, 255, 255, 0.05, 0.8, 0, 3.0, 10.0, 0.1, 0.5, 8)     if (wpnindex==13||wpnindex==14||wpnindex==36){         g_credits[attacker] = g_credits[attacker]-1         show_hudmessage(0,"%s losses 1 credit to have wounded of %d Hp^nan ally with grenade and has %i remaining!", name, damage, g_credits[attacker])         format(menuBody,120,"-1 credit for %s:^n1. Forgive^n2. Slap (5 Hp) and forgive.^n3. Do not forgive",name)         show_menu(victim,keys,menuBody,40)         Check_credits(attacker)         return PLUGIN_CONTINUE     }     if (wpnindex==29||wpnindex==30||wpnindex==31) {         g_credits[attacker] = g_credits[attacker]-2         show_hudmessage(0,"%s losses 2 credits to have wounded of %d Hp^nan ally with rocket-launcher and has %i remaining!", name, damage, g_credits[attacker])         format(menuBody,120,"-2 credits for %s:^n1. Forgive^n2.Slap (10 Hp) and forgive.^n3. Do not forgive",name)         show_menu(victim,keys,menuBody,40)         Check_credits(attacker)         return PLUGIN_CONTINUE     }     g_credits[attacker] = g_credits[attacker]-3     show_hudmessage(0,"%s losses 3 credits to have wounded of %d Hp^nan ally and has %i remaining!", name, damage, g_credits[attacker])     format(menuBody,120,"-3 credits for %s:^n1. Forgive^n2.Slap (15 Hp) and forgive.^n3. Do not forgive",name)     show_menu(victim,keys,menuBody,40)     Check_credits(attacker)     return PLUGIN_CONTINUE } public client_death(killer,victim,wpnindex,hitplace,TK) {     if ( !TK )         return PLUGIN_CONTINUE // If amx_ffm_multiTK=1, when a multi-Tk at grenade happens, only the 1st will be punished     if ( get_cvar_num("amx_ffm_multiTK") && g_LastAttackTime[killer] == get_gametime() && (wpnindex==13||wpnindex==14||wpnindex==36) ){         return PLUGIN_CONTINUE }     g_LastAttackTime[killer] = get_gametime()     new name[32]     new killerid     new victimid     new menuBody[192]     new keys = (1<<0)|(1<<1)|(1<<2)|(1<<3)     get_user_name(killer,name,31)     g_menu_killerid[victim] = killer     killerid = get_user_userid(killer)     victimid = get_user_userid(victim)     Last2Attacker = Last1Attacker     Last2Victim = Last1Victim     Last1Attacker = killer     Last1Victim = victim       // spawn TK protection     if ( get_gametime() - g_SpawnTime[victim] < get_cvar_float("amx_ffm_protectiontime") || get_gametime() - g_SpawnTime[killer] < get_cvar_float("amx_ffm_protectiontime") ){         set_task(0.5,"delayedkill",killerid)         g_credits[killer] = g_credits[killer]-8         set_hudmessage(255, 0, 255, 0.05, 0.8, 0, 5.0, 11.0, 0.1, 0.5, 8)         show_hudmessage(0,"%s slayed to have killed an ally at spawn^nand losses 8 credits, he has %i remaining!", name, g_credits[killer])         format(menuBody,120,"-8 credits for %s:^n1. Forgive^n2. Do not forgive",name)         show_menu(victim,keys,menuBody,40)         Check_credits(killer)         log_message("[FF MANAGER] %s has killed an ally at spawn and has %i credits remaining!",name, g_credits[killer])         return PLUGIN_CONTINUE     }       // melee TK protection     if ( xmod_is_melee_wpn(wpnindex) ){         g_credits[killer] = g_credits[killer]-6         set_hudmessage(0, 255, 0, 0.05, 0.8, 0, 5.0, 11.0, 0.1, 0.5, 8)         show_hudmessage(0,"%s losses 6 credits to have killed an ally^nat melee; he has %i remaining!", name, g_credits[killer])         format(menuBody,120,"-6 credits for %s:^n1. Forgive^n2. Slap (40Hp) and forgive^n3. Do not forgive",name)         show_menu(victim,keys,menuBody,40)         Check_credits(killer)         return PLUGIN_CONTINUE     }         // mortar TK protection     if ( wpnindex == DODW_MORTAR ){         g_credits[killer] = g_credits[killer]-3         set_hudmessage(0, 255, 0, 0.05, 0.8, 0, 5.0, 11.0, 0.1, 0.5, 8)         show_hudmessage(0,"%s losses 3 credits to have killed an ally^nwith mortar; he has %i remaining!", name, g_credits[killer])         format(menuBody,120,"-3 credits for %s:^n1. Forgive^n2. Slap (15Hp) and forgive^n3. Do not forgive",name)         show_menu(victim,keys,menuBody,40)         Check_credits(killer)         return PLUGIN_CONTINUE     }   // normal TK     new menuid     // prevents the double punishment if the wounder kills: it closes the forgive menu for the TA and forgives it invisibly     if (get_user_menu(victim,menuid,keys) && g_menu_attackerid[victim]==killer){         client_cmd(victim,"slot4")         g_credits[killer] = g_credits[killer]+3     }     g_credits[killer] = g_credits[killer]-4     set_hudmessage(255, 200, 0, 0.05, 0.8, 0, 5.0, 11.0, 0.1, 0.5, 8)     show_hudmessage(0,"%s losses 4 credits to have killed an ally; he has %i remaining!", name, g_credits[killer])      set_task(0.5,"delayedmenu",victimid) // delayedmenu to prevent (I believe) the previous command "slot4" closes this new one too.     return PLUGIN_CONTINUE } // checks the number of credits after a TA/TK Check_credits(player) {     if (g_credits[player] > g_credits_start)         return 0     new name[32], userid     get_user_name(player,name,31)     userid = get_user_userid(player)     set_hudmessage(255, 0, 0, 0.05, 0.6, 0, 8.0, 10.0, 0.1, 0.5, 8)     client_print(userid, print_chat, "If you have no credits anymore, you will be banned %d minutes!",g_bantime)     if (g_credits[player] < 5 && g_credits[player] > -1)     {         set_task(0.5,"delayedkill",userid)         show_hudmessage(0,"%s slayed  because he has less than 5 credits!", name, g_credits[player])     }     if (g_credits[player] < 0)     {         set_task(0.5,"delayedkill",userid)         if (g_adminimmunity && (get_user_flags(player) & ADMIN_BAN))         {             show_hudmessage(0,"%s has no credits anymore^nbut is not banned because he has the immunity!", name)                     }         else         {             if ((g_bantime % 1440)==0)             {                 show_hudmessage(0,"%s has no credits anymore^nand is banned %d hours!", name, (g_bantime / 60))             }             else if (g_bantime < 60)             {                 show_hudmessage(0,"%s has no credits anymore^nand is banned %d minutes!", name, (g_bantime % 1440))             }             else             {                 show_hudmessage(0,"%s%s has no credits anymore^nand is banned %d hours %d minutes!", name, (g_bantime / 60), (g_bantime % 1440))             }             g_credits[player] = g_credits_start // if during the same map the player is unbanned and reconnects, it prevents he starts with negatives credits...             set_task(0.7,"delayedban",userid)         }         log_message("[FF MANAGER] %s was banned %d minutes because he has no credits anymore!",name, g_bantime)         return PLUGIN_CONTINUE     }     return PLUGIN_CONTINUE } public Menu1(id,key) {     new NameV[32], NameA[32]     get_user_name(id,NameV,31)     get_user_name(g_menu_attackerid[id],NameA,31)         switch(key)     {         case 0:{             g_credits[g_menu_attackerid[id]] = g_credits[g_menu_attackerid[id]] + 1             set_hudmessage(0, 90, 235, 0.05, 0.72, 0, 3.0, 11.0, 0.1, 0.5, 9)               show_hudmessage(0,"%s has forgiven %s^nand gives him 1 credit back", NameV, NameA)         }                 case 1:{             g_credits[g_menu_attackerid[id]] = g_credits[g_menu_attackerid[id]] + 1             user_slap (g_menu_attackerid[id], 5)             set_hudmessage(0, 90, 235, 0.05, 0.72, 0, 3.0, 11.0, 0.1, 0.5, 9)               show_hudmessage(0,"%s has slaped (5 Hp) %s^nand gives him 1 credit back", NameV, NameA)         }                 case 2:{             set_hudmessage(0, 90, 235, 0.05, 0.72, 0, 3.0, 11.0, 0.1, 0.5, 9)               show_hudmessage(0,"%s does not forgive %s^nbut can do it later by writting forgive", NameV, NameA)         }     }     return PLUGIN_HANDLED } public Menu2(id,key) {     new NameV[32], NameA[32]     get_user_name(id,NameV,31)     get_user_name(g_menu_attackerid[id],NameA,31)         switch(key)     {         case 0:{             g_credits[g_menu_attackerid[id]] = g_credits[g_menu_attackerid[id]] + 2             set_hudmessage(0, 90, 235, 0.05, 0.72, 0, 3.0, 11.0, 0.1, 0.5, 9)               show_hudmessage(0,"%s has forgiven %s^nand gives him 2 credits back", NameV, NameA)         }                 case 1:{             g_credits[g_menu_attackerid[id]] = g_credits[g_menu_attackerid[id]] + 2             user_slap (g_menu_attackerid[id], 10)             set_hudmessage(0, 90, 235, 0.05, 0.72, 0, 3.0, 11.0, 0.1, 0.5, 9)               show_hudmessage(0,"%s has slaped (10 Hp) %s^nand gives him 2 credits back", NameV, NameA)         }                 case 2:{             set_hudmessage(0, 90, 235, 0.05, 0.72, 0, 3.0, 11.0, 0.1, 0.5, 9)               show_hudmessage(0,"%s does not forgive %s^nbut can do it later by writting forgive", NameV, NameA)         }     }     return PLUGIN_HANDLED } public Menu3(id,key) {     new NameV[32], NameA[32]     get_user_name(id,NameV,31)     get_user_name(g_menu_attackerid[id],NameA,31)         switch(key)     {         case 0:{             g_credits[g_menu_attackerid[id]] = g_credits[g_menu_attackerid[id]] + 3             set_hudmessage(0, 90, 235, 0.05, 0.72, 0, 3.0, 11.0, 0.1, 0.5, 9)               show_hudmessage(0,"%s has forgiven %s^nand gives him 3 credits back", NameV, NameA)         }                 case 1:{             g_credits[g_menu_attackerid[id]] = g_credits[g_menu_attackerid[id]] + 3             user_slap (g_menu_attackerid[id], 15)             set_hudmessage(0, 90, 235, 0.05, 0.72, 0, 3.0, 11.0, 0.1, 0.5, 9)               show_hudmessage(0,"%s has slaped (15 Hp) %s^nand gives him 3 credits back", NameV, NameA)         }                 case 2:{             set_hudmessage(0, 90, 235, 0.05, 0.72, 0, 3.0, 11.0, 0.1, 0.5, 9)               show_hudmessage(0,"%s does not forgive %s^nbut can do it later by writting forgive", NameV, NameA)         }     }     return PLUGIN_HANDLED } public Menu4(id,key) {     new NameV[32], NameA[32]     get_user_name(id,NameV,31)     get_user_name(g_menu_killerid[id],NameA,31)         switch(key)     {         case 0:{             g_credits[g_menu_killerid[id]] = g_credits[g_menu_killerid[id]] + 4             set_hudmessage(0, 90, 235, 0.05, 0.72, 0, 3.0, 11.0, 0.1, 0.5, 9)               show_hudmessage(0,"%s has forgiven %s^nand gives him 4 credits back", NameV, NameA)         }                 case 1:{             g_credits[g_menu_killerid[id]] = g_credits[g_menu_killerid[id]] + 1             user_slap (g_menu_attackerid[id], 20)             set_hudmessage(0, 90, 235, 0.05, 0.72, 0, 3.0, 11.0, 0.1, 0.5, 9)               show_hudmessage(0,"%s has slaped (20 Hp) %s^nand gives him 4 credits back", NameV, NameA)         }                 case 2:{             set_hudmessage(0, 90, 235, 0.05, 0.72, 0, 3.0, 11.0, 0.1, 0.5, 9)               show_hudmessage(0,"%s does not forgive %s^nbut can do it later by writting forgive", NameV, NameA)         }     }     return PLUGIN_HANDLED } public Menu5(id,key) {     new NameV[32], NameA[32]     get_user_name(id,NameV,31)     get_user_name(g_menu_attackerid[id],NameA,31)         switch(key)     {         case 0:{             g_credits[g_menu_attackerid[id]] = g_credits[g_menu_attackerid[id]] + 5             set_hudmessage(0, 90, 235, 0.05, 0.72, 0, 3.0, 11.0, 0.1, 0.5, 9)               show_hudmessage(0,"%s has forgiven %s^nand gives him 5 credits back", NameV, NameA)         }                 case 1:{             g_credits[g_menu_attackerid[id]] = g_credits[g_menu_attackerid[id]] + 5             user_slap (g_menu_attackerid[id], 30)             set_hudmessage(0, 90, 235, 0.05, 0.72, 0, 3.0, 11.0, 0.1, 0.5, 9)               show_hudmessage(0,"%s has slaped (30 Hp) %s^nand gives him 5 credits back", NameV, NameA)         }                 case 2:{             set_hudmessage(0, 90, 235, 0.05, 0.72, 0, 3.0, 11.0, 0.1, 0.5, 9)               show_hudmessage(0,"%s does not forgive %s^nbut can do it later by writting forgive", NameV, NameA)         }     }     return PLUGIN_HANDLED } public Menu6(id,key) {     new NameV[32], NameA[32]     get_user_name(id,NameV,31)     get_user_name(g_menu_killerid[id],NameA,31)         switch(key)     {         case 0:{             g_credits[g_menu_killerid[id]] = g_credits[g_menu_killerid[id]] + 6             set_hudmessage(0, 90, 235, 0.05, 0.72, 0, 3.0, 11.0, 0.1, 0.5, 9)               show_hudmessage(0,"%s has forgiven %s^nand gives him 6 credits back", NameV, NameA)         }                 case 1:{             g_credits[g_menu_killerid[id]] = g_credits[g_menu_killerid[id]] + 6             user_slap (g_menu_attackerid[id], 40)             set_hudmessage(0, 90, 235, 0.05, 0.72, 0, 3.0, 11.0, 0.1, 0.5, 9)               show_hudmessage(0,"%s has slaped (40 Hp) %s^nand gives him 6 credits back", NameV, NameA)         }                 case 2:{             set_hudmessage(0, 90, 235, 0.05, 0.72, 0, 3.0, 11.0, 0.1, 0.5, 9)               show_hudmessage(0,"%s does not forgive %s^nbut can do it later by writting forgive", NameV, NameA)         }     }     return PLUGIN_HANDLED } public Menu7(id,key) {     new NameV[32], NameA[32]     get_user_name(id,NameV,31)     get_user_name(g_menu_attackerid[id],NameA,31)         switch(key)     {         case 0:{             g_credits[g_menu_attackerid[id]] = g_credits[g_menu_attackerid[id]] + 7             set_hudmessage(0, 90, 235, 0.05, 0.72, 0, 3.0, 11.0, 0.1, 0.5, 9)               show_hudmessage(0,"%s has forgiven %s^nand gives him 7 credits back", NameV, NameA)         }                 case 1:{             set_hudmessage(0, 90, 235, 0.05, 0.72, 0, 3.0, 11.0, 0.1, 0.5, 9)               show_hudmessage(0,"%s does not forgive %s^nbut can do it later by writting forgive", NameV, NameA)         }     }     return PLUGIN_HANDLED } public Menu8(id,key) {     new NameV[32], NameA[32]     get_user_name(id,NameV,31)     get_user_name(g_menu_killerid[id],NameA,31)         switch(key)     {         case 0:{             g_credits[g_menu_killerid[id]] = g_credits[g_menu_killerid[id]] + 7             set_hudmessage(0, 90, 235, 0.05, 0.72, 0, 3.0, 11.0, 0.1, 0.5, 9)               show_hudmessage(0,"%s has forgiven %s^nand gives him 7 credits back", NameV, NameA)         }                 case 1:{             set_hudmessage(0, 90, 235, 0.05, 0.72, 0, 3.0, 11.0, 0.1, 0.5, 9)               show_hudmessage(0,"%s does not forgive %s^nbut can do it later by writting forgive", NameV, NameA)         }     }     return PLUGIN_HANDLED } public delayedmenu(victimid){     new menuBody[192]     new name[32]     get_user_name(g_menu_killerid[victimid],name,31)     new keys = (1<<0)|(1<<1)|(1<<2)|(1<<3)     format(menuBody,120,"-4 credits pour %s:^n1. Pardonner^n2. Gifler de 20Hp et pardonner^n3. Ne pas pardonner",name)     show_menu(victimid,keys,menuBody,40) } public delayedkill(id){     user_kill(id) } public delayedban(userid){     server_cmd("banid %d.0 #%d",g_bantime,userid)     server_cmd("writeid")     server_cmd("kick #%d",userid) } // checks players'chat and forgives until lasts 2 actions if asked public HandleSay(id) {     new text[12]     read_argv(1,text,11)     if ( containi(text,"pardonner") == 0 || containi(text,"pardon") == 0 || containi(text,"forgive") == 0 || containi(text,"forgivetk") == 0 )     {         new menuid, keys         new NameV[32]         new NameA[32]         new userid         set_hudmessage(0, 90, 235, 0.05, 0.72, 0, 3.0, 11.0, 0.1, 0.5, 9)         userid = get_user_userid(id)         if (id == Last1Victim)         {             if (get_user_menu(id,menuid,keys) && (g_menu_attackerid[id]==Last1Attacker || g_menu_killerid[id]==Last1Attacker) ) {                 client_cmd(id,"slot4")                 get_user_name(Last1Victim,NameV,31)                 get_user_name(Last1Attacker,NameA,31)                 g_credits[g_menu_attackerid[id]] = g_credits[g_menu_attackerid[id]] + 4                 show_hudmessage(0,"Finally %s has forgiven %s", NameV, NameA)                 Last1Victim = Last2Victim                 Last1Attacker = Last2Attacker                 Last2Victim = 0                 Last2Attacker = 0                 return PLUGIN_CONTINUE             }             client_print(userid, print_chat, "Sorry it is too late to forgive")         }                 if (id == Last2Victim)         {             if (get_user_menu(id,menuid,keys) && (g_menu_attackerid[id]==Last2Attacker || g_menu_killerid[id]==Last2Attacker) ) {                 client_cmd(id,"slot4")                 get_user_name(Last1Victim,NameV,31)                 get_user_name(Last1Attacker,NameA,31)                 g_credits[g_menu_attackerid[id]] = g_credits[g_menu_attackerid[id]] + 4                 show_hudmessage(0,"Finally %s has forgiven %s", NameV, NameA)                 Last2Victim = 0                 Last2Attacker = 0                 return PLUGIN_CONTINUE                          }             client_print(userid, print_chat, "Sorry it is too late to forgive")                 }             }     return PLUGIN_CONTINUE }


So if some of you wants to have a look and manage to find the errors, I would give them thousands of thanks :D. I have spent 2 weeks to do that, and I think it will be very nice to have a similar plugin on DOD servers. And sorry for my english not very good :?

NB: there is a french version

SidLuke 09-12-2004 18:42

I will try to look at it.

About your code display question. BBCode for this is : . It doesn't work for if you put too many text there ( I wanted to edit your post ).

Colt 09-13-2004 12:14

ahh.. ok!
 
Ok now I understand why it didn't work :evil: So to help you to read, I have cutted it in two parts.

And thanks you for your help :)

Colt 09-18-2004 14:51

menus
 
I've tested it with RC5 but it still doesn't work :( The most recurent problem is with menus.
Nevertheless I've seen that in this forum, I hope it can help me:

Quote:

Having trouble with menu keys? Use these defines

#define MENU_KEY_1 (1<<0)
#define MENU_KEY_2 (1<<1)
#define MENU_KEY_3 (1<<2)
#define MENU_KEY_4 (1<<3)
#define MENU_KEY_5 (1<<4)
#define MENU_KEY_6 (1<<5)
#define MENU_KEY_7 (1<<6)
#define MENU_KEY_8 (1<<7)
#define MENU_KEY_9 (1<<8)
#define MENU_KEY_0 (1<<9)

Then use like key_one|key_two instead of (1<<0)|(1<<1).. Makes your code a lot more readable. These defines will be included in v0.2
Can someone explain me how to proceed? I'm lost with all those variables :? : MENU_KEY_1, (1<<2), key_one...

Colt 09-28-2004 15:53

news
 
New tests with RC6: now when I compile it with RC6 (by changing is_melee to xmod_is_melee_wpn of course :) , I don't get a bad load error anymore, but actually the plugin doesn't run at all now! It happens nothing in the game :(

I've tried with amx_debug set to 0, 1 or 2 without difference. And of course necessary modules are loaded.

Please does someone have an idea to solve that? I am very sad for all this time spent on this project :( :( :(

SidLuke 09-28-2004 16:47

change damage_info to client_damage , death_info to client_death and register_statsfwd , example how to use it you can find in stats.sma from dod package.

Colt 09-29-2004 13:03

ok but not yet finished
 
Thank you it works on RC6 now :D ! Sorry I did not see functions have changed theirs names :?

I have still my old bugs, but now I can test them with a better version of AMXX :)

I have seen you have made a nice work with stats.sma, congratulations! And I have found in your code a flag (for wpnindex) I needed: DODW_MORTAR . Before that, I could not detect an attack with this weapon (wpnindex returned nothing).
And I've just seen a new documentation for dodx. Nice!

AND AGAIN THANK YOU! :up:

NB: I have edited the files and the code.

Colt 10-02-2004 11:57

news!
 
The end is close, but I have a new problem :(

I want to make a menu as the "Ban Menu", so that an admin can give credits to a player. The menu is displayed when the admin writes the command. To simplify, I have just pasted the code of the menu:

Code:
new g_menuPosition[33] new g_menuPlayers[33][32] new g_menuPlayersNum[33] new g_menuOption[33] new g_menuCredits[33] public plugin_init() {     register_menucmd(register_menuid("Credits Menu"),1023,"credits_menu")     return PLUGIN_CONTINUE } displayCreditsMenu(id,pos) {   if (pos < 0)  return       get_players(g_menuPlayers[id],g_menuPlayersNum[id])       new menuBody[512]   new b = 0   new i   new name[32]   new start = pos * 7     if (start >= g_menuPlayersNum[id])     start = pos = g_menuPosition[id] = 0       new len = format(menuBody,511,"\yPage %d/%d^nKey Credits Player\w^n^n" ,pos+1,(  g_menuPlayersNum[id] / 7 + ((g_menuPlayersNum[id] % 7) ? 1 : 0 )) )   new end = start + 7   new keys = MENU_KEY_0|MENU_KEY_8   if (end > g_menuPlayersNum[id])     end = g_menuPlayersNum[id]       for (new a = start; a < end; ++a) {     i = g_menuPlayers[id][a]     keys |= (1<<b)     get_user_name(i,name,31)     if ( g_credits[i]<5 ) // set credits in red if <5, if not in blue       len += format(menuBody[len],511-len,"%d. \r%d \w%s^n",++b,g_credits[i],name)     else       len += format(menuBody[len],511-len,"%d. \b%d \w%s^n",++b,g_credits[i],name)   }   if ( !g_menuCredits[id] ) // set  by default the credits to 10 to give     g_menuCredits[id]=10   len += format(menuBody[len],511-len,"^n\y8. Give %d credits^n", g_menuCredits[id] )   if (end != g_menuPlayersNum[id]) {     keys |= MENU_KEY_9       format(menuBody[len],511-len,"^n\y9. Next...^n0. ...Back\w")   }   else format(menuBody[len],511-len,"^n\y0. ...Back\w")   show_menu(id,keys,menuBody,-1,"Credits Menu") } public credits_menu(id,key) {   switch (key) {     case 7: { // change the value of credits to give       ++g_menuOption[id]       g_menuOption[id] %= 3             switch(g_menuOption[id]){       case 0: g_menuCredits[id] = 10       case 1: g_menuCredits[id] = 20       case 2: g_menuCredits[id] = 5       }           displayCreditsMenu(id,g_menuPosition[id])     }     case 8: displayCreditsMenu(id,++g_menuPosition[id]) // go to the next page     case 9: displayCreditsMenu(id,--g_menuPosition[id]) // go to the previous page     default: {       new player = g_menuPlayers[id][g_menuPosition[id] * 7 + key]       new nameplayer[32]       new nameadmin[32]       get_user_name(player,nameplayer,31)       get_user_name(id,nameadmin,31)       set_hudmessage(255, 0, 0, 0.05, 0.6, 0, 8.0, 10.0, 0.1, 0.5, 8)       g_credits[player]+=g_menuCredits[player]       show_hudmessage(0,"The ADMIN %s^nhas given %d credits to %s", nameadmin, g_menuCredits[player], nameplayer)             displayCreditsMenu(id,g_menuPosition[id])     }   }     return PLUGIN_HANDLED }

So what is the problem? The first time, the menu works fine, I can change the credits value and give credits to players.

But the second time (when the menu has been closed and opened back), whatever the key I press, the menu closes and nothing happens! And with debug mod, AMXX says:
Code:

[AMXX] Run time error 4 (index out of bounds) on line 751 (plugin "dod_ff_manager.amxx").
Line 751 is the line
Code:
new player = g_menuPlayers[id][g_menuPosition[id] * 7 + key]

And sometimes, the server's console says too:
Code:

"Can't set * keys"
I've spent 4 hours with changing definitions of keys (MENU_KEY_X or 1<<X) but it does the same thing.

Please help me :( , 1 month on this plugin... :?

Colt 10-05-2004 11:03

I don't undestand... I thought many persons would be interested in this plugin. When there is no admin on the server, players who shoot theirs teamates witout killing them are not punished.

I know my code is not entirely mine, for example to create credits files in the logcredits directory (hard for my level :? )
But I can assure you I have spent hours and hours to find from where could come bugs, but I failed. When I read the part of the code, everything seems to be clear.

Example: when there is a spawn attack, it is detected, displays the hud message and removes credits. But the player is rarely slayed. I insist on the rarely. Why? I can't understand that! Please look at the following code:

Code:
public client_death(killer,victim,wpnindex,hitplace,TK) { //... killerid = get_user_userid(killer) //... if ( get_gametime() - g_SpawnTime[victim] < get_cvar_float("amx_ffm_protectiontime") ){         g_credits[attacker] += -7         g_creditsloss[victim] = 7         set_task(0.5,"delayedkill",killerid)         set_hudmessage(255, 0, 255, 0.05, 0.8, 0, 4.0, 11.0, 0.1, 0.5, 8)           show_hudmessage(0,"%s slayed to have killed an ally at spawn^nand losses 7 credits he has %i remaining!", name, g_credits[attacker])         format(menuBody,120,"-7 credits for %s:^n\d1. Forgive^n\r2. Do not forgive",name)         show_menu(victim,keys,menuBody,40)         Check_credits(attacker)         log_message("[DOD FF MANAGER] %s attacked an ally at spawn and he has %i credits remaining!",name, g_credits[attacker])         return PLUGIN_CONTINUE     } } public delayedkill(id){     user_kill(id) }

(The slay must be delayed, because if it is done at the same time, the server crashes, SidLuke has found it)

If the player wasn't slayed at all, I would say: OK, there is a problem, let's code it differently. But sometimes it works (~10%), and some other it does NOT (~90%)! Why ?!!!!! :evil:

And it is the same case for other bugs (the ban of the player, Admin credits menu which works only one time per map, etc.)

I supply you, I just ask you to look at these 10 lines of code and say me if you see the problem, because me I don't :( :( :( :( :( :( :( :(

SidLuke 10-05-2004 11:36

set_task(0.5,"delayedkill",attackerid) , I see you are using attacker everywhere in the code not attackerid. Maybe you don't set attackerid right ?


All times are GMT -4. The time now is 17:27.

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