Raised This Month: $ Target: $400
 0% 

Plugin works (allmost) but how should i have done?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
sluggo
Member
Join Date: May 2006
Old 10-12-2006 , 15:23   Plugin works (allmost) but how should i have done?
Reply With Quote #1

Hi,
I have made a script/plugin that works, allmost as I want it to, there is something wrong with how many "last dissconnect players" it shows. It tends to show 1 to many but that doesn't matter really :p
I set out to make the script myselfe, and it works but I need help with tweaking it, my coding is terrible I know but I would like to learn.
So if anyone could give me some pointers to how some of the things I have done SHOULD be done I would greatly appreaschiate (spelling?) it.

What does the plugin do then, well it saves the last 32 players who dissconnect and when you say "/last" it shows you the last amx_showlast "x" players. (max 10 b/c I cant code propperly)
We will use it on our servers when ppl say/do something stupid and drops, especially when several ppl drops at the same time.
Enough, here is the code:
Code:
/* Made by sluggo Admins with "ADMIN_CHAT" can type team_say: /last to see the "amx_showlast" default=3 latest players to dissconnect from server. Good if someone says something nasty and drops. Credits to v3x, i borrowed the structure from his "player disconnect info plugin" */ #include <amxmodx> #include <amxmisc> #define PLUGIN "Last Players" #define VERSION "0.8" #define AUTHOR "sluggo" //comment out to not have the plugin print to all in chat when someone dissconnects // #define DEBUG // Change this to what level you want your admins to be able to issue the command #define ACCESS_LEVEL ADMIN_KICK new g_szLastPlrAuth[33][33] new g_szLastPlrName[33][33] new iCountDiss public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)     register_clcmd("say /last", "leftserver", ACCESS_LEVEL, "- displays in consol and chat the last players to admins")     register_cvar("amx_showlast","3")   //default 3 last players should show. Max 10     register_cvar("amx_showdissconnects", "0") //show when someone dissconnects 0 = off 1=on } public client_disconnect(id) {     if(is_user_bot(id) || (is_user_hltv(id))) {         return PLUGIN_CONTINUE     }     iCountDiss = iCountDiss + 1     if (iCountDiss == 0) {         iCountDiss = 1     }     if (iCountDiss > 32) {                 new i = get_cvar_num("amx_showlast")         if(i>10) {             i=10         }         iCountDiss = i + 1         new c, iMaxUser //just a counter...         iMaxUser = 32         for(c = 1;c <= i; c++) {             copy(g_szLastPlrName[iMaxUser - i + c],32,g_szLastPlrName[c])         }     }     get_user_name(id, g_szLastPlrName[iCountDiss], 32);     get_user_authid(id, g_szLastPlrAuth[iCountDiss], 32);     if(get_cvar_num("amx_showdissconnects") == 1) {         client_print(0,print_chat, "Nick: %s SteamID: %s dissconnected", g_szLastPlrName[id], g_szLastPlrAuth[id]);     }     return PLUGIN_CONTINUE } public leftserver(id) //id of the one who issued the command {     new i, k // counters     if(iCountDiss <= get_cvar_num("amx_showlast")){         k = 1 // make sure at least 1 is going to show     }     else{           k = iCountDiss - get_cvar_num("amx_showlast")     }     for(i = k; i <= iCountDiss; i++) {         client_print(id,print_chat, "[Nick] %s - [SteamID] %s", g_szLastPlrName[i], g_szLastPlrAuth[i]);         console_print(id,"[Nick] %s - [SteamID] %s", g_szLastPlrName[i], g_szLastPlrAuth[i]); #if defined DEBUG     server_print(g_szLastPlrName[i])     server_print(g_szLastPlrName[i])     server_print("%i", i) #endif     }     return PLUGIN_CONTINUE }
sluggo is offline
schnitzelmaker
Senior Member
Join Date: Apr 2006
Location: HERE
Old 10-12-2006 , 15:53   Re: Plugin works (allmost) but how should i have done?
Reply With Quote #2

i think it is the typical "for" problem:
here what i mean:
Code:
new i, k //i,k have 0 for(i = k; i <= iCountDiss; i++) { //increase every loop i to "<=" icountDiss(33). }

"<=" mean increase the "i" until it is higher that icountDiss, and this is 33 not 32.
and i are increase every loop.A little script to show it.
Code:
new i for(i=0;i<=10;i++)   {    client_print(id,print_chat,"i:%d",i) //i begin with 0,but end with 11   } //i have now 11 not 10

I make this most also wrong.

And a little tip,you can also write this
Code:
iCountDiss = iCountDiss + 1
same effect
Code:
iCountDiss += 1
or
Code:
iCountDiss++

a little better
Code:
public client_disconnect(id) {     if(is_user_bot(id) || (is_user_hltv(id))) {         return PLUGIN_CONTINUE     }     if (iCountDiss > 32) {         new iMaxUser = 32         for(new c = 0;c < iMaxUser; c++) {             copy(g_szLastPlrName[c],32,g_szLastPlrName[c+1])         }//this copy every playername 1 slot backwards and put the oldest out.     else iCountDiss++     get_user_name(id, g_szLastPlrName[iCountDiss], 32);     get_user_authid(id, g_szLastPlrAuth[iCountDiss], 32);     if(get_cvar_num("amx_showdissconnects") == 1) {         client_print(0,print_chat, "Nick: %s SteamID: %s dissconnected", g_szLastPlrName[id], g_szLastPlrAuth[id]);     }     //return PLUGIN_CONTINUE optional, not needed } public leftserver(id) //id of the one who issued the command {     new k = iCountDiss-get_cvar_num("amx_showlast")     if(k<0)         k= 0 //arrays begin with 0     for(new i = iCountDiss;i>=k ; i--) {         client_print(id,print_chat, "[Nick] %s - [SteamID] %s", g_szLastPlrName[i], g_szLastPlrAuth[i]);         console_print(id,"[Nick] %s - [SteamID] %s", g_szLastPlrName[i], g_szLastPlrAuth[i]); #if defined DEBUG     server_print(g_szLastPlrName[i])     server_print(g_szLastPlrName[i])     server_print("%i", i) #endif     }     //return PLUGIN_CONTINUE optional, not needed }
__________________

Last edited by schnitzelmaker; 10-12-2006 at 16:29.
schnitzelmaker is offline
sluggo
Member
Join Date: May 2006
Old 10-12-2006 , 17:41   Re: Plugin works (allmost) but how should i have done?
Reply With Quote #3

Thank you for your answer
I wondered how to get the for-loop to go backwards, but i gave up and did it another way. Thanks

And I seem never to be able to get the > < = correct, trial and error doesn't allways work :S

Thank you again, I will compare our codes and try to learn as much as possible
+karma!
sluggo is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:52.


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