logo logo

 Back to main page

The NWNX Community Forum

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
On_Client_leave - problem.

 
Post new topic   Reply to topic    nwnx.org Forum Index -> Scripts and Modules
View previous topic :: View next topic  
Author Message
cieciwa



Joined: 09 Aug 2005
Posts: 33
Location: Cracov, Poland

PostPosted: Thu Jun 08, 2006 9:38    Post subject: On_Client_leave - problem. Reply with quote

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
View user's profile Send private message Send e-mail
dumbo



Joined: 21 Aug 2005
Posts: 21

PostPosted: Thu Jun 08, 2006 11:20    Post subject: Reply with quote

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
View user's profile Send private message
cieciwa



Joined: 09 Aug 2005
Posts: 33
Location: Cracov, Poland

PostPosted: Thu Jun 08, 2006 11:55    Post subject: Reply with quote

I have SetLocalString.
Other starange is,that sometimes this works o, and sometimes not.

Don't know why.
Back to top
View user's profile Send private message Send e-mail
odenien



Joined: 26 Sep 2005
Posts: 37

PostPosted: Thu Jun 08, 2006 14:33    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
cieciwa



Joined: 09 Aug 2005
Posts: 33
Location: Cracov, Poland

PostPosted: Thu Jun 08, 2006 18:41    Post subject: Reply with quote

BUT I use SetLocalString !! ...
And work/don't work ....
Back to top
View user's profile Send private message Send e-mail
odenien



Joined: 26 Sep 2005
Posts: 37

PostPosted: Fri Jun 09, 2006 12:45    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
FunkySwerve



Joined: 02 Jun 2005
Posts: 377

PostPosted: Fri Jun 09, 2006 16:25    Post subject: Reply with quote

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
View user's profile Send private message
cieciwa



Joined: 09 Aug 2005
Posts: 33
Location: Cracov, Poland

PostPosted: Fri Jun 09, 2006 19:15    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
FunkySwerve



Joined: 02 Jun 2005
Posts: 377

PostPosted: Sat Jun 10, 2006 6:39    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Scripts and Modules All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group