AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   client_print problem (https://forums.alliedmods.net/showthread.php?t=172536)

da_ciouzan_oan 11-22-2011 06:18

client_print problem
 
Hello,
I have some problems with client_print

This is how I declared my vars
Code:
#define _ACHIEVEMENT_Max 128 enum ACHIEVEMENT_Info {     ACHIEVEMENT_Name[ 32 ],     ACHIEVEMENT_Message[ 192 ] } new _ACHIEVEMENT_GlobalInfo[ _ACHIEVEMENT_Max ][ ACHIEVEMENT_Info ]

I read the achievement data from a file, but the weird thing is.. that when I try to print the stored string into chat, it shows me '[AC] Ai primit medalia xph`XPH@80('
Code:
client_print(id, print_chat, "[AC] Ai primit medalia %s, ^"%s^"", _ACHIEVEMENT_GlobalInfo[ id_medalie ][ ACHIEVEMENT_Name ], _ACHIEVEMENT_GlobalInfo[ id_medalie ][ ACHIEVEMENT_Message ])

BUT when I use the same variables to print the stored string into server console, it's nothing wrong..
Code:
log_amx("[status] ID %d, nume: %s, mesaj: %s", id_medalie, _ACHIEVEMENT_GlobalInfo[ id_medalie ][ ACHIEVEMENT_Name ], _ACHIEVEMENT_GlobalInfo[ id_medalie ][ ACHIEVEMENT_Message ])
Showing: 'L 11/22/2011 - 13:00:21: [achievements.amxx] [status] ID 3, nume: Life Hater, mesaj: Sinucide-te o data'

id_medalie is 3 in both cases.

Thanks in advance ^^.

LE: BTW, is there any posibility to change the volume of a sound using emit_sound so I can hear it louder?

LE2: Great, now crashes the server..
Code:
register_event("DeathMsg", "onPlayerKill", "a")
Code:
public onPlayerKill(killer, victim, headshot, wpnname[]) {     killer = read_data(1)     victim = read_data(2)     headshot = read_data(3)     read_data(4, wpnname, 31)         if(killer == 0 || killer == victim)         ACHIEVEMENT_Earn(victim, 3) }
Code:
ACHIEVEMENT_Earn(id, id_medalie) {     new nume_player[ 32 ], players[ 32 ], num     get_players(players, num)     get_user_name(id, nume_player, charsmax(nume_player))     for(new i; i < num; i++)     {         if(is_user_connected(players[ i ]))         {             if(players[ i ] == id)             {                 client_print(id, print_chat, "[AC] Ai primit medalia %s, ^"%s^"", _ACHIEVEMENT_GlobalInfo[ id_medalie ][ ACHIEVEMENT_Name ], _ACHIEVEMENT_GlobalInfo[ id_medalie ][ ACHIEVEMENT_Message ]))                 continue;             }             client_print(players[ i ], print_chat, "[AC] %s a primit medalia %s !", nume_player, _ACHIEVEMENT_GlobalInfo[ id_medalie ][ ACHIEVEMENT_Name ])         }     }     log_amx("[status] %s a primit medalia %s, ^"%s^"", nume_player, _ACHIEVEMENT_GlobalInfo[ id_medalie ][ ACHIEVEMENT_Name ], _ACHIEVEMENT_GlobalInfo[ id_medalie ][ ACHIEVEMENT_Message ])     _ACHIEVEMENT_PlayerInfo[ id ][ id_medalie ] = 1 }

Xellath 11-22-2011 07:59

Re: client_print problem
 
Might be due to the fact that 190 is maximum size of the TextMsg event, which is used in the client_print function to actually send the message (see UTIL_ClientPrint below). Not entirely sure however. As it seems to be working correctly with log_amx I would assume so.

Source code from client_print:
Code:
static cell AMX_NATIVE_CALL client_print(AMX *amx, cell *params) /* 3 param */ {     int len = 0;     char *msg;         if (params[1] == 0)     {         for (int i = 1; i <= gpGlobals->maxClients; ++i)         {             CPlayer *pPlayer = GET_PLAYER_POINTER_I(i);                         if (pPlayer->ingame)             {                 g_langMngr.SetDefLang(i);                 msg = format_amxstring(amx, params, 3, len);                 msg[len++] = '\n';                 msg[len] = 0;                 UTIL_ClientPrint(pPlayer->pEdict, params[2], msg);             }         }     } else {         int index = params[1];                 if (index < 1 || index > gpGlobals->maxClients)         {             LogError(amx, AMX_ERR_NATIVE, "Invalid player id %d", index);             return 0;         }                 CPlayer* pPlayer = GET_PLAYER_POINTER_I(index);         g_langMngr.SetDefLang(index);                 msg = format_amxstring(amx, params, 3, len);         msg[len++] = '\n';         msg[len] = 0;                 if (pPlayer->ingame)             UTIL_ClientPrint(pPlayer->pEdict, params[2], msg);      //format_amxstring(amx, params, 3, len));     }         return len; } void UTIL_ClientPrint(edict_t *pEntity, int msg_dest, char *msg) {     if (!gmsgTextMsg)         return; // :TODO: Maybe output a warning log?         char c = msg[190];     msg[190] = 0; // truncate without checking with strlen()     if (pEntity)         MESSAGE_BEGIN(MSG_ONE, gmsgTextMsg, NULL, pEntity);     else         MESSAGE_BEGIN(MSG_BROADCAST, gmsgTextMsg);     WRITE_BYTE(msg_dest);     WRITE_STRING(msg);     MESSAGE_END();     msg[190] = c; }

About emit_sound() - parameter 4 (vol) decides the volume of the current sound.

Also, there is no need to iterate through all players to send a message, simply do the following to send it to all players:
Code:
client_print( 0, print_chat, "message" );

da_ciouzan_oan 11-22-2011 08:29

Re: client_print problem
 
1. I made some changes and now it doesn't crash the server anymore.. but still prints like !@#%:
I wanted to check if in console prints ok but.. it doesn't. Only when it loads from file it prints how it should..

This message is printed when the file is readed and stored into vars:
Code:
log_amx("[status] ID %d, nume: %s, mesaj: %s", id_medalie, _ACHIEVEMENT_GlobalInfo[ id_medalie ][ ACHIEVEMENT_Name ], _ACHIEVEMENT_GlobalInfo[ id_medalie ][ ACHIEVEMENT_Message ])
'L 11/22/2011 - 15:22:29: [achievements.amxx] [status] ID 3, nume: Life Hater, mesaj: Sinucide-te o data'

This message is printed when I get the achievement:
Code:
log_amx("[status] %s a primit medalia %s, ^"%s^"", nume_player, _ACHIEVEMENT_GlobalInfo[ id_medalie ][ ACHIEVEMENT_Name ], _ACHIEVEMENT_GlobalInfo[ id_medalie ][ ACHIEVEMENT_Message ])
'L 11/22/2011 - 15:24:19: [achievements.amxx] [status] ThE_ChOSeN_OnE a primit medalia |xtplhd`\XTPLHD@<840,($'
Also, the same message is printed in chat.
'[AC] Ai primit medalia |xtplhd`\XTPLHD@<840,($'

2. I already tried to change the param volume and if I raise it, the server crashes. Thats why I asked here :-? maybe it's something else, another way maybe.

3. I Iterate through all players cause I send a message to the player who's receiving the Achievement and a different message to all other players.

Xellath 11-22-2011 08:35

Re: client_print problem
 
Can I see the function where you load the achievements?

da_ciouzan_oan 11-22-2011 08:38

Re: client_print problem
 
Quote:

Originally Posted by Xellath (Post 1600708)
Can I see the function where you load the achievements?

The file with achiv's look like this:
Code:

0 "Ace Shot" "Omoara 2 playeri cu un glont"
1 "First Blood" "Fa primul frag din runda"
2 "Humiliation" "Omoara 1 player cu cutitul"
3 "Life Hater" "Sinucide-te o data"

Yep, here it is.
Code:
public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)     register_event("DeathMsg", "onPlayerKill", "a")     ACHIEVEMENT_Global() }

Code:
ACHIEVEMENT_Global() {     new nume_fisier[ 128 ], fisier, count     format(nume_fisier, charsmax(nume_fisier), "addons/amxmodx/data/achievements/achievements.SET")         if(!dir_exists("addons/amxmodx/data/achievements"))         mkdir("addons/amxmodx/data/achievements")             if(!file_exists(nume_fisier))     {         log_amx("[eroare] Pentru a rula acest plugin este necesar fisierul 'achievements.SET'!")         server_cmd("amx_pausecfg stop achievements.amxx")         server_exec()     }     else     {         fisier = fopen(nume_fisier, "r")         if(fisier)         {             while(!feof(fisier))             {                 new date[ 256 ], id_medalie_str[ 6 ], id_medalie, nume_medalie[ 32 ], mesaj_medalie[ 192 ], temp[ ACHIEVEMENT_Info ]                 fgets(fisier, date, charsmax(date))                 trim(date)                                 if (date[0] == '0' || date[0] == '1' || date[0] == '2' || date[0] == '3' || date[0] == '4' || date[0] == '5' || date[0] == '6' || date[0] == '7' || date[0] == '8' || date[0] == '9')                 {                     parse(date, id_medalie_str, charsmax(id_medalie_str), nume_medalie, charsmax(nume_medalie), mesaj_medalie, charsmax(mesaj_medalie))                     id_medalie = str_to_num(id_medalie_str)                     if(id_medalie > _ACHIEVEMENT_Max || id_medalie < 0)                     {                         log_amx("[eroare] Medalia cu ID %d depaseste limita maxima de medalii, recompilati pluginul cu noul numar maxim de medalii !")                         continue;                     }                     copy(_ACHIEVEMENT_GlobalInfo[ id_medalie ][ ACHIEVEMENT_Name ], charsmax(temp[ ACHIEVEMENT_Name ]), nume_medalie)                     copy(_ACHIEVEMENT_GlobalInfo[ id_medalie ][ ACHIEVEMENT_Message ], charsmax(temp[ ACHIEVEMENT_Message ]), mesaj_medalie)                     temp[ ACHIEVEMENT_Name ] = 0 // To get rid of warning message                                         count++                     log_amx("[status] ID %d, nume: %s, mesaj: %s", id_medalie, _ACHIEVEMENT_GlobalInfo[ id_medalie ][ ACHIEVEMENT_Name ], _ACHIEVEMENT_GlobalInfo[ id_medalie ][ ACHIEVEMENT_Message ])                 }             }             fclose(fisier);         }         server_print("[status] S-au citit %d medalii.", count)     } }

Xellath 11-22-2011 09:06

Re: client_print problem
 
Cannot see anything wrong with that code, except for the unnecessary temp variable. Just use charsmax(_ACHIEVEMENT_GlobalInfo[ ][ ACHIEVEMENT_* ]).

Try to format the string then print it using client_print and see what results you have.

da_ciouzan_oan 11-22-2011 10:05

Re: client_print problem
 
Code:
ACHIEVEMENT_Earn(id, id_medalie) {     new nume_player[ 32 ], players[ 32 ], num, nume_medalie[ 32 ], mesaj_medalie[ 96 ]     get_players(players, num)     get_user_name(id, nume_player, charsmax(nume_player))         copy(nume_medalie, charsmax(nume_medalie), ACHIEVEMENT_GlobalInfo[ id_medalie ][ ACHIEVEMENT_Name ])     copy(mesaj_medalie, charsmax(mesaj_medalie), ACHIEVEMENT_GlobalInfo[ id_medalie ][ ACHIEVEMENT_Message ])         for(new i; i < num; i++)     {         if(is_user_connected(players[ i ]))         {             if(players[ i ] == id)             {                 color_chat(id, "!y[AC] You've earned the !g%s!y achievement for !g^"%s^"", nume_medalie, mesaj_medalie)                 continue;             }             color_chat(players[ i ], "!y[AC] !g%s has earned the !g%s!y achievement !", nume_player, nume_medalie)         }     }     log_amx("[AC] %s has earned the ^"%s^" achievement !", nume_player, nume_medalie)     //emit_sound(id, CHAN_STATIC, "achievements/achievement_earned.wav", 1.5, ATTN_NORM, 0, PITCH_NORM)     ACHIEVEMENT_PlayerInfo[ id ][ id_medalie ] = 1 }

This is printed into chat, I changed the language.. also switched to color_chat cause client_print was crashing the server.
[AC] You've earned the |xtplhd`\XTPLHD@<840,($  achievement for "
This is printed into console:
L 11/22/2011 - 17:03:50: [achievements.amxx] [AC] ThE_ChOSeN_OnE has earned the "|xtplhd`\XTPLHD@<840,($ " achievement !

Xellath 11-22-2011 11:00

Re: client_print problem
 
I did a quick test, and it works correctly for me.

Tested code:
Code:
#include <amxmodx> #define _ACHIEVEMENT_Max 128 enum ACHIEVEMENT_Info {     ACHIEVEMENT_Name[ 32 ],     ACHIEVEMENT_Message[ 192 ] } new _ACHIEVEMENT_GlobalInfo[ _ACHIEVEMENT_Max ][ ACHIEVEMENT_Info ] public plugin_init() {     ACHIEVEMENT_Global() } public client_connect( id ) {     set_task( 10.0, "task", id ); } public task( id ) {     for( new i; i < 4; i++ )     {         server_print( "%s: %s", _ACHIEVEMENT_GlobalInfo[ i ][ ACHIEVEMENT_Name ], _ACHIEVEMENT_GlobalInfo[ i ][ ACHIEVEMENT_Message ] );                 client_print( id, print_chat, "%s: %s", _ACHIEVEMENT_GlobalInfo[ i ][ ACHIEVEMENT_Name ], _ACHIEVEMENT_GlobalInfo[ i ][ ACHIEVEMENT_Message ] );     } } ACHIEVEMENT_Global() {     new nume_fisier[ 128 ], fisier, count     format(nume_fisier, charsmax(nume_fisier), "addons/amxmodx/data/achievements/achievements.SET")         if(!dir_exists("addons/amxmodx/data/achievements"))         mkdir("addons/amxmodx/data/achievements")             if(!file_exists(nume_fisier))     {         log_amx("[eroare] Pentru a rula acest plugin este necesar fisierul 'achievements.SET'!")         server_cmd("amx_pausecfg stop achievements.amxx")         server_exec()     }     else     {         fisier = fopen(nume_fisier, "r")         if(fisier)         {             while(!feof(fisier))             {                 new date[ 256 ], id_medalie_str[ 6 ], id_medalie, nume_medalie[ 32 ], mesaj_medalie[ 192 ]                 fgets(fisier, date, charsmax(date))                 trim(date)                                 if (date[0] == '0' || date[0] == '1' || date[0] == '2' || date[0] == '3' || date[0] == '4' || date[0] == '5' || date[0] == '6' || date[0] == '7' || date[0] == '8' || date[0] == '9')                 {                     parse(date, id_medalie_str, charsmax(id_medalie_str), nume_medalie, charsmax(nume_medalie), mesaj_medalie, charsmax(mesaj_medalie))                     id_medalie = str_to_num(id_medalie_str)                     if(id_medalie > _ACHIEVEMENT_Max || id_medalie < 0)                     {                         log_amx("[eroare] Medalia cu ID %d depaseste limita maxima de medalii, recompilati pluginul cu noul numar maxim de medalii !")                         continue;                     }                     copy(_ACHIEVEMENT_GlobalInfo[ id_medalie ][ ACHIEVEMENT_Name ], charsmax(_ACHIEVEMENT_GlobalInfo[ ][ ACHIEVEMENT_Name ]), nume_medalie)                     copy(_ACHIEVEMENT_GlobalInfo[ id_medalie ][ ACHIEVEMENT_Message ], charsmax(_ACHIEVEMENT_GlobalInfo[ ][ ACHIEVEMENT_Message ]), mesaj_medalie)                                         count++                     log_amx("[status] ID %d, nume: %s, mesaj: %s", id_medalie, _ACHIEVEMENT_GlobalInfo[ id_medalie ][ ACHIEVEMENT_Name ], _ACHIEVEMENT_GlobalInfo[ id_medalie ][ ACHIEVEMENT_Message ])                 }             }             fclose(fisier);         }         server_print("[status] S-au citit %d medalii.", count)     } }

da_ciouzan_oan 11-22-2011 11:36

Re: client_print problem
 
This code is working ..
Code:
public task() {     server_print("%s: %s", ACHIEVEMENT_GlobalInfo[ 3 ][ ACHIEVEMENT_Name ], ACHIEVEMENT_GlobalInfo[ 3 ][ ACHIEVEMENT_Message ])     client_print(0, print_chat, "%s: %s", ACHIEVEMENT_GlobalInfo[ 3 ][ ACHIEVEMENT_Name ], ACHIEVEMENT_GlobalInfo[ 3 ][ ACHIEVEMENT_Message ]) }
I changed the function.. I put the code from the task inside my function and it's not working, is the same !@*$&^ code and it's not working. Wtf is going on here?! so annoying ...
Code:
public ACHIEVEMENT_Earn(id, id_medalie) {     /*new nume_player[ 32 ], players[ 32 ], num, nume_medalie[32], mesaj_medalie[96]     get_players(players, num)     get_user_name(id, nume_player, charsmax(nume_player))         copy(nume_medalie, charsmax(nume_medalie), ACHIEVEMENT_GlobalInfo[ 3 ][ ACHIEVEMENT_Name ])     copy(mesaj_medalie, charsmax(mesaj_medalie), ACHIEVEMENT_GlobalInfo[ 3 ][ ACHIEVEMENT_Message ])         for(new i; i < num; i++)     {         if(is_user_connected(players[ i ]))         {             if(players[ i ] == id)             {                 color_chat(id, "!y[AC] You earned the !g%s!y achievement for !g^"%s^"", nume_medalie, mesaj_medalie)                 continue;             }             color_chat(players[ i ], "!y[AC] !g%s has earned the !g%s!y achievement !", nume_player, nume_medalie)         }     }     log_amx("[AC] %s has earned the ^"%s^" achievement !", nume_player, nume_medalie)     //emit_sound(id, CHAN_STATIC, "achievements/achievement_earned.wav", 1.5, ATTN_NORM, 0, PITCH_NORM)     ACHIEVEMENT_PlayerInfo[ id ][ id_medalie ] = 1*/     server_print("%s: %s", ACHIEVEMENT_GlobalInfo[ 3 ][ ACHIEVEMENT_Name ], ACHIEVEMENT_GlobalInfo[ 3 ][ ACHIEVEMENT_Message ])     client_print(0, print_chat, "%s: %s", ACHIEVEMENT_GlobalInfo[ 3 ][ ACHIEVEMENT_Name ], ACHIEVEMENT_GlobalInfo[ 3 ][ ACHIEVEMENT_Message ]) }

This is printed into chat from the task:
Code:

Life Hater: Sinucide-te o data
This is printed into chat from my function:
Code:

|xtplhd`\XTPLHD@<840,($ 

Xellath 11-22-2011 11:50

Re: client_print problem
 
Code:
ACHIEVEMENT_Earn(id, id_medalie) {     new nume_player[ 32 ], players[ 32 ], num, player     get_players(players, num)     get_user_name(id, nume_player, charsmax(nume_player))         for(new i; i < num; i++)     {         player = players[ i ]                 if(is_user_connected(player))         {             if(player == id)             {                 client_print(id, print_chat, "[AC] You've earned the %s achievement for ^"%s^"", _ACHIEVEMENT_GlobalInfo[ id_medalie ][ ACHIEVEMENT_Name ], _ACHIEVEMENT_GlobalInfo[ id_medalie ][ ACHIEVEMENT_Name ])             }             else             {                 client_print(id, print_chat, "[AC] %s has earned the %s achievement!", _ACHIEVEMENT_GlobalInfo[ id_medalie ][ ACHIEVEMENT_Name ], _ACHIEVEMENT_GlobalInfo[ id_medalie ][ ACHIEVEMENT_Name ])             }         }     }     //log_amx("[AC] %s has earned the ^"%s^" achievement !", nume_player, nume_medalie)     //emit_sound(id, CHAN_STATIC, "achievements/achievement_earned.wav", 1.5, ATTN_NORM, 0, PITCH_NORM)     //ACHIEVEMENT_PlayerInfo[ id ][ id_medalie ] = 1 }


All times are GMT -4. The time now is 08:30.

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