Post new topic    
Slime
Send private message
Getting Npcs with different ID to do the same action at once 
 PostMon Aug 12, 2013 10:14 am
Send private message Reply with quote
Hey so I'm stuck here again. I want to make all copies of 4 npc's with different ID's make the same action continously at the same time, but I'm not getting there!

Code:
while (current map == 3)
do (set npc direction(all,north)
wait (17)
set npc direction(all,south)
wait (17)
   )


I tried with NPC arguments, but I don't want to use them, as the npc's should be still able to to be activated and respond with a text box when the hero uses them. I thought there might be a way of storing several npc's into a variable (???) or some other trick that I'm not aware of, but it didn't work out so far.
I tried doing a workaround with the "walk in place" option, but then the animation is going way too fast that way...
Liquid Metal King Slime
Send private message
Re: Getting Npcs with different ID to do the same action at 
 PostMon Aug 12, 2013 2:37 pm
Send private message Reply with quote
They all have different ID numbers?

What you are asking for about putting more than one NPC ID into a single variable is called an "Array" but plotscripting does not support those (yet)

This example pretends that you are using ID numbers 5, 7, 12, and 23

Code:

while (current map == 3) do(
  set npc direction(5, north)
  set npc direction(7, north)
  set npc direction(12, north)
  set npc direction(23, north)
  wait(17)
  set npc direction(5, south)
  set npc direction(7, south)
  set npc direction(12, south)
  set npc direction(23, south)
  wait(17)
)



If all your NPC ID numbers happen to be in-order, you can use a "for" loop. Suppose that your NPC ID numbers are 6,7,8,9

Code:

variable(i)
while (current map == 3) do(
  for(i, 6, 9) do(
    set npc direction(i, north)
  )
  wait(17)
  for(i, 6, 9) do(
    set npc direction(i, south)
  )
  wait(17)
)



You notice that this example is not really and shorter, and it is a bit harder to read. This method might not be a good idea unless you have a very large number of NPCs.
Red Slime
Send private message
 
 PostMon Aug 12, 2013 3:05 pm
Send private message Reply with quote
Quote:
Hey so I'm stuck here again. I want to make all copies of 4 npc's with different ID's make the same action continously at the same time, but I'm not getting there!


I am guessing you want to have something like a group of guards that march back and forth (Wizard of Oz-style)? Would it be possible to do with a standard NPC movetype (e.g. "Pace")? I've never actually used that movetype myself, but I would imagine that's what it does...

e: Also, if you don't like the movement speed, you can edit that with the move speed NPC stat (don't know if it affects walk-in-place animation speed, though).
Metal King Slime
Send private message
 
 PostMon Aug 12, 2013 7:34 pm
Send private message Reply with quote
The speed of the walk in place animation really needs to be customisable (movement speed does not affect it). It would be an easy feature to add, but last time it came up we didn't agree on how it should work. A global setting? Per NPC type? Per walkabout set*?

*related to the plan for custom sprite animations
Liquid Metal King Slime
Send private message
 
 PostMon Aug 12, 2013 8:04 pm
Send private message Reply with quote
@TMC
I'd think it would be best suited as an option just below npc speed.
Npc Animation speed.
With default, then a couple slower and a couple faster options.
Metal King Slime
Send private message
 
 PostMon Aug 12, 2013 8:50 pm
Send private message Reply with quote
Yeah, I admit that makes perfect sense. I was just being difficult/idealistic in arguing that the animation speed should be a property of a sprite, not of an NPC. Come to think of it, that's wrong, for the same reason that different NPCs can have different movement speeds.
Slime
Send private message
 
 PostTue Aug 13, 2013 8:27 am
Send private message Reply with quote
^Not sure if that would only solve half the problem. In my case the "walk in place"-option would work since i just need two different walkabouts that need to change. But what if you'd need 4? Then something like "turn around continously" would be needed for the walktype. What I'd be personally love the most would be an "NPC animation pattern" just as you have for maptiles, where only left & right is possible from the walkabout editor (no down & up).
Slime
Send private message
Re: Getting Npcs with different ID to do the same action at 
 PostTue Aug 13, 2013 8:41 am
Send private message Reply with quote
Bob the Hamster wrote:
They all have different ID numbers?

What you are asking for about putting more than one NPC ID into a single variable is called an "Array" but plotscripting does not support those (yet)

This example pretends that you are using ID numbers 5, 7, 12, and 23

Code:

while (current map == 3) do(
  set npc direction(5, north)
  set npc direction(7, north)
  set npc direction(12, north)
  set npc direction(23, north)
  wait(17)
  set npc direction(5, south)
  set npc direction(7, south)
  set npc direction(12, south)
  set npc direction(23, south)
  wait(17)
)


Damn, and I thought I had tried it this way and that it didn't work...must have been under time pressure. Works flawlessy, thanks!! Damn too early enthusiasm. So what if there are several copies, and i want them all to do this, without going via an activation script?
Metal King Slime
Send private message
 
 PostTue Aug 13, 2013 11:46 am
Send private message Reply with quote
Use NPC references to refer to individual NPCs. When you use an NPC type ID for commands like that, it refers to the first NPC with that type ID number.

Code:

variable (npc 1, npc 2)
npc 1 := npc reference (23, 0)  # first ID 23 npc
npc 2 := npc reference (23, 1)  # second

while (current map == 3) do(
  set npc direction(5, north)
  set npc direction(7, north)
  set npc direction(12, north)
  set npc direction(npc 1, north)
  set npc direction(npc 2, north)
  wait(17)
  set npc direction(5, south)
  set npc direction(7, south)
  set npc direction(12, south)
  set npc direction(npc 1, south)
  set npc direction(npc 2, south)
  wait(17)
)


Quote:
^Not sure if that would only solve half the problem. In my case the "walk in place"-option would work since i just need two different walkabouts that need to change. But what if you'd need 4? Then something like "turn around continously" would be needed for the walktype. What I'd be personally love the most would be an "NPC animation pattern" just as you have for maptiles, where only left & right is possible from the walkabout editor (no down & up).


Tip: you can create a 4 frame animation by surrounding an NPC with walls and setting it to Always Turn Right. It'll loop through the four directions. But the animation speed is again fixed (and fast)

As I hinted a few posts up, creating arbitrary NPC animations is planned. I was really hoping that get that in the next release, but since we haven't started yet it's looking very unlikely.
Slime
Send private message
 
 PostTue Aug 13, 2013 5:00 pm
Send private message Reply with quote
Thanks TMC, but I am aware of NPC references. What I wanted was that the command would apply to several, or at best ALL copies, not only a single one. That is what I wanted from the begin. Angel

Quote:

Tip: you can create a 4 frame animation by surrounding an NPC with walls and setting it to Always Turn Right. It'll loop through the four directions. But the animation speed is again fixed (and fast)

As I hinted a few posts up, creating arbitrary NPC animations is planned. I was really hoping that get that in the next release, but since we haven't started yet it's looking very unlikely.

Thanks for the tip and looking forward to see the feature!
Liquid Metal King Slime
Send private message
 
 PostTue Aug 13, 2013 5:14 pm
Send private message Reply with quote
Here is how to do an action on every copy of NPC ID 5

Code:

variable(i, ref)
for(i, 0, NPC copy count(5) -- 1) do(
  ref := NPC reference(5, i)
  set NPC direction(ref, south)
)
wait(15)
for(i, 0, NPC copy count(5) -- 1) do(
  ref := NPC reference(5, i)
  set NPC direction(ref, north)
)
Display posts from previous: