A common task that can be more confusing that it should be is adjusting the level, equipment or gold of a character when entering a module. A solid understanding of what scripts are called when the PC enters is a good place to start. Much of this information is taken from this post: http://nwn2forums.bioware.com/forums/viewtopic.html?topic=528278&forum=1...
What happens when a PC enters a module
When a PC logins in, the first events to fire are the OnAcquireItem and OnPlayerEquipItem events. At that point, the PC object exists and can have inventory. But it has no location.
Then OnClientEnter fires. The PC object is complete, but still has no location. (the lack of location is what causes most scripting issues)
Once the PC has been assigned an area, OnPCLoaded is called.
Then OnEnter and OnClientEnter are called for the area the PC ends up in. (OnEnter is called for all creatures entering an area - including NPC right after onModuleLoad, OnClientEnter is just for PCs)
A trigger would be called last.
Transitioning between modules in a campaign
One more thing I noticed: when you transition to a new module in a campaign (StartNewModule and LoadNewModule), OnPCLoaded is not called. OnClientEnter is called, and so are the area's OnEnter and OnClientEnter. (onClientLeave is also not called)
OnPCLoaded is called when a PC logs out and back in.
Adjusting the new characters
The best way I've found to adjust a new PC is to use an OnClientEnter Script. Go to View > Module Properties to get to the Module Properties window. Under the Scripts heading, look for the On Client Enter Script.
The following script is an example that checks to see if this is the first time the PC has entered the current campaign, removes all inventory, then sets the XP and gold for a level 3 character.
// example_oncliententer
/*
Description:
Onclient enter to call
Also has additional functions to set up first time
entry scripts for the pc.
FRW xp and gold guidelines:
Level XP Gold
2nd 1,000 450
3rd 3,000 1,350
4th 6,000 2,700
5th 10,000 4,500
6th 15,000 6,500
7th 21,000 9,500
8th 28,000 13,500
9th 36,000 18,000
10th 45,000 24,500
11th 55,000 33,000
12th 66,000 44,000
13th 78,000 55,000
14th 91,000 75,000
15th 105,000 100,000
16th 120,000 130,000
17th 136,000 170,000
18th 153,000 220,000
19th 171,000 290,000
20th 190,000 380,000
*/
// Vendalus Nov 15, 2008
// Removes all items from the players inventory
void RemoveAllItems( object oPC )
{
DestroyObject(GetItemInSlot(INVENTORY_SLOT_ARMS, oPC));
DestroyObject(GetItemInSlot(INVENTORY_SLOT_ARROWS, oPC));
DestroyObject(GetItemInSlot(INVENTORY_SLOT_BELT, oPC));
DestroyObject(GetItemInSlot(INVENTORY_SLOT_BOLTS, oPC));
DestroyObject(GetItemInSlot(INVENTORY_SLOT_BOOTS, oPC));
DestroyObject(GetItemInSlot(INVENTORY_SLOT_BULLETS, oPC));
DestroyObject(GetItemInSlot(INVENTORY_SLOT_CARMOUR, oPC));
DestroyObject(GetItemInSlot(INVENTORY_SLOT_CHEST, oPC));
DestroyObject(GetItemInSlot(INVENTORY_SLOT_CLOAK, oPC));
DestroyObject(GetItemInSlot(INVENTORY_SLOT_CWEAPON_B, oPC));
DestroyObject(GetItemInSlot(INVENTORY_SLOT_CWEAPON_L, oPC));
DestroyObject(GetItemInSlot(INVENTORY_SLOT_CWEAPON_R, oPC));
DestroyObject(GetItemInSlot(INVENTORY_SLOT_HEAD, oPC));
DestroyObject(GetItemInSlot(INVENTORY_SLOT_LEFTHAND, oPC));
DestroyObject(GetItemInSlot(INVENTORY_SLOT_LEFTRING, oPC));
DestroyObject(GetItemInSlot(INVENTORY_SLOT_NECK, oPC));
DestroyObject(GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oPC));
DestroyObject(GetItemInSlot(INVENTORY_SLOT_RIGHTRING, oPC));
object oItem = GetFirstItemInInventory();
while( GetIsObjectValid(oItem) ){
DestroyObject(oItem);
oItem = GetNextItemInInventory();
}
}
// Checks to see if this player has already entered the campaign for the first time
int GetHasEnteredThisCampaign( object oPC )
{
return GetGlobalInt("ENTERED_"+GetName(oPC));
}
// Notes that this player entered the module for the first time
void SetHasEnteredThisCampaign( object oPC )
{
SetGlobalInt("ENTERED_"+GetName(oPC), TRUE);
}
// Gives some starting gold
void GiveStartingGold( object oPC, int nAmount )
{
int nGold = GetGold(oPC);
TakeGoldFromCreature(nGold, oPC, TRUE);
GiveGoldToCreature(oPC, nAmount);
}
void main()
{
// get our entering player
object oPC = GetEnteringObject();
// Only run if this is a pc who is entering for the first time
// and who is not a DM.
if( GetIsPC(oPC) && !GetHasEnteredThisCampaign(oPC) && !GetIsDM(oPC)){
// Note that this pc has entered for the first time
SetHasEnteredThisCampaign(oPC);
// Remove all items from the entering player
RemoveAllItems(oPC);
// Give them some starting gold for level 3
GiveStartingGold(oPC, 1350);
// Adjust to level 3
SetXP(oPC, 3000);
}
}
Obviously in a case like this, you'd want to present the character with a store immediately. Note also that there is a chart at the top of the script showing the XP and total gold guidelines per level as outlined by the Forgotten Realms Weave.
What happens when a PC leaves the module
Similarly, when the PC logs out OnClientLeave gets called. At that time, the client information is no longer associated with the object, just the physical characteristics. (which is another scripting issue) Then OnExit for the area is called (unless the PC logs out dead, then it is not called). Usually, there is nothing to do here and there have been some reports of this not firing correctly all the time.
Recent comments
2 years 15 weeks ago
2 years 15 weeks ago
2 years 15 weeks ago
2 years 20 weeks ago
2 years 21 weeks ago
2 years 37 weeks ago
2 years 38 weeks ago
2 years 42 weeks ago
2 years 42 weeks ago
2 years 45 weeks ago