Author Topic: DelayCommand() in nwnx_funcs onplayerleaving  (Read 335 times)

Legacy_Kato -

  • Hero Member
  • *****
  • Posts: 747
  • Karma: +0/-0
DelayCommand() in nwnx_funcs onplayerleaving
« on: December 16, 2011, 05:35:58 pm »


               Hi,

Although this is rather straightforward and simple, something is apparently wrong with this code example, used in nwnx_funcs onplayerleaving, the script hooking the OnClientLeave event:

void main()
{
    // OBJECT_SELF is the player currently leaving
    string sName = GetName(OBJECT_SELF);
    string sAcc = GetPCPlayerName(OBJECT_SELF);

    AssignCommand(GetModule(), DelayCommand(300.0, UpdateDBPCInfos(sName, sAcc)));
}

The problem is, both variables are empty when the DelayCommand() is executed. This would be normal in the standard OnClientLeave event handler, but not with nwnx_funcs onplayerleaving... Maybe 12-15 hours of coding a day is ruining my brain and I forgot something simple, thanks in advance for any insight.


Kato
               
               

               


                     Modifié par Kato_Yang, 16 décembre 2011 - 05:48 .
                     
                  


            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
DelayCommand() in nwnx_funcs onplayerleaving
« Reply #1 on: December 16, 2011, 05:40:58 pm »


               code is correct, I don't use account or name but currenthitpoints and player tag and both works, so there is no reason why those functions you tried should't work

just to be sure, you didn't added this script into module OnPlayerLeave event right?
Did you also set up nwnx_funcs in NWNX.ini? It should look like this:

[FUNCS]
Number_of_Skills=28
HOOK_CustomTrapGeometry=1
HOOK_OnPlayerLeaving=1
OnPlayerLeavingScript=your_script_name


               
               

               
            

Legacy_Kato -

  • Hero Member
  • *****
  • Posts: 747
  • Karma: +0/-0
DelayCommand() in nwnx_funcs onplayerleaving
« Reply #2 on: December 16, 2011, 05:51:37 pm »


               Thanks for the confirmation and reminder, ShadoOoW, I have re-verified and everything is set as you suggest. I'll dig deeper and report any findings if they are instructive...


Kato
               
               

               


                     Modifié par Kato_Yang, 16 décembre 2011 - 05:52 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
DelayCommand() in nwnx_funcs onplayerleaving
« Reply #3 on: December 16, 2011, 10:29:07 pm »


               I am confused.  But that may be because I have not used nwnx.   The only thing I can question is the OBJECT_SELF being the PC.    Does the nwnx Hook run the script on the PC instead of the module?
               
               

               
            

Legacy_Kato -

  • Hero Member
  • *****
  • Posts: 747
  • Karma: +0/-0
DelayCommand() in nwnx_funcs onplayerleaving
« Reply #4 on: December 16, 2011, 10:45:05 pm »


               

Lightfoot8 wrote...

I am confused.  But that may be because I have not used nwnx.   The only thing I can question is the OBJECT_SELF being the PC.    Does the nwnx Hook run the script on the PC instead of the module?


Yes, OBJECT_SELF is supposed to be the leaving player, according to the in-script comments, contrary to OnClientLeave scripts where OBJECT_SELF is the mod.


Kato
               
               

               
            

Legacy_wyldhunt1

  • Sr. Member
  • ****
  • Posts: 443
  • Karma: +0/-0
DelayCommand() in nwnx_funcs onplayerleaving
« Reply #5 on: December 16, 2011, 10:46:32 pm »


               I'm a bit shady on the way Funcs handles this also.
I assume it runs with an ExecuteScript(oExitingObject, "funcs_exit") or something.
The part I'm looking at is the huge delay that you have.
I know that I can't delay commands in OnDeath events for NPC's. I can't delay commands in Client Exit events... in any circumstance that requires the object to be a valid object at the time of the delay. So, stuff like GetName requires the object to be valid at the time that the delay happens.

The way I get around it is to make a custom function and pass in the (Still valid) info at the time of death or exit. Then have that function do the delay. That way, you've already passed the info in so the function doesn't lose it.

void UpdateDBP(string sName, string sAcc)
{
   AssignCommand(GetModule(), DelayCommand(300.0, UpdateDBPCInfos(sName, sAcc)));
}


See if something like that works.
               
               

               
            

Legacy_Kato -

  • Hero Member
  • *****
  • Posts: 747
  • Karma: +0/-0
DelayCommand() in nwnx_funcs onplayerleaving
« Reply #6 on: December 16, 2011, 11:16:41 pm »


               Thanks for the suggestion, wyldhunt1, I'll give it a try.


Kato