Author Topic: Help with Script  (Read 1755 times)

Legacy_YeoldeFog

  • Sr. Member
  • ****
  • Posts: 415
  • Karma: +0/-0
Help with Script
« on: June 28, 2016, 08:12:10 am »


               

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? '<img'>


 


 



               
               

               
            

Legacy_belisarius

  • Newbie
  • *
  • Posts: 18
  • Karma: +0/-0
Help with Script
« Reply #1 on: June 28, 2016, 01:43:39 pm »


               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
               
               

               
            

Legacy_Proleric

  • Hero Member
  • *****
  • Posts: 1750
  • Karma: +0/-0
Help with Script
« Reply #2 on: June 28, 2016, 02:59:09 pm »


               

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.



               
               

               
            

Legacy_YeoldeFog

  • Sr. Member
  • ****
  • Posts: 415
  • Karma: +0/-0
Help with Script
« Reply #3 on: June 28, 2016, 04:06:14 pm »


               

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. :/



               
               

               
            

Legacy_Proleric

  • Hero Member
  • *****
  • Posts: 1750
  • Karma: +0/-0
Help with Script
« Reply #4 on: June 28, 2016, 05:54:15 pm »


               

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



               
               

               
            

Legacy_YeoldeFog

  • Sr. Member
  • ****
  • Posts: 415
  • Karma: +0/-0
Help with Script
« Reply #5 on: June 29, 2016, 08:48:24 am »


               

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));


}


               
               

               
            

Legacy_Proleric

  • Hero Member
  • *****
  • Posts: 1750
  • Karma: +0/-0
Help with Script
« Reply #6 on: June 29, 2016, 10:07:39 am »


               

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.



               
               

               
            

Legacy_YeoldeFog

  • Sr. Member
  • ****
  • Posts: 415
  • Karma: +0/-0
Help with Script
« Reply #7 on: June 29, 2016, 01:32:26 pm »


               

Perfect, it works. I made the OnEnter and OnExit trigger aswell! Thank you! '<img'>



               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
Help with Script
« Reply #8 on: June 29, 2016, 02:24:19 pm »


               

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?


               
               

               
            

Legacy_Proleric

  • Hero Member
  • *****
  • Posts: 1750
  • Karma: +0/-0
Help with Script
« Reply #9 on: June 29, 2016, 05:21:53 pm »


               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.
               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
Help with Script
« Reply #10 on: June 29, 2016, 08:30:14 pm »


               

Yeah, totally with you and not trying to criticize '<img'>  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 ...