ID:2201048
 
Code:
//This is a verb that calls the proc to test it... it works perfectly when //called

mob/NPC/verb/Talk()
set src in view(3)
Conversation()

//This is the proc I want to work.

mob/NPC/proc/Conversation()
set src in view(5)
if (ckey = 0)
var/Adlib
while(src in view())
RandConvo()
Adlib = MasterOption
view() << "[src] : [Adlib]"
sleep (100)



mob/NPC/var
adlib1
adlib2
adlib3

var
Option1
Option2
Option3
MasterOption


mob/NPC/proc/RandConvo()
Option1 = rand(1,100)
Option2 = rand(1,100)
Option3 = rand(1,100)
if (Option1 > Option2 && Option1 > Option3)
MasterOption = adlib1
else if (Option2 > Option1 && Option2 > Option3)
MasterOption = adlib2
else if (Option3 > Option1 && Option3 > Option2)
MasterOption = adlib3

//This was my guess on how to get the proc to work by itself... however,
//this didn't work


mob/NPC/proc/NPCNear()
if(src in view(5))
Conversation()
else return 1

// And this is one of my NPC along with his adlibs.

mob/NPC
DrugDealer
icon = 'DrugDealer.dmi'
adlib1 = "Damn, business is good!"
adlib2 = "These streets don't pay me enough."
adlib3 = "Not a bad day to be hustlin"


Problem description: I made up a proc to allow NPC's to say 3 random sentences every 45 secs if I'm nearby... So far it works if I call it by a verb, but I don't know how to call a proc without a verb (so it's always active)


You'd either want to make it a loop, or more ideally, trigger it within Move() when a player moves into view of the NPC.

mob/player/Move() // Assuming your players are their own type.
. = ..()
var/mob/NPC/found_npc = locate() in view(src)
if(found_npc)
if(!found_npc.conversating) found_npc.Conversation()


Now you'd want to add a 'conversating' variable to the NPC that gets set to 1 when the loop is active and 0 when it's become inactive. That'll prevent the loop from being activated multiple times.
mob/proc/Girltalk()
if(src.player)
for(var/mob/Npc/M in view())
if(M in get_step(5,src.dir))
spawn(20)
switch(rand(1,4))
if(1) view()<<("Stole his girlfriend and put her in a bag!")
if(2) view()<<("I got bread come buy some!")
if(4) view()<<("What you buying.....")


Don't know if it might work for yah just trying something :)