Aller au contenu

Photo

Help with Script


  • Veuillez vous connecter pour répondre
10 réponses à ce sujet

#1
YeoldeFog

YeoldeFog
  • Members
  • 282 messages

Hey!

 

I am looking for some kind of sacrifice script.

 

Details

When a PC kills (anything) inside a designated area (trigger) a door opens.

 

Can someone go pro at this? :)

 

 



#2
belisarius

belisarius
  • Members
  • 9 messages
Hmmm.

Can the solution involve changing the default OnDeath script?

If yes, its as simple as adding a single conditional.

If no, need to setup a listener for on death shouts, fiddly. I don't have my computer here, or I'd write and test it, sorry

#3
Proleric

Proleric
  • Members
  • 2 343 messages

Is it the PC or the creature that need to be in the trigger, or both?

 

Assuming it's the creature - in the trigger OnEnter, set a local int flag on the creature. OnExit, delete it. Add a line to the OnDeath script(s) to open the door if the flag is set.

 

Have a go. Happy to help if your script doesn't work.



#4
YeoldeFog

YeoldeFog
  • Members
  • 282 messages

Hey and thanks for the reply!

 

Proleric: I have figured this out myself, but I would need some help with the actual script. I tried it myself with Lilac's, but it didn't work. :/



#5
Proleric

Proleric
  • Members
  • 2 343 messages

If you post what you have so far, I'm sure we can fix it.



#6
YeoldeFog

YeoldeFog
  • Members
  • 282 messages

I have nothing, because Lilac only set integers on the PC and not the creature/npc. 

 

But this is what I got

 

//Put this script OnDeath
void main()
{


object oPC = GetLastKiller();


if (!GetIsPC(oPC)) return;


if (GetLocalInt(oPC, "int_sacrifice_tri")!= 1)
   return;


object oTarget;
oTarget = GetObjectByTag("sv_barrow_door");


AssignCommand(oTarget, ActionOpenDoor(oTarget));


}


#7
Proleric

Proleric
  • Members
  • 2 343 messages

OK, so heading in the right direction, just needs some work.

 

If you already have many different creatures that might be sacrificed, you probably want to make one script change that affects them all automatically. That avoids all the work of editing the creature templates and instances.

 

So, I suggest you change the default OnDeath script nw_c2_default7.

 

Open the script editor > Open An Existing File > check "All Resources" > select "nw_c2_default7" > OK to the warning.

 

Replace this line

 

craft_drop_items(oKiller);

 

with this:

 

craft_drop_items(oKiller);
 
// Custom code
 
if (GetLocalInt(OBJECT_SELF, "int_sacrifice_tri")!= 1)
   return;

object oTarget;
oTarget = GetObjectByTag("sv_barrow_door");

AssignCommand(GetModule(), AssignCommand(oTarget, ActionOpenDoor(oTarget)));
// End custom code
 

 

You'll see I've made two changes to your code.

 

Firstly, OBJECT_SELF is the creature who just died.

 

Secondly, I've told the module to issue your action to the door. This is a trick to avoid the general rule that orders issued by dead creatures get cancelled.

 

I can make it a little tidier, if you like.



#8
YeoldeFog

YeoldeFog
  • Members
  • 282 messages

Perfect, it works. I made the OnEnter and OnExit trigger aswell! Thank you! :)


  • Proleric aime ceci

#9
meaglyn

meaglyn
  • Members
  • 802 messages

Nice. One thing you might want to do is reverse the sense of the "if", remove the return; and enclose the rest in brackets {}.   As it stands if you add any code after that it won't run unless this variable is set. It just looks like a frustrating bug waiting to happen. 

e.g.:

if (GetLocalInt(OBJECT_SELF, "int_sacrifice_tri")) {
        object oTarget;
        oTarget = GetObjectByTag("sv_barrow_door");

        AssignCommand(GetModule(), AssignCommand(oTarget, ActionOpenDoor(oTarget))); 
}

Also, why not just assign the opendoor command to the module?



#10
Proleric

Proleric
  • Members
  • 2 343 messages
Sure, and declare oTarget in the assignment line, too, perhaps.

That was the "tidiness" I refered to. I just wanted to use as much as possible of the original script, to demonstrate that having a go gets close to something that works, with a little help from us.

#11
meaglyn

meaglyn
  • Members
  • 802 messages

Yeah, totally with you and not trying to criticize :)  I could see him adding more code down there for another feature and not getting the results he expected.  that's a bit more than tidiness. It's a functional difference which may save Fog some pain later on.  Just trying to save future pain ...


  • Proleric aime ceci