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 
 
persistant death monitoring

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



Joined: 27 Jan 2005
Posts: 18

PostPosted: Wed Feb 09, 2005 21:41    Post subject: persistant death monitoring Reply with quote

I am working on an easy anti-plugger death system, and didn;t want to use a death token system.

this is what i have already, but not seeming to work, if anyone can please look it over and tell me what i have done wrong, it would be appreciated


OnCLientLeave:

Code:
#include "dar_func"
#include "aps_include"

void main() {
    object oPC = GetExitingObject();
    if(GetIsDead(oPC)) {
        SetPersistentInt(oPC,"dead",1);
        }

    OnSubraceLeave(oPC);
}





OnClientEnter:


Code:
#include "dar_func"
#include "aps_include"

void main() {
    object oPC;

    if(GetIsPC(oPC = GetEnteringObject())) {
        OnSubraceEnter(oPC);
    }
        if(OBJECT_INVALID == GetItemPossessedBy(oPC,"locationsaver")){
        CreateItemOnObject("locationsaver",oPC);
    }
    int Plug = GetPersistentInt(oPC, "dead");
        if(Plug==1) {
        effect eDamage = EffectDamage(10000,DAMAGE_TYPE_MAGICAL);
        ApplyEffectToObject(DURATION_TYPE_INSTANT,eDamage,oPC);
        SetPersistentInt(oPC,"dead",0);

    }
}
Back to top
View user's profile Send private message
Dazzle



Joined: 29 Dec 2004
Posts: 19

PostPosted: Wed Feb 09, 2005 22:58    Post subject: Reply with quote

NWN can't get any of the GetPCPlayerName/GetName at ClientLeave from a leaving player, SetPersistentInt uses these variables to store the integer. Your script uses these two variables, but since you try to get them at OnClientLeave, the script fails. There's a workaround for it, but it requires some editing.

First, OnClientEnter you store the two earlier mentioned variables locally on the player.

Like this:
Code:
SetLocalString(oPC, "PlayerCharacterName", GetName(oPC);
SetLocalString(oPC, "PlayerPlayerLoginName", GetPCPlayerName(oPC);


After that, you open the aps_include script and change the SetPersistentString() function into this one:
Code:
void SetPersistentString(object oObject, string sVarName, string sValue, int iExpiration =
                         0, string sTable = "pwdata")
{
    string sPlayer;
    string sTag;

    if (GetIsPC(oObject))
    {
        sPlayer = SQLEncodeSpecialChars(GetLocalString(oObject, "PlayerPlayerLoginName"));
        sTag = SQLEncodeSpecialChars(GetLocalString(oObject, "PlayerCharacterName"));
    }
    else
    {
        sPlayer = "~";
        sTag = GetTag(oObject);
    }

    sVarName = SQLEncodeSpecialChars(sVarName);
    sValue = SQLEncodeSpecialChars(sValue);

    string sSQL = "SELECT player FROM " + sTable + " WHERE player='" + sPlayer +
        "' AND tag='" + sTag + "' AND name='" + sVarName + "'";
    SQLExecDirect(sSQL);

    if (SQLFetch() == SQL_SUCCESS)
    {
        // row exists
        sSQL = "UPDATE " + sTable + " SET val='" + sValue +
            "',expire=" + IntToString(iExpiration) + " WHERE player='" + sPlayer +
            "' AND tag='" + sTag + "' AND name='" + sVarName + "'";
        SQLExecDirect(sSQL);
    }
    else
    {
        // row doesn't exist
        sSQL = "INSERT INTO " + sTable + " (player,tag,name,val,expire) VALUES" +
            "('" + sPlayer + "','" + sTag + "','" + sVarName + "','" +
            sValue + "'," + IntToString(iExpiration) + ")";
        SQLExecDirect(sSQL);
    }
}



Below is your OnClientEnter script, I added the two SetLocalString functions and cleaned it up a bit.

Code:
#include "dar_func"
#include "aps_include"
void main()
{
    object oPC = GetEnteringObject();

    SetLocalString(oPC, "PlayerCharacterName", GetName(oPC));
    SetLocalString(oPC, "PlayerPlayerLoginName", GetPCPlayerName(oPC));

    if( GetIsPC(oPC) )
    {
        OnSubraceEnter(oPC);
    }

    if( GetItemPossessedBy(oPC,"locationsaver") == OBJECT_INVALID )
    {
        CreateItemOnObject("locationsaver", oPC);
    }

    int Plug = GetPersistentInt(oPC, "dead");
    if( Plug == 1 )
    {
        effect eDamage = EffectDamage(10000, DAMAGE_TYPE_MAGICAL);
        ApplyEffectToObject(DURATION_TYPE_INSTANT, eDamage, oPC);
        SetPersistentInt(oPC,"dead", 0);
    }
}


This'll most likely work, if not, just ask again.
Back to top
View user's profile Send private message
Tuebits



Joined: 27 Jan 2005
Posts: 18

PostPosted: Wed Feb 09, 2005 23:07    Post subject: Reply with quote

your first code is for OnCLientLeave i beleive, being that your last code is OnEnter..
Back to top
View user's profile Send private message
Tuebits



Joined: 27 Jan 2005
Posts: 18

PostPosted: Wed Feb 09, 2005 23:13    Post subject: Reply with quote

how about using SetPersistentInt(oPC,"dead",1)' OnDeath event.

then change SetPersistentInt(oPC,"dead",0) when repawn, raise dead, and ressurect.. and leave my OnClientEnter the same, as well as aps_inclde.. ?
Back to top
View user's profile Send private message
NoMercy



Joined: 03 Jan 2005
Posts: 123
Location: UK

PostPosted: Wed Feb 09, 2005 23:32    Post subject: Reply with quote

You can mark them dead on the death event, but do remember sometimes people come back to live though other means (DM's clicking heal buttons come to mind) so it's a good idea to also save on logout, and mabie in other situations as well.

I guess if you were paranoid enough you could set a psudo heartbeat off checking every minute if the player has come back to live though means other than respawn/raise/resurect.
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Tuebits



Joined: 27 Jan 2005
Posts: 18

PostPosted: Wed Feb 09, 2005 23:42    Post subject: Reply with quote

ohh i forgot about the DM heal button...respawn, ress, raise dead are the only 3 other options. you know if the DM heal has its own script and the possible NWN base script name for it, can always add it there too if there is a script for it
Back to top
View user's profile Send private message
dguntner



Joined: 31 Dec 2004
Posts: 116

PostPosted: Thu Feb 10, 2005 9:16    Post subject: Reply with quote

Dazzle wrote:
NWN can't get any of the GetPCPlayerName/GetName at ClientLeave from a leaving player, [...]


Just FYI, GetName() works fine on a leaving player in the OnClientLeave script. But you're right, GetPCPlayerName() won't turn anything up at that point.

--Dave
Back to top
View user's profile Send private message
DarkstarsDad



Joined: 17 Jan 2005
Posts: 59
Location: Overland Park, Kansas USA

PostPosted: Sun Feb 13, 2005 6:15    Post subject: cool Reply with quote

Damn I didnt know that. thanks dave. i can use that for another script Im working on.
_________________
Just because you think you can't. Is the best reason to try it anyway.
Back to top
View user's profile Send private message
chunkymonky



Joined: 20 Feb 2005
Posts: 31

PostPosted: Sun Feb 20, 2005 16:18    Post subject: Reply with quote

I'm having a similar problem with my death system and persistence. Could someone please advise me how to make death persistent with NWNX/APS? My scripting is ok, not spectacular, so it is a vexing situation for me.
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