Difference between revisions of "OnClientLeave"

From NWN Lexicon
Jump to: navigation, search
(Created page with "=OnClientLeave= The script attached to this event fires when a client leaves the module. This can be used to remove any custom creatures spawned because of the appearance o...")
 
(Specify limits of EE update re: Writing data to character.)
 
(8 intermediate revisions by 7 users not shown)
Line 1: Line 1:
=OnClientLeave=
+
The script attached to this event fires when a client leaves the module. This can be used to remove any custom creatures spawned because of the appearance of a particular PC or a variety of other things.
 +
===Trigger===
  
The script attached to this event fires when a client leaves the module. This can be used to remove any custom creatures spawned because of the appearance of a particular PC or a variety of other things. During this event, the player has already left. All data that pertains to the player is unavailable (GetPCPlayerName, GetPCPublicCDKey, GetPCIPAddress) and the player has become detatched from the character object, hence GetIsPC returns false. If you want any of this information at time of client leave, you must have already stored this information (on client enter is a good time to do this). Also, due to this, no locals can be stored on the PC at this time. If you want to store information pertaining to the player during this event, store it on the module with something to indicate which player and character it is for.
+
Whenever a player logs out of a server or leaves the module. This event doesn't trigger in local/single player game at all.
  
<br />
+
===Function(s)===
  
====Trigger====
+
[[GetExitingObject]]() returns the PC who is leaving.
  
Whenever a player logs out of a server or leaves the module.
+
===Remarks===
  
<br />
+
Triggers before player exit an Area and in case the player is dead, area's OnExit event won't fire at all. For more info see [[OnExit]].
  
====Function(s)====
+
Otherwise this in NWN:EE works as expected and you can retrieve and save information from the client/character as they leave for later use. Note you cannot add/save to the character during this (without workaround, See EE Note below)
  
[[GetExitingObject | GetExitingObject() ]] returns the PC who is leaving.
+
===Known Bugs===
  
<br />
+
==== 1.69 and earlier ====
  
====Remarks====
+
During this event, the player has already left. All data that pertains to the player is unavailable ([[GetPCPlayerName]], [[GetPCPublicCDKey]], [[GetPCIPAddress]]) and the player has become detached from the character object, hence [[GetIsPC]] returns false. If you want any of this information at time of client leave, you must have already stored this information (on client enter is a good time to do this). Also, due to this, no locals can be stored on the PC at this time. If you want to store information pertaining to the player during this event, store it on the module with something to indicate which player and character it is for.
  
You can get any information off the GetExtingObject(), which basically means you can store, for example, thier location, and get it locally - SetLocalLocation() and GetLocalLocation() respectivly. There is also little point having anything in this in single player modules. The player never leaves - they can only exit (and thus either start again, or load up a saved game).
+
You can't get any information off the GetExitingObject(), which basically means you can't store, for example, their location, and get it locally - [[SetLocalLocation]]() and [[GetLocalLocation]]() respectively. Some information is however still accessible, namely: [[GetName]], [[GetLocalInt]], [[GetLocalString]], [[GetLocalFloat]], [[GetLocalLocation]] (this list is not exhaustive). However, while data can be accessed from local vars, setting local variables in this event doesn't work. To work around it, you need to set local variable on the module with the player ID / name as a part of the variable name, i.e., <span class="code">SetLocalInt(OBJECT_SELF, ObjectToString(oPC) + "_exited", TRUE);</span>
  
<br />
+
GetPCPlayerName doesn't work properly during this event; GetExitingObject does not return an object that can be saved to the database. See above for reasons, and the other functions that do not return data.
  
====Known Bugs====
+
==== NWN:EE ====
  
GetPlayername doesn't work properly during this event; it does not return an object that can be saved to the database. See above for reasons, and the other functions that do not return data.
+
{{NWNEE}}
  
<br />
+
The bugs related to this script firing are fixed; OnClientLeave event is now called before the creature is physically removed from the area, instead of after, to allow scripting to determine the creature’s position as it leaves. However, OnClientLeave event is still after the automatic server call to save the Character file. Therefore if you add items or save local variables during this event be sure to call [[ExportSingleCharacter]] explicitly before the event end.
  
 
====Example====
 
====Example====
  
<font color="#007f00">// In the Client Exit, the actual object (now almost like a dead-AI
+
<nwscript>
</font><font color="#007f00">// NPC) still exsists, but the PC's properties do not.
+
// In the Client Exit, the actual object (now almost like a dead-AI
</font>
+
// NPC) still exists, but the PC's properties do not.
<font color="#007f00">// In this example, we know GetName will work, such as a
 
</font><font color="#007f00">// characters name "Hero". If we used GetPlayername(), it
 
</font><font color="#007f00">// wouldn't return a valid string, mearly "".
 
</font>
 
<font color="#007f00">// Other things that would be useful might be GetLocalInt(),
 
</font><font color="#007f00">// GetLocalString(), GetLocalLocation() and so on. These might
 
</font><font color="#007f00">// be stored to the database, for example, for when they re-log
 
</font><font color="#007f00">// into the server next time.
 
</font>
 
<font color="#0000ff">void</font> main()
 
{
 
    <font color="#007f00">// Valid data we could use:
 
</font>    <font color="#0000ff">object</font> oPC = GetExitingObject();
 
 
    <font color="#007f00">// If they have an item, of tag SHOUT_EXIT, we shout to the
 
</font>    <font color="#007f00">// world we have exited. As it is the module shouting, it should
 
</font>    <font color="#007f00">// appear as "[SERVER]" as the shouter name.
 
</font>    <font color="#0000ff">if</font>(GetIsObjectValid(GetItemPossessedBy(oPC, <font color="#00007f">"SHOUT_EXIT"</font>))
 
    {
 
        <font color="#007f00">// Shout
 
</font>        SpeakString(<font color="#00007f">"Leaving!"</font> + GetName(oPC), TALKVOLUME_SHOUT);
 
    }
 
}
 
  
====See Also====
+
// In this example, we know GetName will work, such as a
 +
// characters name "Hero". If we used GetPlayername(), it
 +
// wouldn't return a valid string, merely "".
 +
 
 +
// Other things that would be useful might be GetLocalInt(),
 +
// GetLocalString(), GetLocalLocation() and so on. These might
 +
// be stored to the database, for example, for when they re-log
 +
// into the server next time.
 +
 
 +
void main()
 +
{
 +
    // Valid data we could use:
 +
    object oPC = GetExitingObject();
 +
 
 +
    // If they have an item, of tag SHOUT_EXIT, we shout to the
 +
    // world we have exited. As it is the module shouting, it should
 +
    // appear as "[SERVER]" as the shouter name.
 +
    if (GetIsObjectValid(GetItemPossessedBy(oPC, "SHOUT_EXIT"))
 +
    {
 +
        // Shout
 +
        SpeakString("Leaving!" + GetName(oPC), TALKVOLUME_SHOUT);
 +
    }
 +
}
 +
</nwscript>
 +
 
 +
===See Also===
  
 
{| class="seealso"
 
{| class="seealso"
 
|-
 
|-
 
| width="1px" align="right" valign="top" | <font color="gray">functions: </font>
 
| width="1px" align="right" valign="top" | <font color="gray">functions: </font>
|
+
| [[GetExitingObject]]()
[[GetExitingObject | GetExitingObject() ]]
 
 
|}
 
|}
  
Line 70: Line 72:
 
[[Category:Module_Events]]
 
[[Category:Module_Events]]
 
[[Category:Events]]
 
[[Category:Events]]
 +
[[Category:Neverwinter Nights Enhanced Edition Changes]]

Latest revision as of 01:08, 10 February 2021

The script attached to this event fires when a client leaves the module. This can be used to remove any custom creatures spawned because of the appearance of a particular PC or a variety of other things.

Trigger

Whenever a player logs out of a server or leaves the module. This event doesn't trigger in local/single player game at all.

Function(s)

GetExitingObject() returns the PC who is leaving.

Remarks

Triggers before player exit an Area and in case the player is dead, area's OnExit event won't fire at all. For more info see OnExit.

Otherwise this in NWN:EE works as expected and you can retrieve and save information from the client/character as they leave for later use. Note you cannot add/save to the character during this (without workaround, See EE Note below)

Known Bugs

1.69 and earlier

During this event, the player has already left. All data that pertains to the player is unavailable (GetPCPlayerName, GetPCPublicCDKey, GetPCIPAddress) and the player has become detached from the character object, hence GetIsPC returns false. If you want any of this information at time of client leave, you must have already stored this information (on client enter is a good time to do this). Also, due to this, no locals can be stored on the PC at this time. If you want to store information pertaining to the player during this event, store it on the module with something to indicate which player and character it is for.

You can't get any information off the GetExitingObject(), which basically means you can't store, for example, their location, and get it locally - SetLocalLocation() and GetLocalLocation() respectively. Some information is however still accessible, namely: GetName, GetLocalInt, GetLocalString, GetLocalFloat, GetLocalLocation (this list is not exhaustive). However, while data can be accessed from local vars, setting local variables in this event doesn't work. To work around it, you need to set local variable on the module with the player ID / name as a part of the variable name, i.e., SetLocalInt(OBJECT_SELF, ObjectToString(oPC) + "_exited", TRUE);

GetPCPlayerName doesn't work properly during this event; GetExitingObject does not return an object that can be saved to the database. See above for reasons, and the other functions that do not return data.

NWN:EE

Nwnee logo.jpg Note: This article documents Neverwinter Nights: Enhanced Edition new content or changes/updates/fixes to 1.69 functions. These are all listed under the category and patches pages.

The bugs related to this script firing are fixed; OnClientLeave event is now called before the creature is physically removed from the area, instead of after, to allow scripting to determine the creature’s position as it leaves. However, OnClientLeave event is still after the automatic server call to save the Character file. Therefore if you add items or save local variables during this event be sure to call ExportSingleCharacter explicitly before the event end.

Example

// In the Client Exit, the actual object (now almost like a dead-AI
// NPC) still exists, but the PC's properties do not.
 
// In this example, we know GetName will work, such as a
// characters name "Hero". If we used GetPlayername(), it
// wouldn't return a valid string, merely "".
 
// Other things that would be useful might be GetLocalInt(), 
// GetLocalString(), GetLocalLocation() and so on. These might
// be stored to the database, for example, for when they re-log
// into the server next time.
 
void main()
{
    // Valid data we could use:
    object oPC = GetExitingObject();
 
    // If they have an item, of tag SHOUT_EXIT, we shout to the
    // world we have exited. As it is the module shouting, it should 
    // appear as "[SERVER]" as the shouter name.
    if (GetIsObjectValid(GetItemPossessedBy(oPC, "SHOUT_EXIT"))
    {
        // Shout
        SpeakString("Leaving!" + GetName(oPC), TALKVOLUME_SHOUT);
    }
}

See Also

functions:  GetExitingObject()