ID:178185
 
I need an example of a verb that will give all players that click the Challenge() verb an Attack verb , but only when the user accepts the challenge. I am not sure how to do this
Branks wrote:
I need an example of a verb that will give all players that click the Challenge() verb an Attack verb , but only when the user accepts the challenge. I am not sure how to do this

Well, to get started, you'd need to go over the challenge process. I guess it would be like this:

  • Player 1 offers challenge to player 2.
  • Player 2 accepts or declines
  • If challenge is accepted, both players are given verbs.

    Because input() and alert() would get in the way of anyone who was challenged, I'd try a different approach, using links and/or verbs.
mob
var/list/challenged
var/mob/challenging

proc/ExtendChallenge(mob/M)
if(challenging)
src << "You can't challenge [M] until you're finished with [challenging]."
return
if(!challenged) challenged=list()
if(M in challenged) return
challenged+=M
spawn(600) ChallengeTimeout(M)
M << "[src] has challenged you. You have one minute to <A HREF='?ch_accept=\ref[src]'>accept</A> or <A HREF='?ch_decline=\ref[src]'>decline</A>."
src << "You challenge [M]."

proc/ChallengeTimeout(mob/M)
if(!challenged || !(M in challenged)) return
challenged-=M
challenged-=null // just prune accidental null entries

// called by M when M excepts challenge
proc/AcceptChallenge(mob/M)
if(challenging)
M << "[challenging] has accepted the challenge instead."
return
if(!challenged || !(M in challenged))
M << "The challenge has been withdrawn."
return
client.verbs+=/mob/proc/Attack
M.client.verbs+=/mob/proc/Attack
challenging=M
M.challenging=src
challenged=null
M.challenged=null

proc/DeclineChallenge(mob/M)
M << "You decline the challenge from [src]."
src << "[M] declines your challenge."
ChallengeTimeout(M) // remove it from the list

Now the rest of the dirty work: You need a verb to call the ExtendChallenge() proc, and client.Topic() to handle the links to accept it or decline. Verbs could be used for the latter too, but to do that you'll need a separate list keeping track of who has challenged you.

Lummox JR