Author Topic: Examples of utilising the death handler  (Read 11016 times)

0 Members and 2 Guests are viewing this topic.

Offline Cloudee1

Examples of utilising the death handler
« on: January 11, 2007, 09:23:19 PM »
Alright so you have done the tutorial and now you are working on your own game, and you want the character to die but getting the user to type "die" just isn't going to cut it. Most cases of handling death can be done in the same way, by adding in a doit method. For instance being too close to a character or view, crossing a road or perhaps standing in the wrong spot, like under a piano. Would all be handled in the doit method.

Kill the character whenever something else gets too close. We will of course need to have an instance of the oPPonent actor, as well as having it inited, but otherwise to activate the death script.
Code: [Select]
(method (doit)
 (var dyingScript) // don't forget this line
 (super:doit())

   (if(not(gProgramControl))
    (if(< (send gEgo:distanceTo(oPPonent)) 40)
      ProgramControl()
//      (oPPonent:cel(0)loop(4)setMotion(NULL)setCycle(Fwd)) // switch opponent to attacking
//      (send gEgo:view(1)cel(0)setMotion(NULL)setCycle(Fwd))// switch ego to getting attacked
 
      = dyingScript ScriptID(DYING_SCRIPT)
      (send dyingScript:
       caller(3)
       register("You're dead")
       )
      (send gGame:setScript(dyingScript))   
    )
   )
 ) // end method
  
Similarly, If perhaps ego were to attempt crossing an uncrossable road. Rather than measure the distance between ego and something you can just simply lay down say a purple control color line on the road where ego can't cross. For this you will still need a doit method but the car which is still an actor since we need to apply motion to it, but you won't need to init it when you do all the normal things, but rather right when it's needed, afterall it may never actually be needed.
Code: [Select]
(method (doit)
 (var dyingScript)
 (super:doit())

   (if(not(gProgramControl))
    (if(== (send gEgo:onControl()) $0021)// purple and black
      ProgramControl()
      (oPPonent:cel(0)loop(4)setMotion(walk)MoveTo(0 165)init()) // Car starts down road
      (send gEgo:view(1)cel(0)setMotion(NULL)setCycle(End))// switch ego to getting hit
 
      = dyingScript ScriptID(DYING_SCRIPT)
      (send dyingScript:
       caller(3)
       register("You're dead")
       )
      (send gGame:setScript(dyingScript))
  
    )
   )
 ) // end method
  

Another way of doing it would aslo be to check if ego was in a rectangle and whenever they are trigger the events. It's exactly the last two examples except the beginning if statement, which is essentially what typing the word die in is in that section of the tutorial, it is simply the trigger to start the death event.  The best way by far, giving the most room for animations is to place the death handler at the end of a changestate.
« Last Edit: January 13, 2007, 02:58:14 AM by Cloudee1 »


Halloween Competition Brass Lantern Prop Competition Groundhog Day Competition

Offline Cloudee1

Re: Examples of utilising the death handler
« Reply #1 on: November 04, 2014, 08:54:58 PM »
While we are talking about the death handler, we may as well touch on a few modifications that are easily made.

To start with, the caller variable. As it is set up in the template game, represents the view to be used for the icon in the death's print statement. While I like the idea of using a view in the print statement, what I don't like is using a different view for each death icon that I want to use. Instead I would rather use a single view and instead multiple loops.

This is a pretty easy change. In my case, I placed all of the death icons into a single view, 900. Any number can be used of course, this is just the one that I picked and plan to stay with.

In dying.sc, I hard coded the view to 900 and then used the caller variable to point to the loop I want instead of the view. So I changed this
Code: [Select]

  (if(<> NULL caller)
  Load(rsVIEW caller)
  (deadIcon:view(caller))
  )(else
  Load(rsVIEW DYING_SCRIPT)
  (deadIcon:view(DYING_SCRIPT))
  )
to this
Code: [Select]
  //(if(<> NULL caller)
  Load(rsVIEW 900)
  (deadIcon:view(900)loop(caller)cel(0))
  //)(else
  // Load(rsVIEW DYING_SCRIPT)
  // (deadIcon:view(DYING_SCRIPT))
  //)

Also, while we are at it, that 3 seconds thing before triggering the death statement really bugs me. I usually call the death statement at the end of a changestate method in a room so I already have full control of when where and how everything is animated. Again, changing this is another easy edit. In case 0 of the dying scripts changestate, there is the line
Code: [Select]
= seconds 3
Personally a brief pause is more than enough for my needs so this is one I change to
Code: [Select]
= cycles 5

And lastly for today, a dcicon, which is what the death print statement really is, by default cycles forward indefinately. While this is fine as long as you know that when you draw it, you may have cases where you don't want it to play indefinately but instead just want it to play through once to end.

If you scroll all the way down to the bottom of the dying script
Code: [Select]
(instance deadIcon of DCIcon
(properties)
(method (init)
(super:init())
(if(== gRoomNumberExit 540)
= cycler (End:new())
(send cycler:init(self))
)
)
)
Now, in this little bitty instance, you'll notice the gRoomNumberExit. Basicly this if statement says that if the dying script was called from room 540 then just play the animation till the last cel, otherwise it maintains its default behavior of just playing indefinately. If you want all of the death print icons, regardless of rooms to play till the last cel, then you could simply comment out the if statement and the closing ) all together.

Code: [Select]
(instance deadIcon of DCIcon
(properties)
  (method (init)
  (super:init())
    //(if(== gRoomNumberExit 2)
= cycler (End:new())
(send cycler:init(self))
     //)
  )// end method
)// end instance

Or if you want a mix, some room's death icons cycle indefinitely and other room's don't, then you would want to edit the if statement to include the rooms where it only plays till the end.

Code: [Select]
(instance deadIcon of DCIcon
(properties)
  (method (init)
  (super:init())
(if(
             (== gRoomNumberExit 2) or
             (== gRoomNumberExit 6) or
             (== gRoomNumberExit 54)
            )
= cycler (End:new())
(send cycler:init(self))
     )
  )// end method
)// end instance

I suppose better yet would be to create a new global variable and set it when calling the dying script, and then check against it in this little instance. That would give you the option per death, not just by room.
« Last Edit: November 04, 2014, 08:59:23 PM by Cloudee1 »
Halloween Competition Brass Lantern Prop Competition Groundhog Day Competition


SMF 2.0.19 | SMF © 2021, Simple Machines
Simple Audio Video Embedder

Page created in 0.033 seconds with 21 queries.