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 
 
help! setpersistent and getpersistent
Goto page 1, 2  Next
 
Post new topic   Reply to topic    nwnx.org Forum Index -> Scripts and Modules
View previous topic :: View next topic  
Author Message
b1o



Joined: 03 Apr 2007
Posts: 16

PostPosted: Tue Apr 03, 2007 16:04    Post subject: help! setpersistent and getpersistent Reply with quote

ok here is what i want to happen. when you die your status will be set to dead. and when you log on you wil be sendt to desired location(haven or hell or w/e) so i made this. but it seems that the get functuin doesn't work right.

OnDeath i added the line
Quote:

SetPersistentString(oPC, "STATUS", "DEAD");


on client enter i added
Quote:

string sStatus = GetPersistentString(oPC, "STATUS");
if (sStatus == DEAD)
{
SendMessageToPC(oPC, "hei du er død");
object oGoal = GetWaypointByTag("WP_FUGUE");
location lTarget = GetLocation(oGoal);
AssignCommand(oPC, ClearAllActions());
AssignCommand(oPC, ActionJumpToLocation(lTarget));
}
Back to top
View user's profile Send private message
TroveLord



Joined: 22 Nov 2006
Posts: 136
Location: Italy

PostPosted: Tue Apr 03, 2007 17:37    Post subject: Re: help! setpersistent and getpersistent Reply with quote

Quote:
if (sStatus == DEAD)

This is a string therefore use quotes:
Quote:
if (sStatus == "DEAD")

or turn it into a int (I'd recommend the second).
e.g.
Quote:
SetPersistentInt(oPC, "dead_status", TRUE);

nStatus = GetPersistentInt(oPC, "dead_status");
if(nStatus == TRUE)
and so on..


Also there's no need to use JumpAtLocation, JumpToObject will do just fine with a waypoint.

Lastly, when you're in doubt use some debug strings
e.g.
Code:
SendMessageToPC(GetFirstPC(), "sStatus: "+sStatus);

note that I used GetFirstPC() instead of oPC, so you will know if the problem is with the oPC variable.
Back to top
View user's profile Send private message
b1o



Joined: 03 Apr 2007
Posts: 16

PostPosted: Tue Apr 03, 2007 17:53    Post subject: okey Reply with quote

Ended up with 4 scripts
first a script with constants

Quote:

const int STATUS_DEAD = 0;
const int STATUS_ALIVE = 1;
const int STATUS_BLEEDING = 2;


then a script wich sets and gets the status

Quote:

#include "nwnx_sql"
#include "my_status"


void SetStatus(object oPC, int iStatus)
{
SetPersistentInt(oPC, "STATUS", iStatus);
}

int GetStatus(object oPC)
{
int nValue = GetPersistentInt(oPC, "STATUS");
return nValue;
}


then the death script which sets the status

Quote:

code
SetStatus(oPC, STATUS_DEAD);
more code


and then at last oncliententer script

Quote:

void main()
{
object oPC = GetEnteringObject();
int oHP = GetCurrentHitPoints(oPC);
ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectDamage(oHP -1, DAMAGE_TYPE_MAGICAL, DAMAGE_POWER_NORMAL, TRUE), oPC);
if (GetStatus(oPC) == STATUS_DEAD)
{
SendMessageToPC(oPC, "Hey u'r dead");
object oGoal = GetWaypointByTag("WP_FUGUE");
AssignCommand(oPC, ClearAllActions());
AssignCommand(oPC, ActionJumpToObject(oGoal));
}

}


and still doesn't work.
the problem is geting the data. i have checked the database and the correct data are there
Back to top
View user's profile Send private message
TroveLord



Joined: 22 Nov 2006
Posts: 136
Location: Italy

PostPosted: Tue Apr 03, 2007 18:15    Post subject: Re: okey Reply with quote

You can change this:
Code:
int GetStatus(object oPC)
{
     int nValue = GetPersistentInt(oPC, "STATUS");
     return nValue;
}

To:
Code:
int GetStatus(object oPC)
{
     return  GetPersistentInt(oPC, "STATUS");
}



Quote:

void main()
{
object oPC = GetEnteringObject();
int oHP = GetCurrentHitPoints(oPC);
ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectDamage(oHP -1, DAMAGE_TYPE_MAGICAL, DAMAGE_POWER_NORMAL, TRUE), oPC);
if (GetStatus(oPC) == STATUS_DEAD)
{
SendMessageToPC(oPC, "Hey u'r dead");
object oGoal = GetWaypointByTag("WP_FUGUE");
AssignCommand(oPC, ClearAllActions());
AssignCommand(oPC, ActionJumpToObject(oGoal));
}

}

Ok a few notes.
Characters entering the module always have full HP, so unless you're storing the HP on logout and reapplying the damage on re-enter, this:
Code:
object oPC = GetEnteringObject();
int oHP = GetCurrentHitPoints(oPC);
ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectDamage(oHP -1, DAMAGE_TYPE_MAGICAL, DAMAGE_POWER_NORMAL, TRUE), oPC);

is gonna do nothing, other than applying 1 point of damage; furthermore this code is actually not needed because you're sending the PC to a no-exit area, so doesn't matter how healthy he is.

All you need is this:
Code:

object oPC = GetEnteringObject();
if (GetStatus(oPC) == STATUS_DEAD)
{
      SendMessageToPC(oPC, "Hey u'r dead");
      AssignCommand(oPC, ClearAllActions(TRUE));
      AssignCommand(oPC, JumpToObject(GetWaypointByTag("WP_FUGUE")));
}

Make sure that WP_FUGUE is unique and that it is valid.
Also I used JumpToObject instead of ActionJumpToObject but shouldn't actually make any difference.
Lastly, if you're not sure wheter the variable is saved use a debug string.

At the top of the OnEnter script add this
Code:

SendMessageToPC(GetFirstPC(), "status of "+GetName(oPC)+": "+IntToString(GetStatus(oPC)));

And see what number it returns.

EDIT:I would recommend that you swap the values of STATUS_DEAD and STATUS_ALIVE, so, if the PC has no variable or it gets lost he will be considered alive (because it would return 0).
Back to top
View user's profile Send private message
b1o



Joined: 03 Apr 2007
Posts: 16

PostPosted: Tue Apr 03, 2007 18:36    Post subject: thanks Reply with quote

ill try it, but i know that the data is stored, i just cant get it out. btw it is nwnx4 for nwn2

the script that sets the hp to 1 is just to make me die faster Smile
Back to top
View user's profile Send private message
b1o



Joined: 03 Apr 2007
Posts: 16

PostPosted: Tue Apr 03, 2007 18:48    Post subject: Reply with quote

Neh still doesn't work. there is something wrong with
Code:

if (GetStatus(oPC) == STATUS_DEAD)
{
      SendMessageToPC(oPC, "Hey u'r dead");
      object oGoal = GetWaypointByTag("WP_FUGUE");
      AssignCommand(oPC, ClearAllActions());
      AssignCommand(oPC, ActionJumpToObject(oGoal));
}
Back to top
View user's profile Send private message
TroveLord



Joined: 22 Nov 2006
Posts: 136
Location: Italy

PostPosted: Tue Apr 03, 2007 18:55    Post subject: Reply with quote

Does the PC get the "Hey you're dead" message?
Back to top
View user's profile Send private message
b1o



Joined: 03 Apr 2007
Posts: 16

PostPosted: Tue Apr 03, 2007 19:06    Post subject: Reply with quote

no so it cant get the right data.

oh and i swaped from 0 to 1 as you said. quite smart, thanks
Back to top
View user's profile Send private message
TroveLord



Joined: 22 Nov 2006
Posts: 136
Location: Italy

PostPosted: Tue Apr 03, 2007 19:09    Post subject: Reply with quote

I never used Persistent Variables but I assume they use the database, do you get any notable info from the log?
Back to top
View user's profile Send private message
b1o



Joined: 03 Apr 2007
Posts: 16

PostPosted: Tue Apr 03, 2007 19:10    Post subject: Reply with quote

yes they use the database.
i can see that they are created in the db.

where can i find the log?
nwn2 doesn't store one i think
Quote:

NWNX MySQL Plugin V.0.0.7
(c) 2007 by Ingmar Stieger (Papillon)
visit us at http://www.nwnx.org
(built using mysql-5.0.27 source)

* Log level set to 2 (everything)
* Connecting to server localhost
* Plugin initialized.
* Registering under function class SQL
* Executing: CREATE TABLE IF NOT EXISTS pwdata (player varchar(64) NOT NULL default ' ',tag varchar(64) NOT NULL default ' ',name varchar(64) NOT NULL default ' ',val varchar(64),expire smallint(5) unsigned default NULL,last timestamp(14) NOT NULL,PRIMARY KEY (player,tag,name)) TYPE=MyISAM;
* Executing: SELECT val FROM pwdata WHERE player='b1o' AND tag='Vicho Borino' AND name='STATUS'
* Returning: 0 (column 0)
* Executing: SELECT player FROM pwdata WHERE player='b1o' AND tag='Vicho Borino' AND name='STATUS'
* Executing: UPDATE pwdata SET val='1',expire=0 WHERE player='b1o' AND tag='Vicho Borino' AND name='STATUS'
* Executing: SELECT val FROM pwdata WHERE player='b1o' AND tag='Vicho Borino' AND name='STATUS'
* Returning: 1 (column 0)
* Plugin unloaded.

xp_mysql.txt

Quote:

NWN Extender 4 V.0.0.7
(c) 2007 by Ingmar Stieger (Papillon)
visit us at http://www.nwnx.org

* Loading plugins...
* Loading plugin xp_mysql.dll: Successfully registered as class: SQL
* Loading plugin xp_time.dll: Successfully registered as class: TIME
* Disabling general protection fault error dialog.
* NWNX4 activated.
* NWNX4 shutting down...
* NWNX4 shutdown successfull.

nwnx.txt
Back to top
View user's profile Send private message
TroveLord



Joined: 22 Nov 2006
Posts: 136
Location: Italy

PostPosted: Tue Apr 03, 2007 19:31    Post subject: Reply with quote

Seems to work fine, although I find odd that name is the value and tag is the character name

Code:
SELECT val FROM pwdata WHERE player='b1o' AND tag='Vicho Borino' AND name='STATUS'
Back to top
View user's profile Send private message
b1o



Joined: 03 Apr 2007
Posts: 16

PostPosted: Tue Apr 03, 2007 19:33    Post subject: Reply with quote

yeah. still nothing happens Sad.
I'm allmost getting suicidal here
Back to top
View user's profile Send private message
TroveLord



Joined: 22 Nov 2006
Posts: 136
Location: Italy

PostPosted: Tue Apr 03, 2007 19:42    Post subject: Reply with quote

Let's wait for some other scripter, I can't really figure what's the problem.
Back to top
View user's profile Send private message
b1o



Joined: 03 Apr 2007
Posts: 16

PostPosted: Tue Apr 03, 2007 19:43    Post subject: Reply with quote

sounds fair ^^
Back to top
View user's profile Send private message
ShaDoOoW



Joined: 20 Aug 2005
Posts: 584

PostPosted: Tue Apr 03, 2007 22:07    Post subject: Reply with quote

Well, i don't see any error in script either in setup database. It don't seems, that you forgot use SQLInit(); in onmoduleload as me.

But i can recommend something.

Use debugs: let server writetimestampedlofentry of any value you get in script and then try this values input to script and watch the result. This is way to solve any problem Smile . Debugs are very powerful tool.
_________________
Community Patch / NWNX Patch / NWNX Files / NWNX Connect
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
Goto page 1, 2  Next
Page 1 of 2

 
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