ID:143967
 
Code:
var
rYes//Yes voting

rNo//no voting


mob
var
voted = 0//You'll see what its for.
rebootreason//You will see.

verb
Request_Reboot()
if(usr.voted==1)//If they voted recently...
usr << "<font color = red>Please wait atleast 3 minutes between votes."
if(usr.voted==0)//If it has been a minute.
usr.voted = 1
usr.rebootreason = input("Why are you rebooting?","Reason","[usr.rebootreason]")//The reboot reason.
if(length(usr.rebootreason)>300)//If it is over 300 letters...
usr << "That reason is to long. You still need to wait a 3 minutes to vote again."
return
else
world << "<b><font color = green>[usr.key] has requested a reboot because '</b><i>[html_encode(usr.rebootreason)]</i>'<b><font color = green> You have 30 seconds to input your vote.</b></font>"//Notice the html_encode? Protects from spam.
for(var/mob/M in world)//For a mob..
// if(!M.client)
// return
// else
M << "Testing"
M.rvote()//Calls the proc.
sleep(300)//30 seconds
if(rYes==rNo)//If they are equal...
world << "<b><font color = green>There has been a tie. Time to randomize!"
var/maybe = rand(1,2)
if(maybe==1)
world << "<b><font color = green>And reboot it is!"
world.rebootv()
return
else
world << "<b><font color = red>No reboot wins!"
return
if(rYes>rNo)//If Yes wins
world << "<b><font color = green>Reboot has won! Here is what was voted.<br></b><font color = blue>Yes = [rYes]<br>No = [rNo]"
world.rebootv()
if(rNo>rYes)//If no wins.
world << "<b><font color = green>Reboot has lost! Here is what was voted.<br></b><font color = blue>Yes = [rYes]<br>No = [rNo]"
rNo = 0
rYes = 0
return
sleep(1800)//3 minute delay.
usr.voted = 0
mob
proc
rvote(mob/M)//Everything in this proc is obvious.
src << "<font color = red>Debug: You should get this message 1 time."
switch(alert("Would you like a reboot?","Reboot voting.","Yes","No"))
if("Yes")
rYes+=1
return
if("No")
rNo+=1
return


Problem description:

Alright, basically, I want to send that rvote proc to all mobs. Well, if there are 3 mobs, it will send it to the mob 3 times. I do not know why. The odd thing is, it only sends the message "Testing" 1 time to me...Help me please.


EDIT: RESOLVED. The alert went to usr!
PROBLEM! Since you called rvote(M) withotu anythign before if (usr.,src.,m., etc), the proc was automatically directed as src!
rvote(M)//Calls the proc.
rvote(M) "is the same as" src.rvote(M)

SO... the fix:
M.rvote(M)

Hey, on your "rvote" proc, you have two returns!
mob
proc
rvote(mob/M)//Everything in this proc is obvious.
src << "<font color = red>Debug: You should get this message 1 time."
switch(alert("Would you like a reboot?","Reboot voting.","Yes","No"))
if("Yes")
rYes+=1
return // THIS DELETES THE FOR() EFEFCT!
if("No")
rNo+=1
return // SAME HERE!

*EDIT*
[May 13 19:41] Jon88: It's not the problem.
[May 13 19:41] Jon88: The correct response is "No pur usr in proc. Ungh."
[May 13 19:42] Kunark: So he doesn't understand "No put usr in proc. Ungh."
[May 13 19:42] Jon88: No, it's one of the "It's a problem now."
<dm>
mob
proc
Vote()
if(alert(src,"Reboot","Vote To Reboot","Yes","No")=="Yes")
return 1
return 0
mob/verb/Reboot()
unique = new
if(!canvote) return
canvote = 0
var/neededvotes
var/totalvotes
for(var/client/C)
if(C.address in unique) continue
unique.Add(C.address)
neededvotes++
totalvotes += C.mob.Vote()
neededvotes >>=1
if(totalvotes > neededvotes)
world.Reboot()
else
world << "We need [neededvotes - totalvotes] more votes to reboot"
world << "You can reboot in [votetime] minutes"
var/const/votetime = 20 // 20 minutes
var/canvote = 1
var/list/unique
proc
VoteTimer()
sleep(votetime*600)
canvote = 1
In response to Gooseheaded (#1)
The M.rvote did nothing different, except not give me the debug message each time.