ID:148025
 
im having problems with my challenge verb, mainly just 2 things with it
Challenge(var/mob/PC/M as mob in world)
set category = "Battle"
if(istype(M,/mob/PC))
if(arena == 0)
arena = 1
var/challenge = input(M,"[usr] has challenged you to one-on-one combat. Do you accept?") in list("Yes","No")
if(challenge == "Yes")
usr << "[M] has accepted your challenge"
M << "You have accepted [usr]'s challenge"
M.OLDx = M.x
M.OLDy = M.y
M.OLDz = M.z
usr.OLDx = usr.x
usr.OLDy = usr.y
usr.OLDz = usr.z
M.loc = locate(/area/pvp2)
usr.loc = locate(/area/pvp1)
spawn(1)
challengetimer()
if(M.HP <= 0)
world << "[M] has been defeated by [usr]"
usr.loc = locate(usr.OLDx,usr.OLDy,usr.OLDz)
if(usr.HP <= 0)
world << "[usr] has been defeated by [M]"
M.loc = locate(M.OLDx,M.OLDy,M.OLDz)
arena = 0
if(challenge == "No")
usr << "[M] has declined your challenge"
M << "You have declined [usr]'s challenge"
arena = 0
else
usr << "You cant challenge [M]"

the first problem is that when a person is killed, the alive person isnt transported back to their original location. Also, i know that the
if(usr.HP <=0)
isnt right, and i wanted to make a proc on how to check the persons hp, but i dont know what it would need to include
You'd need to make a loop.

What I would do is make a few seperate procs, nothing is worse (in my opinion) than trying to do everything from the verb. You'll need, at the very least, a loop that checks the HP of the combatants, like so:

proc/combat(mob/Attacker, mob/Defender)
while(Attacker.hp>0 && Defender.hp>0)
spawn() //Spawn here to avoid infinite recursion
//put fighting functionality here
if(Attacker.hp>0)
world<<"[Attacker] defeated [Defender]"
//put transport coding here
else
world<<"[Defender] defeated [Attacker]"
//put transport coding here


The above snippet is a proc that takes the arguments of Attacker and Defender (the two mobs fighting) and loops through combat until one of their HP totals falls to 0 or below. It then displays a message to the world telling of victory depending on who has HP left. After the message is given, it transports the victor to wherever you need them (insert your own code for that). You can modify it as needed to transport both the victor and the defeated if you don't take care of that in a death proc.

That's a basic outline of a proc you might use. It's probably not what you need exactly, but it should spark some ideas. Good luck :)
In response to sapphiremagus
the thing is, i want real time combat, so would i just have to leave the spawn part out?
In response to Lazyboy
Actually, I'd leave it in. Just omit the combat part. And, in this case, I'd use spawn(1). Since the loop condition is that both combatants have HP greater than 0, if either one dies it ends. As soon as that happens, the transport is done and the message is given.
In response to sapphiremagus
i modified that code and i got a problem though can u help? I have...

mob/PC/verb/Challenge(mob/M in world)
set category = "Communication"
if(istype(M,/mob/PC))
if(arena == 0)
var/challenge = input(M,"[usr] has challenged you to one-on-one combat. Do you accept?") in list("Yes","No")
if(challenge == "Yes")
usr << "[M] has accepted your challenge"
M << "You have accepted [usr]'s challenge"
M.loc = locate(18,15,11)
usr.loc = locate(9,15,11)
arena = 1
combat()
else
usr << "[M] has rejected your challenge! What a wuss!"
else
usr << "Arena is in use already!"

proc/combat(mob/Attacker, mob/Defender)
while(Attacker.SP>0 && Defender.SP>0)
spawn() //Spawn here to avoid infinite recursion
if(Attacker.SP > 0)
world<<"[Attacker] defeated [Defender]"
Attacker.loc = locate(3,3,1)
else
world<<"[Defender] defeated [Attacker]"
Defender.loc = locate(3,3,1)



when i compile i get 1 error it says...

error:mob:undefined var

and wen i double click on that it highlights...

if(Attacker.SP > 0)
In response to Coolchris
Dunno why you're getting that error, but try this:

Change
proc/combat(mob/Attacker, mob/Defender)

to
proc/combat(var/mob/Attacker, var/mob/Defender)


Also, even without that error, the system won't work.
 if(challenge == "Yes")
usr << "[M] has accepted your challenge"
M << "You have accepted [usr]'s challenge"
M.loc = locate(18,15,11)
usr.loc = locate(9,15,11)
arena = 1
combat() //<----- HERE


combat() will not do anything. You want to use combat(usr,M).