ID:140581
 
Code:
mob
Buster
verb
Buster_Call()
set category = "Skills"
if(bustercall == 1)
usr << output("There is already a bustercall ongoing!","SM")
return
else
world << output("<font color= blue> {[usr.rank]} [usr] has started a Buster Call!","SM")
bustercall = 1
usr.verbs += typesof(/mob/bustend/verb)
for(var/mob/M in world)
if(M.class == "Marine")
if(M.rank == "Vice Admiral")
switch(input("[usr] has invited you to a Buster Call!","Invitation") in list("Accept","Decline"))
if("Accept")
if(buster ==5)
M << output("You are too late! all spots have been filled!","SM")
return
else
M.loc = locate(usr.x,usr.y+1,usr.z)
buster +=1
return
if("Decline")
return
if(M.rank == "Admiral")
switch(input("[usr] has invited you to a Buster Call!","Invitation") in list("Accept","Decline"))
if("Accept")
if(buster ==5)
M << output("You are too late! all spots have been filled!","SM")
return
else
M.loc = locate(usr.x,usr.y+1,usr.z)
buster +=1
return
if("Decline")
return
if(M.rank == "Fleet Admiral")
switch(input("[usr] has invited you to a Buster Call!","Invitation") in list("Accept","Decline"))
if("Accept")
if(buster ==5)
M << output("You are too late! all spots have been filled!","SM")
return
else
M.loc = locate(usr.x,usr.y+1,usr.z)
buster +=1
return
if("Decline")
return
else
return
else
return


Problem description:
Well what i am trying to achieve is for the verb to send out invitation to the group of people in the world with the ranks specifyed.. but no one recieves them.. reasons to why?
This isn't related to the problem, but I immediately noticed is that you are unnecessarily copying the exact same bit of code three times: under each rank check; you can just write:
if(M.rank in list("Vice Admiral","Admiral","Fleet Admiral"))
// do stuff

Now for the problem:
When I look at your input line, it appears the input is sent to the user of the verb for every mob/M in world.
You need to specify the first argument of the input() proc if you're sending an input pop-up to some one else, like so:
switch(input(M, "[usr] has invited you to a Buster Call!","Invitation") in list("Accept","Decline"))


And, you don't really need to use switch() for only two conditions; you can use a simple if followed by an else:
var/confirm = input(M, "[usr] has invited you to a Buster Call!","Invitation") in list("Accept","Decline")
if(confirm == "Accept")
// do stuff
else
// do the other stuff
Oh, and those "else return" should be replaced by "else continue", because you don't want the for() loop in your verb to break when just one mob shouldn't get an invite.

And you may want to change
"if(M.class == "Marine")"
to
"if(M.client && M.class == "Marine")"
Because you don't want to send invites to NPCs


Edit: Oh and you also need to remove those returns from your accept/descline choices, for the same reason as stated above
I decided to put a corrected code snippet here, but DO read my previous posts before putting this in your code.

I'm sure others will still find more things that could be improved, though

mob
Buster
verb
Buster_Call()
set category = "Skills"

if(bustercall)
usr << output("There is already a bustercall ongoing!","SM")

else
world << output("<font color=blue> {[usr.rank]} [usr] has started a Buster Call!</font>","SM")
bustercall = 1
usr.verbs += typesof(/mob/bustend/verb)

for(var/client/C)
var/mob/M = C.mob
if(!M) continue

spawn() // if you don't put this here, the input()/alert() will hold up the for() loop
if(M.class == "Marine" && M.rank in list("Vice Admiral","Admiral","Fleet Admiral"))
var/confirm = alert(M, "[usr] has invited you to a Buster Call!","Invitation","Accept","Decline")
// displays two buttons in stead of a list box with two items
if(confirm == "Accept")
if(buster >= 5)
M << output("You are too late! All spots have been filled!","SM")
else
M.loc = get_step(usr, NORTH) // same as locate(usr.x,usr.y+1,usr.z)
buster ++ // same as += 1


You will notice there are actually no more returns nor continues in the code, since they weren't really needed; no need to use continue at the end of an iteration
In response to Nielz
Note that the for() loop should also be replaced with:

for(var/client/C)
var/mob/M = C.mob
if(!M) continue
spawn()
//etc...


You are filtering out non-clients anyway (oh right, remove the if(M.client) as well), there's no reason to loop through mobs instead of clients.
In response to Nielz
I'd recommend using the 'datum version' of input by Nadrew[link].
Store them in a list, soon as you populated the five spots, loop, delete and Cut().
This way, you won't have to keep ugly inputs open for players only to tell them that they're too late anyway.
In response to Garthor
Exactly, post edited
In response to Schnitzelnagler
Narutostory's code doesn't rely on a timer for the input though; in stead it relies on a limited number of people who can click 'Accept'
In response to Schnitzelnagler
Well, I've modified Nadrew's Input proc to rely on a counter in stead of a timer:

var/list/inputs = list()

MyInput
proc
Input(caller, caption = "", title = "", default = "", list/optlist)
var/answer

if(optlist)
answer = input(caller,caption,title) as anything in optlist
else
answer = input(caller,caption,title,default)

return answer

mob
verb/TestInput()
var
MyInput/I = new()
input_id = rand(1,10000)

inputs[input_id] = 5

for(var/client/C)
spawn()
var/answer = I.Input(C.mob,"Hello!","Accept stuff?","Test",list("Accept","Decline"))
if(answer == "Accept")
inputs[input_id]--
// [do stuff]
else
// [do other stuff]

spawn()
while(inputs[input_id]) sleep(1)

inputs.Remove(input_id)
del(I)
In response to Nielz
I think you misunderstood me, party because I didn't express myself properly.

AlertDatum
proc
Alert(caller=usr,message="",title="")
. = alert(caller, message, title, "Accept", "Decline")

mob
Buster
var/list/alerts

proc
CleanAlerts()
for(var/AlertDatum/ad in alerts)
del ad
alerts.Cut()

verb
Buster_Call()
set category = "Skills"
if(bustercall)
usr << output("There is already a bustercall ongoing!","SM")
else
world << output("<font color=blue> {[usr.rank]} [usr] has started a Buster Call!</font>","SM")
bustercall = 1
verbs += typesof(/mob/bustend/verb)
for(var/client/c)
if(c.mob)
var/mob/m = c.mob
spawn()
if(M.class == "Marine" && M.rank in list("Vice Admiral","Admiral","Fleet Admiral"))
var/AlertDatum/a = new()
inputs += a
var/confirm = a.Alert(M, "[name] has invited you to a Buster Call!","Invitation")
if(confirm == "Accept")
if(buster >= 5)
CleanAlerts()
else
M.loc = get_step(usr, NORTH)
buster++