ID:144797
 
Code:
example of attack list for a mob.
list/attacks  = list(/mob/proc/attack,/mob/proc/splash,/mob/proc/splash)


Code:
combat system.
mob/proc/combat(mob/M)

if(M.hp <= 0)
src.death(M)
return

var/turn = pick(M.attacks)
spawn() call(M,turn)(src)


Problem description:
Basically I want the monsters in this mud to randomly choose their attacks. And every single attack, including attack are a proc. IE mob/proc/attack() and mob/proc/splash().

What I was going for is every mob has the attacks they can use in their attacks list. And then in the combat proc, it would randomly choose one of those attacks in the list and then calls it.

Won't work though. Compiles just fine and the game runs perfect, except that all the mobs ever do is call attack() and nothing else.

Edit:

Would:

spawn() call(M, pick(M.attacks))(src)


work the same way or would that be incorrect?

Edit 2:

With some suggestions from Jon88 I changed the lists to like this:

list/attacks  = list("attack","splash")


And it works just fine, except for some reason it simply picks attack every single time. It has yet out of like a few 100 cycles to pick anything then attack.
when using call() with a reference to something, always refer to the name of the call.

pick() shouldn't do that, you probably were just lucky.
In response to DivineO'peanut
Oh this was weird, I didn't know list worked like this. I had defined the attack list as a general var under mob/var and then defined it for every mob differently.

Just being curious I added the splash proc to the attack list under the mob/var instead of just for the monsters that had it, and it worked.

So then I just made it so when the mobs are created that they would add splash to their list with New() and removed splash from the general mob/var again and it still worked and now it seems to be working flawlessly despite being a little clunky.