View previous topic :: View next topic |
Author |
Message |
cieciwa
Joined: 09 Aug 2005 Posts: 33 Location: Cracov, Poland
|
Posted: Thu Jun 08, 2006 9:38 Post subject: On_Client_leave - problem. |
|
|
Hi, I have script:
Code: |
#include "__default"
#include "aps_include"
void main()
{
object oPC = GetExitingObject();
string sPLogin=SQLEncodeSpecialChars(GetLocalString(oPC,"player"));
string sPName=SQLEncodeSpecialChars(GetName(oPC));
string sQuery;
//update HP
sQuery ="update `player_data` set `HP`="+ IntToString(GetCurrentHitPoints(oPC)) +" where `login`='" + sPLogin + "' and `character`= '" + sPName + "'";
SQLExecDirect(sQuery);
DEBUG("sQuery: " +sQuery);
if (SQLFetch() != SQL_SUCCESS) {
SendMessageToPC(oPC, "Not in database.");
DEBUG("[OnClientLeave] - not updated " +GetName(oPC));
}
// exit time
SQLExecDirect(" SELECT CURRENT_DATE()");
SQLFetch();
string sCurrDate = SQLGetData(1);
SQLExecDirect(" SELECT CURRENT_TIME()");
SQLFetch();
string sCurrTime = SQLGetData(1);
string sLastLogOut = sCurrDate + " " + sCurrTime;
sQuery ="update `player_data` set `last_log_out`='"+ sLastLogOut + "' where `login`='" + sPLogin + "' and `character`='" + sPName + "'";
SQLExecDirect(sQuery);
DEBUG("sQuery: " +sQuery);
// write to log
PrintString("[OnClientLeave] - Exiting player: " +sPLogin+ ", character: " +GetName(oPC));
}
|
but in log I have:
[DEBUG]sQuery: update `player_data` set `HP`=14 where `login`='' and `character`= 'Norgror Nibieski'
[DEBUG][OnClientLeave] - not updated Norgror Nibieski
[DEBUG]sQuery: update `player_data` set `last_log_out`='2006-06-07 23:47:45' where `login`='' and `character`='Norgror Nibieski'
[OnClientLeave] - Exiting player: , character: Norgror Nibieski
When I make mistake ? |
|
Back to top |
|
|
dumbo
Joined: 21 Aug 2005 Posts: 21
|
Posted: Thu Jun 08, 2006 11:20 Post subject: |
|
|
OnClientEnter:
Code: |
...
SetLocalString(oPC, "player", GetPCPlayerName(oPC));
...
|
lexicon: Quote: |
OnClientLeave, the PC object (GetExitingObject) is still valid, but the player object (i.e. the human being logged into the server) is not. This means that there are a few things you can't do OnClientLeave. Namely, the GetPCPlayerName, GetPCIPAddress, and GetPCPublicCDKey will not work, since the player is no longer around to get that information from. This can be worked around by storing them as local strings on the PC, for instance OnClientEnter. |
|
|
Back to top |
|
|
cieciwa
Joined: 09 Aug 2005 Posts: 33 Location: Cracov, Poland
|
Posted: Thu Jun 08, 2006 11:55 Post subject: |
|
|
I have SetLocalString.
Other starange is,that sometimes this works o, and sometimes not.
Don't know why. |
|
Back to top |
|
|
odenien
Joined: 26 Sep 2005 Posts: 37
|
Posted: Thu Jun 08, 2006 14:33 Post subject: |
|
|
That is what the Lexicon site says. You can not get the character name on client exit, due to the fact its unpredictable. This is sort of where the destructor of the object is being called and certain things can not be retrieved. I use an unique integer in my player table to access the records. I find it on_client_enter, add it to the player as a SetLocalInt, then I use it through on_client_exit. |
|
Back to top |
|
|
cieciwa
Joined: 09 Aug 2005 Posts: 33 Location: Cracov, Poland
|
Posted: Thu Jun 08, 2006 18:41 Post subject: |
|
|
BUT I use SetLocalString !! ...
And work/don't work .... |
|
Back to top |
|
|
odenien
Joined: 26 Sep 2005 Posts: 37
|
Posted: Fri Jun 09, 2006 12:45 Post subject: |
|
|
What is the PCPlayerName suppose to be? does it have any special characters in it? It looks like it is possibly being overwritten. |
|
Back to top |
|
|
FunkySwerve
Joined: 02 Jun 2005 Posts: 377
|
Posted: Fri Jun 09, 2006 16:25 Post subject: |
|
|
Why don't you show us the script where you SetLocalString the "player" variable? Mighth help eliminate that as the cause.
Funky |
|
Back to top |
|
|
cieciwa
Joined: 09 Aug 2005 Posts: 33 Location: Cracov, Poland
|
Posted: Fri Jun 09, 2006 19:15 Post subject: |
|
|
OK.
This is OnClientEnter:
Code: |
void main()
{
object oPC = GetEnteringObject();
string sLogin = SQLEncodeSpecialChars( GetPCPlayerName(oPC) );
string sCharacter = SQLEncodeSpecialChars( GetName(oPC) );
SetLocalString(oPC,"player", sLogin);
} |
|
|
Back to top |
|
|
FunkySwerve
Joined: 02 Jun 2005 Posts: 377
|
Posted: Sat Jun 10, 2006 6:39 Post subject: |
|
|
If that's the entire script, it won't compile correctly, because you are missing the #include "aps_include" line that refernces the file with the encode function. It you are using this exact script OCEnter, that's your problem - the "player" local would be returning blank. If not, I would still check the value of the local to make sure it's correct, but doing and IntToString on it and PrintStringing it to the logfil to check it.
Funky |
|
Back to top |
|
|
|