Hi all,
I've spent some time looking at this code and can't for the life of me figure out why it won't trigger. Here's some background: I have a script that creates an "I Am Disturbed Token" on a NPC when the right conditions are met. The idea is once this item was created in the inventory, the user defined
disturbed script section would fire with my code. The problem is this
isn't happening.
I already double checked with the DM Client and needless to say that one Token (and ONLY one) IS getting created in my creature's inventory. I have altered my onspawn code to allow user defined disturbed events to fire this script in the OnUserDefined tab.
Here is the code:
#include "nw_i0_plot"
const int EVENT_USER_DEFINED_PRESPAWN = 1510;
const int EVENT_USER_DEFINED_POSTSPAWN = 1511;
void main()
{
int nUser = GetUserDefinedEventNumber();
int iRan = d3(); \\\\ Ignore this, it just determines my NPC's reaction
object oNPC = OBJECT_SELF;
object oPC = GetLocalObject(GetModule(), "o_magicuser");
else if(nUser == EVENT_DISTURBED) // DISTURBED
{
// This event triggers when the NPC loses his I Am Disturbed Token. It
// creates another one in their inventory (so they can get disturbed again),
// and causes the reaction.
if (HasItem(oNPC, "iamdisturbedtoke"))
{
DestroyObject(GetItemPossessedBy(oNPC, "iamdisturbedtoke"));
iRan = d3();
// Depending on iRan, oNPC will say something different
if (iRan == 1)
{
AssignCommand(oNPC, ActionSpeakString("Magicker!", TALKVOLUME_SHOUT));
}
else if (iRan == 2)
{
AssignCommand(oNPC, ActionSpeakString("Help! Magic user!", TALKVOLUME_SHOUT));
}
else
{
AssignCommand(oNPC, ActionSpeakString("Wizard! Wizard!", TALKVOLUME_SHOUT));
}
// This part causes oNPC to flee from oPC
AssignCommand(oNPC, ActionMoveAwayFromObject(oPC, TRUE));
DelayCommand(60.0, SetLocalInt(oNPC, "int_sawmagicuser", FALSE));
}
}
}
UserDefined OnDisturbed Script Not Firing
Débuté par
Ralthis
, mars 25 2011 06:50
#1
Posté 25 mars 2011 - 06:50
#2
Posté 25 mars 2011 - 08:11
Hmm...Well this script doesn't even compile. You started with an "else if" instead of just an "if".
#include "nw_i0_plot"
const int EVENT_USER_DEFINED_PRESPAWN = 1510;
const int EVENT_USER_DEFINED_POSTSPAWN = 1511;
void main()
{
int nUser = GetUserDefinedEventNumber();
int iRan = d3(); \\\\ Ignore this, it just determines my NPC's reaction
object oNPC = OBJECT_SELF;
object oPC = GetLocalObject(GetModule(), "o_magicuser");
else if(nUser == EVENT_DISTURBED) // DISTURBED
{
// This event triggers when the NPC loses his I Am Disturbed Token. It
Did this compile for you? Is there any of this script missing?
#include "nw_i0_plot"
const int EVENT_USER_DEFINED_PRESPAWN = 1510;
const int EVENT_USER_DEFINED_POSTSPAWN = 1511;
void main()
{
int nUser = GetUserDefinedEventNumber();
int iRan = d3(); \\\\ Ignore this, it just determines my NPC's reaction
object oNPC = OBJECT_SELF;
object oPC = GetLocalObject(GetModule(), "o_magicuser");
else if(nUser == EVENT_DISTURBED) // DISTURBED
{
// This event triggers when the NPC loses his I Am Disturbed Token. It
Did this compile for you? Is there any of this script missing?
Modifié par GhostOfGod, 25 mars 2011 - 08:11 .
#3
Posté 25 mars 2011 - 03:32
Sorry, I should have mentioned that I cut out parts and and pasted from the default OnUserDefined script (x2_def_userdef). The actual script is much longer (starting with a whole other section for behaviour on perceive), but I didn't want to post a script with a whole bunch of sections that have nothing to do with my problem. Again, my bad,
!
#4
Posté 25 mars 2011 - 07:29
You said your NPCs do receive the item as they are suppose to cant you use the onacquire to fire the pattern you want?
#5
Posté 25 mars 2011 - 08:05
That's a much better idea than what I was trying to do...thanks Baragg!
#6
Posté 25 mars 2011 - 09:01
My guess Is that it was not working because you never set the SpawnInCondition :
SetSpawnInCondition(NW_FLAG_DISTURBED_EVENT)
In your onSpawn script or it is commented out. Without it being set the UserDefined Event will never fire from the Disturbed Event.
However If you are always creating the Object in the creatures inventory and he is never picking it up or having a DM place it in his inventory. You are jumping through to many hoops to get where you are going.
Again if the item is always being created in the inventory by a script. All you need to do is directly signal the User Defined Event from the script instead of creating the Item. .
SignalEvent(oCreature, EventUserDefined(EVENT_DISTURBED));
SetSpawnInCondition(NW_FLAG_DISTURBED_EVENT)
In your onSpawn script or it is commented out. Without it being set the UserDefined Event will never fire from the Disturbed Event.
However If you are always creating the Object in the creatures inventory and he is never picking it up or having a DM place it in his inventory. You are jumping through to many hoops to get where you are going.
Again if the item is always being created in the inventory by a script. All you need to do is directly signal the User Defined Event from the script instead of creating the Item. .
SignalEvent(oCreature, EventUserDefined(EVENT_DISTURBED));
#7
Posté 26 mars 2011 - 10:47
Ahh, that would be much better. Thank you Lightfoot. It's my first time trying to use UserDefined scripting, so any advice is good advice. Baragg, I tried your method, and it works like a charm!
#8
Posté 27 mars 2011 - 02:26
Trust me when I say, Lightfoot is waaaaay better at this than I, but I do have a moment every once and again.





Retour en haut






