SA-MP Forums Archive
format fail? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: format fail? (/showthread.php?tid=436013)



format fail? - Mellnik - 09.05.2013

I got a normal format here. Nothing special:
Код:
    
new query[150];
format(query, sizeof(query), "UPDATE `accounts` SET `Logged` = 1, `IP` = '%s' WHERE `Name` = '%s'", __GetIP(playerid), __GetName(playerid));
Getting players name and ip with these functions:

Код:
__GetName(playerid)
{
    new name[25];
    GetPlayerName(playerid, name, 25);
    return name;
}

__GetIP(playerid)
{
	new IP[16];
	GetPlayerIp(playerid, IP, 16);
	return IP;
}
It works well but sometimes either format or one of the function fails and that's whats going to print in the mysql log:
Quote:

UPDATE `accounts` SET `Logged` = 1, `IP` = '' WHERE `Name` = ''

So where is the problem? It only happens by certain querys.


Re: format fail? - DaRk_RaiN - 09.05.2013

The IP won't showup because you're using the wrong specifier, it's an integer so use %d or %i instead of %s.


AW: format fail? - Mellnik - 09.05.2013

No it is a string.


Re: format fail? - BlackBank - 09.05.2013

Your 'query' variable size is maybe to low.

Try new query[256]; and look if that solve your problem.


Also try to not use the __ before your function.


Re: format fail? - park4bmx - 09.05.2013

Quote:
Originally Posted by DaRk_RaiN
Посмотреть сообщение
The IP won't showup because you're using the wrong specifier, it's an integer so use %d or %i instead of %s.
No, its returning a string.

Try using a stock, also without the "_"
pawn Код:
stock GetName(playerid)
{
    new Pnamer[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof Pnamer);
    format(Pnamer,sizeof Pnamer,"%s",Pnamer);
    printf("name: %s",Pnamer);//debug
    return Pnamer;
}

stock GetIP(playerid)
{
    new IP[16];
    GetPlayerIp(playerid, IP, 16);
    format(IP,sizeof IP,"%s",IP);
    printf("IP: %s",IP);//debug
    return IP;
}



Re: format fail? - Vince - 09.05.2013

Is this in OnPlayerDisconnect? It is known for these function not to work properly in OnPlayerDisconnect.


Re: format fail? - Kwarde - 09.05.2013

According to Vince's message; This is why I use global variables that are loaded when the player gets connected. Here's a very small script as example/preview:
pawn Код:
#include <a_samp>

new PlayerName[MAX_PLAYERS][MAX_PLAYER_NAME];
new PlayerIP[MAX_PLAYERS][16];

//Main & OnGameModeInit not included; this script won't actually work because this is an example!

public OnPlayerConnect(playerid)
{
    GetPlayerName(playerid, PlayerName[playerid], MAX_PLAYER_NAME);
    GetPlayerIp(playerid, PlayerIP[playerid], 16);
    return 1;
}
So insead of the __GetName(playerid) and __GetIP() you must use PlayerName[playerid] and PlayerIP[playerid]
I'm not sure if this would solve your problem (because if you didn't use this in OnPlayerDisconnect, this probably wouldn't solve your problem), but more as a generally tip, and if it's used in OnPlayerDisconnect, it might be the fix
Please note that my way isn't the best thing for the server memory, but it always worked fine for me


AW: format fail? - Mellnik - 09.05.2013

Thank you for your answers.
These querys are not under OnPlayerDisconnect so Kwardes suggestion would help me probably.


Re: format fail? - Kwarde - 09.05.2013

Quote:

These querys are not under OnPlayerDisconnect so Kwardes suggestion would help me probably.

Actually I said that it could be a solution if it was under OnPlayerDisconnect. Though still it might help perhaps (SAMP can have strange bugs.. I once made script, it had strange bugs.. I re-created it on EXACT the same way and the bugs were gone -.-)


Re: format fail? - park4bmx - 09.05.2013

Quote:
Originally Posted by Kwarde
Посмотреть сообщение
SAMP can have strange bugs.. I once made script, it had strange bugs.. I re-created it on EXACT the same way and the bugs were gone -.-)
or you didn't see the problem in the first attempt, this is a script based, doing the same thing will give you the exact same result.