how do I set hero position relative to npc?

Ask and answer questions about making games and related topics. Unrelated topics go in that other forum.

Moderators: marionline, SDHawk

Post Reply
User avatar
marionline
Metal Slime
Posts: 673
Joined: Sat Feb 26, 2011 9:23 pm

how do I set hero position relative to npc?

Post by marionline »

Hello,
I want to place the 4 heros around an NPC/ set the heros position relative to an NPC.
The script shall be run by several npcs. So I want to use the NPCs ID Number script argument to hand the NPC's ID to the script.

Some assumptions I made:
The x position of the NPC is recived by the script with NPC X (id), right?
The datatype of an NPC's x position is a number? Why can't I do "set hero position (0, NPC X (id)-1, NPC Y (id))?"
I am told I'd give 4 arguments where 3 are required. I do not see how/why I hand in 4 arguments. :???:

No knowing what to do, I tried to work around with variables. But it dosen't work either:

Code: Select all

plotscript, use_shrine, id, begin,
# id = id of npc that called script
    showtextbox(122)
    wait for textbox
    alter NPC (id,NPCstat:picture,113)
    wait(16)
    alter NPC (id,NPCstat:picture,114)
    wait(16)
    alter NPC (id,NPCstat:picture,115)
    wait(16)
    alter NPC (id,NPCstat:picture,116)
    wait(16)
    alter NPC (id,NPCstat:picture,117)
    wait(16)
    alter NPC (id,NPCstat:picture,112)
    wait(16)
    use shop (3)
    fade screen out
    
    variable (hero_x, hero_y, hero1_x, hero1_y, hero2_x, hero2_y, hero3_x, hero3_y) 
    hero_x := NPC X (id)-1
    hero_y := NPC Y (id)
    set hero position (0, hero_x, hero_y)
    
    hero1_x := NPC X (id)
    hero1_y := NPC Y (id)-1
    set hero position (1, hero1_x, hero1_y)
    
    hero2_x := NPC X (id)+1
    hero2_y := NPC Y (id)
    set hero position (2, hero2_x, hero2_y)
    
    hero3_x := NPC X (id)+1
    hero3_y := NPC Y (id)
    set hero position (3, hero3_x, hero3_y)

    fade screen in
    wait(32)
end
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7660
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

If this is a script triggered by using the npc, then the script will receive two arguments. The first is the "Argument" defined in the NPC editor.

The second is an NPC reference.

Code: Select all

plotscript, use_shrine, unused arg, ref, begin
    variable(id)
    id := NPC id(ref)
Other than that, your script looks good. You do want to make sure to use the -- operator for subtraction

Code: Select all

hero_x := NPC X (id)--1
Also, your script will only work correctly if there is only one copy of each shrine NPC on the map. Rewriting it to work with multiple copies is possible, but making the animation work for only one copy of the NPC might be more work than you want to bother with.
User avatar
marionline
Metal Slime
Posts: 673
Joined: Sat Feb 26, 2011 9:23 pm

Post by marionline »

Code: Select all

 hero_x := NPC X (id)--1
Thanks a lot! :D
It was the double minus symbol, that was causeing the trouble for me.

Oh, and the script also works without the 'unused arg' argument. (<- Edit: It seems that is only 1 NPC using the script.
On the 2nd Map the script was behaving diffrently.)
Last edited by marionline on Thu Dec 29, 2016 9:40 pm, edited 1 time in total.
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7660
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

marionline wrote:Oh, and the script also works without the 'unused arg' argument.
Did you manually type the NPC id number into each NPC's "Script Argument" in the NPC editor?
User avatar
marionline
Metal Slime
Posts: 673
Joined: Sat Feb 26, 2011 9:23 pm

Post by marionline »

Yes, I typed it.
(Ah, and on the 2nd map I forgot it...)
Post Reply