 |
Castle Paradox
|
View previous topic :: View next topic |
Author |
Message |
Shadowiii It's been real.

Joined: 14 Feb 2003 Posts: 2460
|
Posted: Wed Sep 01, 2004 4:33 pm Post subject: Recognizing Step-on NPCs in Pixel-Based Movement |
|
|
...yeah.
How might I go about this? I want it so when the hero (who has pixel based movement) walks on an npc the npc triggers.
I had something like this (for every time the npc moved)
Code: | if (key is pressed(key:UP)) then
(
put hero (me,heropixelX(me),heropixelY(me)--2) #PUTS HERO UP 2 PIXELS
#The following loop determines if you are in pixel range of an item npc. If you are, the npc will activate, and you can
#use the item or whatever.
#The item npcs are 5-15 (making 10 total)
for (n, 0, 10) do
(
if ((heropixelx(me) -- npcpixelx(npcnumber) <= 20), and, (heropixelx(me) -- npcpixelx(npcnumber) >= 0)) then
(
if ((heropixely(me) -- npcpixely(npcnumber) <= 20), and, (heropixely(me) -- npcpixely(npcnumber) >= 0)) then
(
use npc(npcnumber)
)
)
#Move to the next npc
npcnumber := npcnumber + 1
)
) |
But I just get script errors. Where am I going wrong? It seems so simple... _________________ But enough talk, have at you! |
|
Back to top |
|
 |
Moogle1 Scourge of the Seas Halloween 2006 Creativity Winner


Joined: 15 Jul 2004 Posts: 3377 Location: Seattle, WA
|
Posted: Wed Sep 01, 2004 4:42 pm Post subject: |
|
|
From the SG3 code:
Code: | npc:=(npcatspot((heropixelx+2)/20,heropixely/20)) #check for NPC collision
if (getnpcid(npc)==0) then
(
npc:=(npcatspot((heropixelx+2)/20,heropixely/20+1))
if (getnpcid(npc)==0) then
(
npc:=(npcatspot((heropixelx+18)/20,heropixely/20+1))
if (getnpcid(npc)==0) then
(
npc:=(npcatspot((heropixelx+18)/20,heropixely/20))
)
)
) |
This could be a little more precise, but it works.
(Edit) At the end of this script, the variable "npc" will be the NPC reference of an NPC at the hero's location. You can "usenpc" on it.
(Edit) If there is no NPC, npc will be 0. _________________
|
|
Back to top |
|
 |
Uncommon His legend will never die

Joined: 10 Mar 2003 Posts: 2503
|
Posted: Wed Sep 01, 2004 4:59 pm Post subject: |
|
|
Moogle1 wrote: | If there is no NPC, npc will be 0. |
Note that it's best to use a bit of code to make up for this, Shadow.
Code: | if (npc <> 0)
then (usenpc (npc)) |
Yeah, very, very simple, but I just wsaid it to make sure (and for people that are reading for the sake of learning how to do the same thing and might not quite think of it). |
|
Back to top |
|
 |
Shadowiii It's been real.

Joined: 14 Feb 2003 Posts: 2460
|
Posted: Wed Sep 01, 2004 5:00 pm Post subject: |
|
|
I take it this is for collision (that is, you run into the npc. I'm horrid at reading other people's code, so thats what I figured).
I need it to activate when you step on the npc, which means when the hero is standing on the general vacinity of the npc. Would this script do this?
(sorry if I'm stupid...I just got back from six full-length courses. 18 credits of classes in one day := ugh)
Edit again: If it helps (for reference), this is basically for a point and click style aspect of the game.
Egads, I need to explain myself more in my posts. _________________ But enough talk, have at you!
Last edited by Shadowiii on Wed Sep 01, 2004 5:04 pm; edited 1 time in total |
|
Back to top |
|
 |
Moogle1 Scourge of the Seas Halloween 2006 Creativity Winner


Joined: 15 Jul 2004 Posts: 3377 Location: Seattle, WA
|
Posted: Wed Sep 01, 2004 5:04 pm Post subject: |
|
|
If the hero is partially or wholly on top of the NPC, it will return that NPC's reference, which can be activated with Unc's little code snippet. If you want to make the hero have to stand more squarely on the NPC, that's not hard, but does require a little modification. _________________
|
|
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
|