PDA

View Full Version : Motd Output problems/help


atomen
04-29-2008, 14:54
Hi !

I've been making a n00b script to understand
and learn how to create a motd window.

The output isn't like I want. Here's the pic
http://sleekupload.com/uploads/top_wannabe.bmp
I want to make so multiple people is displayed. Not by saving to file if possible.

As you can see in the script they get 1 more kill/death when they kill/die.
But it always says 0 in the output. The only thing that is working is there name.

Though only 1 person is displayed. The last one who killed. Here's the script (don't care about the menu) :
#include <amxmodx>
#include <amxmisc>
#include <hamsandwich>

#define gPLUGIN "Top15 Wannabe"
#define gVERSION "1.0"
#define gAUTHOR "Atomen"

#define FUNNY_LENGTH 2047

new pcvar, name[26], g_sBuffer[FUNNY_LENGTH +1] = ""
new kills[33], deaths[33]

public plugin_init()
{
register_plugin(gPLUGIN, gVERSION, gAUTHOR)
RegisterHam(Ham_Killed, "player", "fwd_Ham_Killed_post", 1)

register_clcmd("say .tp15", "Open_Menu")

pcvar = register_cvar("amx_top15_wannabe", "1")
g_sBuffer[0] = 0
}

public fwd_Ham_Killed_post(Victim, Attacker)
{
if(get_pcvar_num(pcvar) && is_user_connected(Victim))
{
get_user_name(Victim, name, 25)
get_user_name(Attacker, name, 25)

deaths[Victim]++
kills[Attacker]++
}
return HAM_IGNORED
}

public Open_Menu(id)
{
new menu = menu_create("\rTop 15 Wannabe Menu", "menu_handler")

menu_additem(menu, "\wOpen top15 Wannabe top", "1")
menu_additem(menu, "\wPress me and I'll say something", "2")

menu_setprop(menu, MPROP_EXIT, MEXIT_ALL)
menu_display(id, menu, 0)
}

public menu_handler(id, menu, item)
{
if(item == MENU_EXIT)
{
menu_destroy(menu)
return 1
}

new data[6], iName[64]
new access, callback

menu_item_getinfo(menu, item, access, data, 5, iName, 63, callback)

new key = str_to_num(data)

switch(key)
{
case 1:
{
client_print(id, print_chat, "[TOP15] Opening the wannabe window")
motd_wannabe(id)

return 1
}

case 2:
{
client_print(id, print_chat, "[TOP15] Hope you loved this text")
}
}

menu_destroy(menu)
return 1
}

public motd_wannabe(id)
{
format_top15_wannabe(g_sBuffer)
show_motd(id, g_sBuffer, "Top 15 Wannabe")

return 0
}

format_top15_wannabe(sBuffer[FUNNY_LENGTH + 1])
{
new iLen;

iLen = format(sBuffer, FUNNY_LENGTH, "<body bgcolor=rgb(0,0,0)><font color=#FFB000><pre>")
iLen += format(sBuffer[iLen], FUNNY_LENGTH - iLen, "# Name Kills Deaths")

iLen += format(sBuffer[iLen], FUNNY_LENGTH - iLen, "^n%s %d %d", name, deaths, kills)
}NOTE : some code taken from statsx plugin.

atomen
04-29-2008, 17:29
Okay, I've located the problem but I don't know why I'm receiving it(I know it is because [33] is to small, but why ?).
This is the debug report.
L 04/29/2008 - 23:18:19: Start of error session.
L 04/29/2008 - 23:18:19: Info (map "de_dust2") (file "addons/amxmodx/logs/error_20080429.log")
L 04/29/2008 - 23:18:19: [AMXX] Displaying debug trace (plugin "top15_wannabe.amxx")
L 04/29/2008 - 23:18:19: [AMXX] Run time error 4: index out of bounds
L 04/29/2008 - 23:18:19: [AMXX] [0] top15_wannabe.sma::fwd_Ham_Killed_post (line 50)
Here's the code :
//...

new kills[33], deaths[33]

//...

public plugin_init()
{
//...
RegisterHam(Ham_Killed, "player", "fwd_Ham_Killed_post", 1)
}

//...

public fwd_Ham_Killed_post(const Victim, const Attacker, const gibbed)
{
if(get_pcvar_num(pcvar) && is_user_connected(Victim))
{
get_user_name(Victim, name, 32)
get_user_name(Attacker, name, 32)

deaths[Victim] = get_user_deaths(Victim)
@@ kills[Attacker] = get_user_frags(Attacker) //Line 50, Though i think line 49 is wrong 2

log_amx("[KILL] Deaths : %d Kills : %d", deaths, kills)
}
return HAM_IGNORED
}

v3x
04-29-2008, 17:46
Which line is #50?

atomen
04-30-2008, 01:54
Sry :/

Edited second post. Though I think there is a problem with line 49 too.
Because deaths[33] is always having zero in value.

Styles
04-30-2008, 02:02
Well first, try getting the args right for Ham_Killed o.0

public fwd_Ham_Killed_post(const id, const attacker, const gibbed)

atomen
04-30-2008, 02:19
Still receiving the same error as before.
Any more clues ?

Styles
04-30-2008, 02:27
just do is_user_connected(Attacker) kills[Attacker] = get_user_frags(Attacker)

You don't know if the killer will be world or w/e :P same w/ victim though..

atomen
04-30-2008, 02:28
I might know the problem but I'm not totally sure.
I'm testing with bots, could that create a problem ?

EDIT: Wasn't the problem. deaths and kills are still returning 0 value.

v3x
04-30-2008, 04:45
Post your updated code, please.

Off-Topic: How do you highlight a single line like that within the [small] tags?

atomen
04-30-2008, 06:56
Current Code :
#include <amxmodx>
#include <amxmisc>
#include <hamsandwich>

#define gPLUGIN "Top15 Wannabe"
#define gVERSION "1.0"
#define gAUTHOR "Atomen"

#define MOTD_LENGTH 2047

new pcvar, name[31], g_sBuffer[MOTD_LENGTH +1] = ""
new kills[33], deaths[33], menu

public plugin_init()
{
//Register Plugin
register_plugin(gPLUGIN, gVERSION, gAUTHOR)

//Register Client Death
RegisterHam(Ham_Killed, "player", "fwd_Ham_Killed_post", 1)

//Create menu
menu = menu_create("\rTop 15 Wannabe Menu", "menu_handler")

//Add menu Items
menu_additem(menu, "\r1. \wOpen top15 Wannabe top", "1")
menu_additem(menu, "\r2. \wPress me and I'll say something", "2")
menu_additem(menu, "^n\r3. \w Exit")

menu_setprop(menu, MPROP_EXIT, MEXIT_ALL)

//Register Say Command
register_clcmd("say .tp15", "Open_Menu")

//Create Cvars
pcvar = register_cvar("amx_top15_wannabe", "1")

//Other
g_sBuffer[0] = 0
}

public fwd_Ham_Killed_post(const id, const attacker, const gibbed)
{
if(get_pcvar_num(pcvar))
{
if(is_user_connected(id))
{
get_user_name(id, name, 30)
deaths[id] = get_user_deaths(id)
}

if(is_user_connected(attacker))
{
get_user_name(attacker, name, 32)
kills[attacker] = get_user_frags(attacker)
}

log_amx("[KILL] Deaths : %d Kills : %d", deaths, kills)
}
return HAM_IGNORED
}

public Open_Menu(id)
{
menu_display(id, menu, 0)
return 1
}

public menu_handler(id, menu, item)
{
if(item == MENU_EXIT)
{
menu_destroy(menu)
return 1
}

new data[6], iName[64]
new access, callback

menu_item_getinfo(menu, item, access, data, 5, iName, 63, callback)

new key = str_to_num(data)

switch(key)
{
case 1:
{
client_print(id, print_chat, "[TOP15] Opening the wannabe window")
motd_wannabe(id)

return 1
}

case 2:
client_print(id, print_chat, "[TOP15] Hope you loved this text")
}

menu_destroy(menu)
return 1
}

public motd_wannabe(id)
{
format_top15_wannabe(g_sBuffer)
show_motd(id, g_sBuffer, "Top 15 Wannabe")

return 0
}

format_top15_wannabe(sBuffer[MOTD_LENGTH + 1])
{
new iLen, num, players[32]
get_players(players, num, "ah")

iLen = format(sBuffer, MOTD_LENGTH, "<body bgcolor=rgb(0,0,0)><font color=#FFB000><pre>")
iLen += format(sBuffer[iLen], MOTD_LENGTH - iLen, "%2s %-22.22s %6s %6s", "#", "Name", "Kills", "Deaths")

iLen += format(sBuffer[iLen], MOTD_LENGTH - iLen, "^n%-22.22s %6d %6d", name, deaths, kills)

log_amx("[KILL] Deaths : %d Kills : %d", deaths, kills)
}Off-Topic: Put 2 @ at the beginning of the line.

v3x
04-30-2008, 07:28
I can't believe that I didn't see this earlier.

log_amx("[KILL] Deaths : %d Kills : %d", deaths, kills)

You need to index the deaths and kills variables. That's your error right there.

atomen
04-30-2008, 07:36
But here for example, what should I do since I'm receiving "undefinied symbol:id/attacker".
format_top15_wannabe(sBuffer[MOTD_LENGTH + 1])
{
new iLen, num, players[32]
get_players(players, num, "ah")

iLen = format(sBuffer, MOTD_LENGTH, "<body bgcolor=rgb(0,0,0)><font color=#FFB000><pre>")
iLen += format(sBuffer[iLen], MOTD_LENGTH - iLen, "%2s %-22.22s %6s %6s", "#", "Name", "Kills", "Deaths")

iLen += format(sBuffer[iLen], MOTD_LENGTH - iLen, "^n%-22.22s %6d %6d", name, deaths, kills)

@@ log_amx("[KILL] Deaths : %d Kills : %d", deaths[id], kills[attacker])
}

v3x
04-30-2008, 07:47
Make a variable like attackerid[33] and store the attacker's ID in there for that player's index. Then do kills[attackerid[id]]. Same goes for deaths.

You will also have to pass id through your format_top15_wannabe function.

atomen
04-30-2008, 07:57
Thank you v3x :]

Though I want to fix 1 more thing.
As it is for now only the last player who killed is
displayed in the top.

I've done a try but it didn't work so good.
Only 1 person is displayed repetitively.

Here's my current code :
#include <amxmodx>
#include <amxmisc>
#include <hamsandwich>

#define gPLUGIN "Top15 Wannabe"
#define gVERSION "1.0"
#define gAUTHOR "Atomen"

#define MOTD_LENGTH 2047

new pcvar, name[31], g_sBuffer[MOTD_LENGTH +1] = ""
new kills[33], deaths[33], menu, victim, killer

public plugin_init()
{
//Register Plugin
register_plugin(gPLUGIN, gVERSION, gAUTHOR)

//Register Client Death
RegisterHam(Ham_Killed, "player", "fwd_Ham_Killed_post", 1)

//Create menu
menu = menu_create("\rTop 15 Wannabe Menu", "menu_handler")

//Add menu Items
menu_additem(menu, "\r1. \wOpen top15 Wannabe top", "1")
menu_additem(menu, "\r2. \wPress me and I'll say something", "2")
menu_additem(menu, "^n\r3. \w Exit")

menu_setprop(menu, MPROP_EXIT, MEXIT_ALL)

//Register Say Command
register_clcmd("say .tp15", "Open_Menu")

//Create Cvars
pcvar = register_cvar("amx_top15_wannabe", "1")

//Other
g_sBuffer[0] = 0
}

public fwd_Ham_Killed_post(const id, const attacker, const gibbed)
{
if(get_pcvar_num(pcvar))
{
if(is_user_connected(id))
{
get_user_name(id, name, 30)
deaths[id] = get_user_deaths(id)
}

if(is_user_connected(attacker))
{
get_user_name(attacker, name, 32)
kills[attacker] = get_user_frags(attacker)
}
victim = id
killer = attacker

log_amx("[KILL] Deaths : %d Kills : %d", deaths[id], kills[attacker])
}
return HAM_IGNORED
}

public Open_Menu(id)
{
menu_display(id, menu, 1)
return 1
}

public menu_handler(id, menu, item)
{
if(item == MENU_EXIT)
{
menu_destroy(menu)
return 1
}

new data[6], iName[64]
new access, callback

menu_item_getinfo(menu, item, access, data, 5, iName, 63, callback)

new key = str_to_num(data)

switch(key)
{
case 1:
{
client_print(id, print_chat, "[TOP15] Opening the wannabe window")
motd_wannabe(id)

return 1
}

case 2:
client_print(id, print_chat, "[TOP15] Hope you loved this text")
}

menu_destroy(menu)
return 1
}

public motd_wannabe(id)
{
format_top15_wannabe(g_sBuffer)
show_motd(id, g_sBuffer, "Top 15 Wannabe")

return 0
}

format_top15_wannabe(sBuffer[MOTD_LENGTH + 1])
{
new iLen, num, players[32]
get_players(players, num, "ah")

iLen = format(sBuffer, MOTD_LENGTH, "<body bgcolor=rgb(0,0,0)><font color=#FFB000><pre>")
iLen += format(sBuffer[iLen], MOTD_LENGTH - iLen, "%2s %-22.22s %6s %6s", "#", "Name", "Kills", "Deaths")

@@ for(new i = 0; i < num; i++) //This is my try, ain't working good.
{
iLen += format(sBuffer[iLen], MOTD_LENGTH - iLen, "^n%-22.22s %6d %6d", name, deaths[victim], kills[killer])
}
log_amx("[KILL] Deaths : %d Kills : %d", deaths[victim], kills[killer])
}

shine771
04-30-2008, 11:13
#include <amxmodx>
#include <hamsandwich>

#define gPLUGIN "Top15 Wannabe"
#define gVERSION "1.0"
#define gAUTHOR "Atomen"

#define MOTD_LENGTH 2047

new pcvar, g_sBuffer[MOTD_LENGTH +1] = ""
new kills[33], deaths[33], menu

public plugin_init()
{
//Register Plugin
register_plugin(gPLUGIN, gVERSION, gAUTHOR)

//Register Client Death
RegisterHam(Ham_Killed, "player", "fwd_Ham_Killed_post", 1)

//Create menu
menu = menu_create("\rTop 15 Wannabe Menu", "menu_handler")

//Add menu Items
menu_additem(menu, "\r1. \wOpen top15 Wannabe top", "1")
menu_additem(menu, "\r2. \wPress me and I'll say something", "2")
menu_additem(menu, "^n\r3. \w Exit")

menu_setprop(menu, MPROP_EXIT, MEXIT_ALL)

//Register Say Command
register_clcmd("say .tp15", "Open_Menu")

//Create Cvars
pcvar = register_cvar("amx_top15_wannabe", "1")

//Other
g_sBuffer[0] = 0
}

public fwd_Ham_Killed_post(const id, const attacker, const gibbed)
{
if(get_pcvar_num(pcvar))
{
deaths[id] = get_user_deaths(id)
kills[attacker] = get_user_frags(attacker)

log_amx("[KILL] Deaths : %d Kills : %d", deaths[id], kills[id])
}
return HAM_IGNORED
}

public Open_Menu(id)
{
menu_display(id, menu, 1)
return 1
}

public menu_handler(id, menu, item)
{
if(item == MENU_EXIT)
{
menu_destroy(menu)
return 1
}

new data[6], iName[64]
new access, callback

menu_item_getinfo(menu, item, access, data, 5, iName, 63, callback)

new key = str_to_num(data)

switch(key)
{
case 1:
{
client_print(id, print_chat, "[TOP15] Opening the wannabe window")
motd_wannabe(id)

return 1
}

case 2:
client_print(id, print_chat, "[TOP15] Hope you loved this text")
}

menu_destroy(menu)
return 1
}

public motd_wannabe(id)
{
format_top15_wannabe(g_sBuffer)
show_motd(id, g_sBuffer, "Top 15 Wannabe")

return 0
}

format_top15_wannabe(sBuffer[MOTD_LENGTH + 1])
{
new iLen, num, players[32]
get_players(players, num, "h")

iLen = format(sBuffer, MOTD_LENGTH, "<body bgcolor=rgb(0,0,0)><font color=#FFB000><pre>")
iLen += format(sBuffer[iLen], MOTD_LENGTH - iLen, "%2s %-22.22s %6s %6s", "#", "Name", "Kills", "Deaths")

for(new i = 0; i < num; i++)
{
new name[32], rdeaths, rkills

rdeaths = str_to_num(deaths[players[i]])
rkills = str_to_num(kills[players[i]])

get_user_name(players[i],name,31)

iLen += format(sBuffer[iLen], MOTD_LENGTH - iLen, "^n%-22.22s %6d %6d", name, rkills, rdeaths)
}
}

atomen
04-30-2008, 11:46
Thanks Shine !

Though I'm receiving an error with the script. Debug Log
L 04/30/2008 - 17:41:24: Start of error session.
L 04/30/2008 - 17:41:24: Info (map "de_cbble") (file "addons/amxmodx/logs/error_20080430.log")
L 04/30/2008 - 17:41:24: [AMXX] Displaying debug trace (plugin "top15_wannabe.amxx")
L 04/30/2008 - 17:41:24: [AMXX] Run time error 4: index out of bounds
L 04/30/2008 - 17:41:24: [AMXX] [0] top15_wannabe.sma::fwd_Ham_Killed_post (line 36)
Current script (Removed Menu)
#include <amxmodx>
#include <hamsandwich>

#define gPLUGIN "Top15 Wannabe"
#define gVERSION "1.0"
#define gAUTHOR "Atomen"

#define MOTD_LENGTH 2047

new pcvar, g_sBuffer[MOTD_LENGTH +1] = ""
new kills[33], deaths[33]

public plugin_init()
{
//Register Plugin
register_plugin(gPLUGIN, gVERSION, gAUTHOR)

//Register Client Death
RegisterHam(Ham_Killed, "player", "fwd_Ham_Killed_post", 1)

//Register Say Command
register_clcmd("say .tp15", "motd_wannabe")

//Create Cvars
pcvar = register_cvar("amx_top15_wannabe", "1")

//Other
g_sBuffer[0] = 0
}

public fwd_Ham_Killed_post(const id, const attacker, const gibbed)
{
if(get_pcvar_num(pcvar))
{
deaths[id] = get_user_deaths(id)
@@ kills[attacker] = get_user_frags(attacker) //Line 36

log_amx("[KILL] Deaths : %d Kills : %d", deaths[id], kills[id])
}
return HAM_IGNORED
}

public motd_wannabe(id)
{
if(get_pcvar_num(pcvar))
{
format_top15_wannabe(g_sBuffer)
show_motd(id, g_sBuffer, "Top 15 Wannabe")
}

return 0
}

format_top15_wannabe(sBuffer[MOTD_LENGTH + 1])
{
new iLen, num, players[32]
get_players(players, num, "h")

iLen = format(sBuffer, MOTD_LENGTH, "<body bgcolor=rgb(0,0,0)><font color=#FFB000><pre>")
iLen += format(sBuffer[iLen], MOTD_LENGTH - iLen, "%2s %-22.22s %6s %6s", "#", "Name", "Kills", "Deaths")

for(new i = 0; i < num; i++)
{
new name[32], rdeaths, rkills

rdeaths = str_to_num(deaths[players[i]])
rkills = str_to_num(kills[players[i]])

get_user_name(players[i],name,31)

iLen += format(sBuffer[iLen], MOTD_LENGTH - iLen, "^n%-22.22s %6d %6d", name, rkills, rdeaths)
}
}

shine771
04-30-2008, 12:01
Try this.. Last time i messed a little up the code xD. And i suggest you to reset kills/deaths on disconnect or the next player who enters the server after the last player who left will gain those kills/deaths. Ok the code:
#include <amxmodx>
#include <hamsandwich>

#define gPLUGIN "Top15 Wannabe"
#define gVERSION "1.0"
#define gAUTHOR "Atomen"

#define MOTD_LENGTH 2047

new pcvar, g_sBuffer[MOTD_LENGTH +1] = ""
new kills[33], deaths[33]

public plugin_init()
{
//Register Plugin
register_plugin(gPLUGIN, gVERSION, gAUTHOR)

//Register Client Death
RegisterHam(Ham_Killed, "player", "fwd_Ham_Killed_post", 1)

//Register Say Command
register_clcmd("say .tp15", "motd_wannabe")

//Create Cvars
pcvar = register_cvar("amx_top15_wannabe", "1")

//Other
g_sBuffer[0] = 0
}

public fwd_Ham_Killed_post(const id, const attacker, const gibbed)
{
if(get_pcvar_num(pcvar))
{
deaths[id] = get_user_deaths(id)
kills[attacker] = get_user_frags(attacker) //Line 36

log_amx("[KILL] Deaths : %d Kills : %d", deaths[id], kills[id])
}
return HAM_IGNORED
}

public motd_wannabe(id)
{
if(get_pcvar_num(pcvar))
{
format_top15_wannabe(g_sBuffer)
show_motd(id, g_sBuffer, "Top 15 Wannabe")
}

return 0
}

format_top15_wannabe(sBuffer[MOTD_LENGTH + 1])
{
new iLen, num, players[32]
get_players(players, num, "h")

iLen = format(sBuffer, MOTD_LENGTH, "<body bgcolor=rgb(0,0,0)><font color=#FFB000><pre>")
iLen += format(sBuffer[iLen], MOTD_LENGTH - iLen, "%2s %-22.22s %6s %6s", "#", "Name", "Kills", "Deaths")

for(new i = 0; i < num; i++)
{
new name[32]
get_user_name(players[i],name,31)

iLen += format(sBuffer[iLen], MOTD_LENGTH - iLen, "^n%-22.22s %6d %6d", name, deaths[players[i]], deaths[players[i]])
}
}

public client_disconnect(id) { deaths[id]=0 ; kills[id]=0;}

atomen
04-30-2008, 12:13
Thank you Shine !
Works perfect now.

Just 1 more question. How could I sort the list
so the 1 with most kills is highest up ?

Here's the code
#include <amxmodx>
#include <hamsandwich>

#define gPLUGIN "Top15 Wannabe"
#define gVERSION "1.0"
#define gAUTHOR "Atomen"

#define MOTD_LENGTH 2047

new pcvar, g_sBuffer[MOTD_LENGTH +1] = ""
new kills[33], deaths[33]

public plugin_init()
{
//Register Plugin
register_plugin(gPLUGIN, gVERSION, gAUTHOR)

//Register Client Death
RegisterHam(Ham_Killed, "player", "fwd_Ham_Killed_post", 1)

//Register Say Command
register_clcmd("say .tp15", "motd_wannabe")

//Create Cvars
pcvar = register_cvar("amx_top15_wannabe", "1")

//Other
g_sBuffer[0] = 0
}

public fwd_Ham_Killed_post(const id, const attacker, const gibbed)
{
if(get_pcvar_num(pcvar))
{
if(is_user_connected(id)) deaths[id] = get_user_deaths(id)
if(is_user_connected(attacker)) kills[attacker] = get_user_frags(attacker)

log_amx("[KILL] Deaths : %d Kills : %d", deaths[id], kills[id])
}
return HAM_IGNORED
}

public motd_wannabe(id)
{
if(get_pcvar_num(pcvar))
{
format_top15_wannabe(g_sBuffer)
show_motd(id, g_sBuffer, "Top 15 Wannabe")
}

return 0
}

format_top15_wannabe(sBuffer[MOTD_LENGTH + 1])
{
new iLen, num, players[32]
get_players(players, num, "h")

iLen = format(sBuffer, MOTD_LENGTH, "<body bgcolor=rgb(0,0,0)><font color=#FFB000><pre>")
iLen += format(sBuffer[iLen], MOTD_LENGTH - iLen, "%2s %-22.22s %6s %6s", "#", "Name", "Kills", "Deaths")

for(new i = 0; i < num; i++)
{
new name[32]
get_user_name(players[i],name,31)

iLen += format(sBuffer[iLen], MOTD_LENGTH - iLen, "^n%-22.22s %6d %6d", name, kills[players[i]], deaths[players[i]])
log_amx("[r] Deaths : %d Kills : %d", deaths[players[i]], kills[players[i]])
}
}

public client_disconnect(id) { deaths[id]=0 ; kills[id]=0;}

shine771
04-30-2008, 13:22
It's not really easy.. at least for me not. I know its built in CSX Module. Maybe i'll take a look in it later. Maybe someone with more experience can do it for you. It's not just 2 lines of code xD.

atomen
04-30-2008, 14:09
Ok, thank you for your help.