format fail?
#1

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.
Reply
#2

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

No it is a string.
Reply
#4

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.
Reply
#5

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;
}
Reply
#6

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

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
Reply
#8

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

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 -.-)
Reply
#10

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)