Custom Scripting: Difference between revisions

From Sinfar
(Add Content From: Using Sinfar Spawning System)
Line 34: Line 34:


* Only Sinfar Supporters can create Players Blueprints/Scripts and upload a house that uses them. Any Sinfar Supporter can use any of the Players Scripts or Bluprints, but they can only be changed by the owner (the player id of the owner is in the ResRef: p_<hex_player_id>_). All resources are listed here: https://nwn.sinfar.net/res_list.php?erf_id=2
* Only Sinfar Supporters can create Players Blueprints/Scripts and upload a house that uses them. Any Sinfar Supporter can use any of the Players Scripts or Bluprints, but they can only be changed by the owner (the player id of the owner is in the ResRef: p_<hex_player_id>_). All resources are listed here: https://nwn.sinfar.net/res_list.php?erf_id=2
= Using Sinfar Spawning System =
Sinfar's spawning system is documented here: [[Sinfar Spawning System]] and it can be used inside houses with a few differences.
=== Usage Difference ===
# The tag must have the additional prefix "_P_", for example: _P_SPAWN_C_P_25_SERVANT: <br />[[File:Sinfar spawning system 20190313-001318.png]]
# The variables must have the additional prefix "P_", for example P_SPAWN_CHANCE: <br />[[File:Sinfar spawning system 20190313-001245.png]]
=== How It Was Enabled ===
Simply by adding those 2 lines:
<syntaxhighlight lang="nwscript">
    RegisterVariableEvent(oArea, "EVENT_WOKEUP", "p_x_wokeupare");
    RegisterVariableEvent(oArea, "EVENT_SUSPEND", "p_x_suspendare");
</syntaxhighlight>
When an house area is created (SetupHomeArea in [https://nwn.sinfar.net/res_nss_edit.php?name=home_include home_include]). You could do the same by setting variables on your areas ([[Variable Based Events]]) and create your own system, but for Sinfar Spawn System, it is done automatically.
You can look at those 2 scripts: [https://nwn.sinfar.net/res_nss_edit.php?name=p_x_wokeupare p_x_wokeupare] and [https://nwn.sinfar.net/res_nss_edit.php?name=p_x_suspendare p_x_suspendare]: they basically call the same functions but of course in the context of an house script (p_) so GetLocalString automatically ensure that the variable name is prefixed by P_ and the tag check expect the _P_ prefix because it is also mandatory for a player blueprint.


[[Category:Sinfar Supporters]]
[[Category:Sinfar Supporters]]

Revision as of 21:30, 29 November 2023

Players Custom Scripts

Sinfar Supporters can make their own scripts for inside their house.

  • The NWScript virtual machine use this 2da: pf_nwscript.2da (Supporter Login Required) ... to validate each function call.

Here's what each column are for:

Column Description
Enable

**** = The function call will do nothing and return an empty value.
YES = The function will be called if the parameters and OBJECT_SELF are valid.
AS_IS = The function will be called no matter what.

ExecuteScript After the validation, instead of calling the internal code, this script will be executed as an event with the same parameters.
GetNextFunction Since the default behaviour of GetFirst/Next functions may return invalid objects and so break make it inefficient/impossible to loop through all objects, when this field is set, the engine will automatically call this next function until it can return a valid object or if it has really reached the last object.
ObjectSelf
Param1
Param2
ParamN
This are the restriction of each parameter and the caller. If the restriction check fails, the function call will do nothing and return an empty value. The parameter depends on the value type

NO_PC = The object must have been created by a player script.
NO_MODULE = The object can't be the module.
string/any value (often "P_") = What the string must start by.
  • Only the module and objects that are in the house (any area of the house) are accessible. Functions may return external objects but then GetIsObjectValid(oExternalObject) will return false and calling any function with those objects as parameter will fail.
  • Only Players Blueprints can be created with the CreateObject function.
  • The events script field of Player Blueprints must start by "p_".
  • Players Dialogs must start by "p_".
  • Players Blueprints Tag must always start by "_P_".
  • Local variables and Campaign variables must start by "P_".
  • Only Sinfar Supporters can create Players Blueprints/Scripts and upload a house that uses them. Any Sinfar Supporter can use any of the Players Scripts or Bluprints, but they can only be changed by the owner (the player id of the owner is in the ResRef: p_<hex_player_id>_). All resources are listed here: https://nwn.sinfar.net/res_list.php?erf_id=2

Using Sinfar Spawning System

Sinfar's spawning system is documented here: Sinfar Spawning System and it can be used inside houses with a few differences.

Usage Difference

  1. The tag must have the additional prefix "_P_", for example: _P_SPAWN_C_P_25_SERVANT:
  2. The variables must have the additional prefix "P_", for example P_SPAWN_CHANCE:

How It Was Enabled

Simply by adding those 2 lines:

    RegisterVariableEvent(oArea, "EVENT_WOKEUP", "p_x_wokeupare");
    RegisterVariableEvent(oArea, "EVENT_SUSPEND", "p_x_suspendare");

When an house area is created (SetupHomeArea in home_include). You could do the same by setting variables on your areas (Variable Based Events) and create your own system, but for Sinfar Spawn System, it is done automatically.

You can look at those 2 scripts: p_x_wokeupare and p_x_suspendare: they basically call the same functions but of course in the context of an house script (p_) so GetLocalString automatically ensure that the variable name is prefixed by P_ and the tag check expect the _P_ prefix because it is also mandatory for a player blueprint.