Difference between revisions of "Death Handler"
m (1 revision) |
|||
(2 intermediate revisions by the same user not shown) |
Latest revision as of 12:50, 11 August 2013
By Cloudee1
Examples of Utilizing the Death Handler
Most cases of a death event 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.
(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 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, after all, it may never actually be needed.
(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 also 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.