ID:172456
 
How can I make it so that it randomly picks a mob from the world? Like anything, NPC, Player, anything, just completely randomly. I want to make a funny joke system kinda thing in my game, just for fun, and I want it to randomly pick a mob in the game lets say every 30 seconds to say,
Hi!, Hello!, or What's Up?
Any help?
This should help.
mob
verb
Pogga()
src << "[RandomMob(src)] stole your cheese!"

proc
RandomMob(var/mob/caller)
var/list/mobs = new
for(var/mob/M in world)
if(M != caller) mobs += M // I only added the "if(M != caller)" line because I dunno if you want the person calling the proc to be included.
var/randommob = pick(mobs)
return randommob
In response to Enigmaster2002
Well I dont want it to be a proc thats called by the player, I want it to be a proc that initializes itself every X ammount of seconds.
In response to Metroid
Okie okie. Just a teeny bit of editing and...
proc
RandomMob()
var/list/mobs = new
for(var/mob/M in world)
mobs += M
var/randommob = pick(mobs)
world << "[randommob] lost his cheese!" // Whatever you want it to do goes here, if you wanna store it in a variable for later use, or you want it to fire off text immediately, etc.
spawn(600) RandomMob() // Replace 600 with however long you want it to wait in ticks, but I imagine you knew that already.
In response to Enigmaster2002
can I make a rand from like 1 to 50 and if its 1 say msg 1 and if its 2 say msg 2 etc? That will work, right?
In response to Metroid
The best way to do that would be to use another list.
var/list/sayings = list("lost his cheese!","lost his mind!","lost his discombobulator!")
proc
RandomMob()
var/list/mobs = new
for(var/mob/M in world)
mobs += M
var/randommob = pick(mobs)
var/randommsg = pick(sayings)
world << "[randommob] [randommsg]"
spawn(600) RandomMob()
In response to Enigmaster2002
var/sayings = list("worldsays: You know, there is always a chance that I could pop up, and your head could go flying...oh wait, you don't have a head anyway, never mind.","worldsays: This game diserves a lot of gratitude, but you people are too foolish to know it.","worldsays: When I jump, your computer screen will crack. *A crack is heard in the distance* Oh wait, that was my head...")

proc
RandomMob()
var/list/mobs = new
for(var/mob/M in world)
mobs += M
var/randommob = pick(mobs)
var/randommsg = pick(sayings)
world << "[randommob] [randommsg]"
spawn(10)
RandomMob()


To see if it would work, i made it at 10 and nothing ever poped, up. Any help?
In response to Metroid
Eheh, I forgot a vital part.
world
New()
..()
RandomMob()
In response to Enigmaster2002
LoL thanks.