ID:179126
 
I finially got the mobs to move around randomly, but now I need for them to interact with the users on their own . . . In particular, I need for the mobs to do things when people get within X tiles of them. How do I call a proc automatically once certain parameters are met? 'if' statements don't seem to work on their own. Thanks again for your help.
Gakumerasara wrote:
I finially got the mobs to move around randomly, but now I need for them to interact with the users on their own . . . In particular, I need for the mobs to do things when people get within X tiles of them. How do I call a proc automatically once certain parameters are met? 'if' statements don't seem to work on their own. Thanks again for your help.

It sounds like you are doing things in the... 'shoot first, ask questions later' method. What you need to do is 'look before you leap'. This will make your code more efficient too.

Have the mob do all its fact finding, using oview to fill in temp vars in the mobs code. once you have gathered these, you can use your if statements to determine what should be the next action(move, attack, etc).
There's an example of attacking mobs in this code.
In response to Nadrew
I can't open project files from online b/c I'm blocked from port 6001 by a firewall. :( Even if I download them, I can't open them correctly (even as Guest). That's why I have to ask so many trivial questions.
In response to ThreeFingerPete
'If' statements only work when within procs or verbs, right? My problem is that I'm trying to do it backwards (if this, then proc). The only idea I had was to call the second proc in the New proc for the mob and then set a for loop to always test for the 'if' parameters. This of course froze my game. Could you give me an example of how to go about doing this?
In response to Gakumerasara
Put the if statements into the mobs' walking procs... After each step...they should check for enemy mobs in the specified area and if one if found...call the attack proc... If not...go on with walking...
In response to Gakumerasara
Gakumerasara wrote:
'If' statements only work when within procs or verbs, right? My problem is that I'm trying to do it backwards (if this, then proc). The only idea I had was to call the second proc in the New proc for the mob and then set a for loop to always test for the 'if' parameters. This of course froze my game. Could you give me an example of how to go about doing this?

What you've basically got right now is the classic problem of polling vs. interrupts. In BYOND, polling will be easier to implement, at least at first.

Your instinct to put the if() in a for loop isn't a bad one, since that's how you would do polling; the part that probably froze your game, I would guess, is that you didn't put in a sleep() call. (You'd also need to spawn off the for loop, so the calling proc returns.)

For example:
obj/monster
New()
..()
spawn()
for() // infinite loop
if(LookForTargets()) // if this returns 1, go again ASAP
sleep() // let other monsters do their polling
continue // skip the usual delay
sleep(3) // look again in 0.3 seconds

Of course, if all your monsters were to poll like this at the same time, your game could go in fits and starts if you had too many of them. One way to mix things up a little would be to sleep for a random time (like rand(2,6) instead of 3), so monsters end up staggering their polling schedules a bit.

Lummox JR
In response to Lummox JR
That's exactly what I needed. Thanks :)