OnAcquireItem problem
Débuté par
Bubba McThudd
, mai 15 2011 11:14
#1
Posté 15 mai 2011 - 11:14
Greetings All,
I’m scripting a battle and
I want four things to happen when you capture the goblins’ banner;
1) a journal entry is made
2) a local integer is set
(nVictorLV)
3) two sound items play.
4) the script "gob_retreat"
fires, causing the goblins to flee.
I tested this with an
invisible character taking the banner out of a barrel right in front of the
goblin lines, and it worked perfectly.
But when I put the banner in the goblins’ shield slot, the gob_retreat script
fired instantly and the goblin army scampered away as soon as the area
loaded. But the local integer was not
set, the journal entry was not made, nor did the sounds play. Below is the relevant section of my
OnAcquireItem script.
Any ideas?
else
if(GetTag(oItem)=="GoblinStandard")
{
AddJournalQuestEntry("GoblinStandard", 2, oPC);
SetLocalInt(oPC,
"nVictorLV", 1);
object oPC =
GetPCSpeaker();
object oTarget;
oTarget =
GetObjectByTag("sCheers1lv");
SoundObjectPlay(oTarget);
oTarget =
GetObjectByTag("sCheers2lv");
SoundObjectPlay(oTarget);
ExecuteScript("gob_retreat", OBJECT_SELF);
}
}
#2
Posté 15 mai 2011 - 11:39
Hard to tell from that script fragment, but it looks like oPC may be declared after it is used. It's possible that it is also declared elsewhere in your script, but we can't see that here. Try putting the
object oPC = GetPCSpeaker();line as the first thing in the
ifblock. Also, since this may not be part of a conversation, I don't know if GetPCSpeaker will do what you want. You would be better off using a different function to get the PC.
Modifié par MrZork, 15 mai 2011 - 11:42 .
#3
Posté 16 mai 2011 - 02:15
After some experimenting, I'm fairly sure that the problem resides in the line
ExecuteScript("gob_retreat", OBJECT_SELF);
Not sure what the correct formulation is though.
ExecuteScript("gob_retreat", OBJECT_SELF);
Not sure what the correct formulation is though.
#4
Posté 16 mai 2011 - 02:38
Probably just need to change OBJECT_SELF to oPC if the script is supposed to run on whoever acquired the item. But also like MrZork already said, you are using oPC in a function before you even define it. Unless you are doing it twice in your script for some reason.
Something else I don't understand though...if this is an OnAcquire script then why are you even using GetPCSpeaker? You should be using GetModuleItemAcquiredBy. And if this is a tag based script then you also need a check at the top of your script for the item event if you don't already have one. I guess I'm not really clear as to what is going on here.
You really should post the whole script.
I see you have a tag check for the item which means you are probably not using tag based scripting for this. Probably putting everything into an OnAcquire script? This is all just speculation of course.
Your script should/might look something like so:
void main()
{
//object oPC = GetPCSpeaker();
object oPC = GetModuleItemAcquiredBy();
//stuff
//other stuff
//if (//stuff)
//{
//stuff
//}
else if(GetTag(oItem)=="GoblinStandard")
{
object oTarget;
AddJournalQuestEntry("GoblinStandard", 2, oPC);
SetLocalInt(oPC, "nVictorLV", 1);
oTarget = GetObjectByTag("sCheers1lv");
SoundObjectPlay(oTarget);
oTarget = GetObjectByTag("sCheers2lv");
SoundObjectPlay(oTarget);
ExecuteScript("gob_retreat", oPC);
}
}
Something else I don't understand though...if this is an OnAcquire script then why are you even using GetPCSpeaker? You should be using GetModuleItemAcquiredBy. And if this is a tag based script then you also need a check at the top of your script for the item event if you don't already have one. I guess I'm not really clear as to what is going on here.
You really should post the whole script.
I see you have a tag check for the item which means you are probably not using tag based scripting for this. Probably putting everything into an OnAcquire script? This is all just speculation of course.
Your script should/might look something like so:
void main()
{
//object oPC = GetPCSpeaker();
object oPC = GetModuleItemAcquiredBy();
//stuff
//other stuff
//if (//stuff)
//{
//stuff
//}
else if(GetTag(oItem)=="GoblinStandard")
{
object oTarget;
AddJournalQuestEntry("GoblinStandard", 2, oPC);
SetLocalInt(oPC, "nVictorLV", 1);
oTarget = GetObjectByTag("sCheers1lv");
SoundObjectPlay(oTarget);
oTarget = GetObjectByTag("sCheers2lv");
SoundObjectPlay(oTarget);
ExecuteScript("gob_retreat", oPC);
}
}
Modifié par GhostOfGod, 16 mai 2011 - 02:54 .
#5
Posté 16 mai 2011 - 03:23
Also, you might want to have the script check to make sure the desired outcomes (journal, variable, retreat call) don't happen unless the one that acquired the flag is a player character. Use GetIsPC(oPC)
Modifié par The Amethyst Dragon, 16 mai 2011 - 03:23 .
#6
Posté 17 mai 2011 - 03:25
I agree, posting the entire script would help a lot.
Modifié par Khuzadrepa, 17 mai 2011 - 03:29 .





Retour en haut






