 |
Castle Paradox
|
View previous topic :: View next topic |
Author |
Message |
TwinHamster ♫ Furious souls, burn eternally! ♫

Joined: 07 Mar 2004 Posts: 1352
|
Posted: Thu Jul 27, 2006 5:27 am Post subject: Activating a running-over-npc script |
|
|
In my game, there's supposed to be a minigame involving the hero, in a car, squishing npcs.
However, take a look at the screenshot and tell me what's wrong.
Yep. The car is 40x40, instead of 20x20. Meaning I have npcs along with the hero making up the car. The hero is the bottom right corner of the car, the rest are npcs.
I thought that this simple script would do the job:
Code: |
script, car scoring, begin
if(keyval(01))
#PRESSING ESCAPE RESULTS IN GAMEOVER
then(gameover)
if(keyval(75))
then(
walk npc (3, left,1)
walk npc (1, left,1)
walk hero (me, left,1)
walk npc (2, left,1)
wait for npc (3)
wait for npc (1)
wait for hero(me)
wait for npc (2)
)
#PRESSING LEFT MOVES EVERYTHING LEFT
if(keyval(77))
then(
walk npc (3, right,1)
walk npc (1, right,1)
walk hero(me, right,1)
walk npc (2, right,1)
wait for npc (3)
wait for npc (1)
wait for hero(me)
wait for npc (2)
)
#PRESSING RIGHT MOVES EVERYTHING RIGHT
if(
#npc 4 is a standard npc.
(herox(me)==npcx(4)) and (heroy(me)==npcy(4)) or (npcx(1)==npcx(4)) and (npcy(1)==npcy(4))
)
then(
set npc direction (4, up)
#NPC SHOWS ITS DEATH IMAGE
wait(5)
destroy npc (4)
set variable (car score, carscore+100)
#GET YOUR SCORE RAISED
end |
Npc 1 is the bottom left corner of the car. I've turned on suspend obstruction so that the npc doesn't stop the car from moving.
Why can't I get the kill-the-npc part of the script to activate? |
|
Back to top |
|
 |
msw188
Joined: 02 Jul 2003 Posts: 1041
|
Posted: Thu Jul 27, 2006 1:15 pm Post subject: |
|
|
My first thought is that this will only work if there is only ever ONE copy of NPC 4 existent at a time, because otherwise it may be checking against the wrong copy of NPC 4. Another possibility is that the 'and' and 'or' operators need special attention, and it should look more like (I'm going to intersperse brackets with the parantheses just to make it easier to see):
if ( [ (herox==x),and,(heroy==y) ] , or , [ (npcx==x),and,(npcy==y) ] )
I just typed up a bit about using 'NPC at spot' instead, and then realised that it was going to have trouble deciding what to return, since the whole idea is that you have two npcs at the same spot. So it has been erased, and now replaced with this paragraph, useless but for the advice to not use 'NPC at spot'... |
|
Back to top |
|
 |
TwinHamster ♫ Furious souls, burn eternally! ♫

Joined: 07 Mar 2004 Posts: 1352
|
Posted: Thu Jul 27, 2006 3:20 pm Post subject: |
|
|
Found the error. I need to move the kill npc segment of the script to a separate script that's located in the each-step script. Then again, I forgot to add commas around the and/or commands.
Thanks a lot for the help |
|
Back to top |
|
 |
TMC On the Verge of Insanity
Joined: 05 Apr 2003 Posts: 3240 Location: Matakana
|
Posted: Fri Jul 28, 2006 6:00 pm Post subject: |
|
|
If this is your onkeypress script, you could move the move left and move right blacks to your eachstep script too. I assume your eachstep script moves the npcs to be squished up the screen. If that's not too difficult though...
You can use npcatspot, though msw is right in that you have to be very careful. Something like:
Code: |
variable (i, ref)
for (i, 0, 1) do (
ref := npc at spot (X, Y, i)
if (get npc id (ref) >= 4) then (
#NPC DEATH CODE HERE (using ref)
#....
)
)
|
This ignores npcs with ids below 4, and handles 2 npcs on the same spot (If you want to handle 3 npcs for example use for (i,0,2) )
Trivia:
The commas around and and or in this case are optional. Here's why:
( is translated to ,begin,
) is translated to ,end,
(That's right! HS uses end and begin internally, and ( and ) are merely shortcuts!)
So basically, you don't need to put commas between a ) or ( and anything else. _________________ "It is so great it is insanely great." |
|
Back to top |
|
 |
TwinHamster ♫ Furious souls, burn eternally! ♫

Joined: 07 Mar 2004 Posts: 1352
|
Posted: Sat Jul 29, 2006 5:02 pm Post subject: |
|
|
Let's say I have five of the same npc lined up horizontally. If I use npcatspot to identify which npc is stepped on, will it save the id of that specific npc or the npc ID shared by all of the npcs?
ex) The third placed npc is run over. Will this cause the first placed npc with that ID to be the victim of the script? |
|
Back to top |
|
 |
Mike Caron Technomancer

Joined: 26 Jul 2003 Posts: 889 Location: Why do you keep asking?
|
Posted: Sat Jul 29, 2006 6:02 pm Post subject: |
|
|
Any command that deals with NPCs will return an NPC reference (the notable exception being, of course, NPC ID()). This includes NPC at spot(). _________________ I stand corrected. No rivers ran blood today. At least, none that were caused by us.
Final Fantasy Q
OHR Developer BLOG
Official OHRRPGCE Wiki and FAQ |
|
Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|