View previous topic :: View next topic |
Author |
Message |
celtic3
Joined: 16 Jul 2005 Posts: 19
|
Posted: Fri Feb 17, 2006 23:14 Post subject: Help GetPersistentObject |
|
|
I have the following scripts for OnClientEnter & OnClientLeave.
OnClientLeave works and the Table is created with the objects in it, but when I come back in with the character OnClientEnter dosent put the objects back on him. This should work but the problem seems to be associated with it running from OnClientEnter. It works fine from a placeable. Maybe a timing issue related to OnClientEnter. Please Help?
[ONCLIENTLEAVE]
Code: |
#include "aps_include"
void main()
{
//Write PC info to SQL Database [pcdata]
object oPC = GetExitingObject();
int iItem;
string sTable;
string pcname = GetName(oPC);
//Create PC Characters Inventory Table
string sChar;
int iCnt = 0;
int iLen = GetStringLength(pcname);
for(iLen; iLen > 0; iLen--)//Get rid of any spaces
{
sChar = GetSubString(pcname, iCnt, 1);//Get next character
if(sChar == " ")
{
//Skip Space
}
else
{
sTable = sTable + sChar;
}
iCnt++;
}
SQLExecDirect("DROP TABLE " + sTable);
SQLExecDirect("CREATE TABLE " + sTable + " (" +
"player varchar(64) NOT NULL default '~'," +
"tag varchar(64) NOT NULL default '~'," +
"name varchar(64) NOT NULL default '~'," +
"val blob," +
"expire int(11) default NULL," +
"last timestamp NOT NULL default CURRENT_TIMESTAMP," +
"PRIMARY KEY (player,tag,name)" +
") ENGINE=MyISAM DEFAULT CHARSET=latin1;");
//Save PC CHaracter's Inventory to Their Table
object oItem = GetFirstItemInInventory(oPC);
while (GetIsObjectValid(oItem))
{
SetPersistentObject(GetModule(), "Item_" + IntToString(iItem), oItem, 0, sTable);
oItem = GetNextItemInInventory(oPC);
iItem++;
}
}
|
[ONCLIENTENTER]
Code: |
#include "aps_include"
void main()
{
object oPC = GetEnteringObject();
object oChest1 = GetModule();
string sTable;
//Write PC info to SQL Database [pcdata]
int iItem;
string pubcdkey = GetPCPublicCDKey(oPC);
string playername = GetPCPlayerName(oPC);
string pcname = GetName(oPC);
string sChar;
int iCnt = 0;
int iLen = GetStringLength(pcname);
//Make table name from PC's name
for(iLen; iLen > 0; iLen--)
{
sChar = GetSubString(pcname, iCnt, 1);//Get next character
if(sChar == " ")
{
//Skip Spaces
}
else
{
sTable = sTable + sChar;
}
iCnt++;
}
SQLExecDirect("SELECT playername FROM pcdata WHERE pubcdkey='" + pubcdkey +
"' AND pcname='" + pcname + "';");
WriteTimestampedLogEntry("Looking for PC: " + pcname);
if (SQLFetch() == SQL_ERROR)
{
// Not found, so create a new character entry into pcdata
WriteTimestampedLogEntry("Creating new PC: " + pcname);
SQLExecDirect("INSERT INTO pcdata (pubcdkey, playername, pcname, nvisits, lastlogin) VALUES('" +
pubcdkey + "', '" + playername + "', '" + pcname + "', '1', CURRENT_TIMESTAMP)");
// Retrieve the pubcdkey again
SQLExecDirect("SELECT pubcdkey FROM pcdata WHERE pubcdkey='" + pubcdkey +
"' AND pcname='" + pcname + "';");
SQLFetch();
//Create PC Characters Inventory Table
SQLExecDirect("CREATE TABLE " + sTable + " (" +
"player varchar(64) NOT NULL default '~'," +
"tag varchar(64) NOT NULL default '~'," +
"name varchar(64) NOT NULL default '~'," +
"val blob," +
"expire int(11) default NULL," +
"last timestamp NOT NULL default CURRENT_TIMESTAMP," +
"PRIMARY KEY (player,tag,name)" +
") ENGINE=MyISAM DEFAULT CHARSET=latin1;");
WriteTimestampedLogEntry("Created");
}
else
{
// Character was found
WriteTimestampedLogEntry("Found PC: " + pcname);
SQLExecDirect("UPDATE pcdata SET nvisits = nvisits + 1, lastlogin = CURRENT_TIMESTAMP WHERE pubcdkey='" + pubcdkey + "';");
WriteTimestampedLogEntry("PUBCDCKEY=" + pubcdkey);
//Get PC Character's Inventory To Their Table
int bContinue = TRUE;
object oCreated;
while (bContinue)
{
oCreated = GetPersistentObject(oChest1, "Item_" + IntToString(iItem), oPC, sTable);
if (!GetIsObjectValid(oCreated))
bContinue = FALSE;
else
iItem++;
}
}
WriteTimestampedLogEntry("Returning PUBCDKEY " + pubcdkey);
}
|
|
|
Back to top |
|
|
Papillon x-man
Joined: 28 Dec 2004 Posts: 1060 Location: Germany
|
Posted: Mon Feb 20, 2006 23:51 Post subject: |
|
|
You are writing to the DB with
Quote: | SetPersistentObject(GetModule(), "Item_" + IntToString(iItem), oItem, 0, sTable); |
and read with
Quote: | Created = GetPersistentObject(oChest1, "Item_" + IntToString(iItem), oPC, sTable); |
The first parameter is probably your problem. When you look at the functions in aps_include, you'll see that it stores effectively under GetTag(oModule) while it tries to retrieve the items by GetTag(oChest) - which won't work because of differing strings/tags.
You can also check out the odbc log file to see what is going wrong. _________________ Papillon |
|
Back to top |
|
|
celtic3
Joined: 16 Jul 2005 Posts: 19
|
Posted: Tue Feb 21, 2006 1:03 Post subject: reply |
|
|
They are not different tags since oChest1 = GetModule. Also It works on a placeable's hook as is but not on the modules hook as I said. |
|
Back to top |
|
|
celtic3
Joined: 16 Jul 2005 Posts: 19
|
Posted: Tue Feb 21, 2006 1:54 Post subject: Resolved |
|
|
I figured it out, and I apreciate you trying to help. It seems a timing issue is involved with the OnClientEnter hook. Using ExecuteScript("script", GetEnteringObject()); I called the above script from the OnClientEnter. I changed oPC = GetEnteringObject(); in the script to oPC = OBJECT_SELF;.
Nothing happens still.
Put a DelayCommand(6.0, ExecuteScript("script", GetEnteringObject())); and it works like a champ.
Anyone know what the timing issue is? |
|
Back to top |
|
|
Rami_Ahmed
Joined: 07 Dec 2005 Posts: 37 Location: Denmark
|
Posted: Mon Jun 05, 2006 20:03 Post subject: Re: Resolved |
|
|
celtic3 wrote: | Anyone know what the timing issue is? |
Probably because the players inventory is not fully loaded when the player enters the module, so delaying it a bit, the players inventory will be loaded. I guess it's a lag issue actually. |
|
Back to top |
|
|
Acrodania
Joined: 02 Jan 2005 Posts: 208
|
Posted: Mon Jun 05, 2006 20:52 Post subject: Re: Resolved |
|
|
Rami_Ahmed wrote: | celtic3 wrote: | Anyone know what the timing issue is? |
Probably because the players inventory is not fully loaded when the player enters the module, so delaying it a bit, the players inventory will be loaded. I guess it's a lag issue actually. |
Yep, the module's OnEnter scripts fire before the PC is completely in the module. You almost always have to add a short delay to accomodate it. Same thing happens when you try to jump a PC OnEnter....
The delay for the PC to fully get into the module and see a area can be as long as 15 seconds with a slow client computer and poor connections. |
|
Back to top |
|
|
|
|
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
|