Here's the battle code that works:
mob/var/inpvp = 0
mob/verb/PvP(mob/M in get_step(usr,usr.dir))
var/prompt = input(M,"PvP [usr]?")in list("Yes","No")
if(M.inpvp == 0 && usr.inpvp == 0) switch(prompt)
if("No")
usr << "[M] declined."
if("Yes")
battlestart(usr,M)
else
usr << "BUG!"
M << "BUG!"
mob/proc/battlestart(mob/A as mob, mob/B as mob)
A.inpvp = 1
B.inpvp = 1
if(A.agility > B.agility)
battleprompt(A,B)
if(B.inpvp == 1 && A.inpvp == 1) battleprompt(B,A)
if(B.inpvp == 1 && A.inpvp == 1) battlestart(A,B)
if(B.agility > A.agility)
var/mob/C = B
B = A
A = C
battleprompt(B,A)
if(B.inpvp == 1 && A.inpvp == 1) battleprompt(A,B)
if(B.inpvp == 1 && A.inpvp == 1) battlestart(A,B)
if(A.agility == B.agility)
var/X = rand(1,2)
if(X == 1)
battleprompt(A,B)
if(B.inpvp == 1 && A.inpvp == 1) battleprompt(B,A)
if(B.inpvp == 1 && A.inpvp == 1) battlestart(A,B)
if(X == 2)
var/mob/C = B
B = A
A = C
battleprompt(B,A)
if(B.inpvp == 1 && A.inpvp == 1) battleprompt(A,B)
if(B.inpvp == 1 && A.inpvp == 1) battlestart(A,B)
mob/proc/battleprompt(mob/A as mob, mob/B as mob)
var/prompt = input(A,"Do what?")in list("Attack", "Run")
switch(prompt)
if("Attack")
var/damage = round((A.attack-B.defense+rand(-2,2))/2)
view() << "[A] Attacks!"
sleep(10)
if(damage >= 0)
view() << "[B] is struck for [damage] damage!"
B.HP -= damage
B.PCDeath()
if(B.inpvp == 0) A.inpvp = 0
if(A.inpvp == 0) B.inpvp = 0
else
view() << "[A]'s attack fails to damage [B]!"
sleep(10)
if("Run")
view() << "[A] surrenders!"
A.HP = 0
if(!B.key) del(B)
A.PCDeath()
if(B.inpvp == 0) A.inpvp = 0
if(A.inpvp == 0) B.inpvp = 0
Here's the evil NPC one:
mob/NPC/Test
icon = 'monsters.dmi'
icon_state = "redslime"
density = 1
skilllist = list("Attack")
mob/var/skilllist = list()
mob/verb/Fight_NPC()
if(usr.x == 500)
usr.x-=1
var/mob/M = new /mob/NPC/Test(usr.loc)
M.attack = round(usr.attack+rand((usr.attack/10),-1*(usr.attack/10)))
M.defense = round(usr.defense+rand((usr.defense/10),-1*(usr.defense/10)))
M.agility = round(usr.agility+rand((usr.agility/10),-1*(usr.agility/10)))
M.HP = round(usr.Max_HP+rand((usr.Max_HP/10),-1*(usr.Max_HP/10)))
if(usr.level >= 15)
M.skilllist += "Attack"
M.skilllist += "Attack"
M.skilllist += "Attack"
M.skilllist += "Attack"
M.skilllist += "Heal"
M.exp_give = usr.level+rand(-1,usr.level)
M.x+=1
M.dir = WEST
usr.dir = EAST
monsterbattle(usr,M)
mob/proc/monsterbattle(mob/A as mob, mob/B as mob)
if(!A.key && B.key)
usr << "Battle ended due to bug"
del(B)
else
A.inpvp = 1
if(A.agility > B.agility)
A.battleprompt(A,B)
if(B.inpvp == 1 && A.inpvp == 1) B.npcbattleprompt(B,A)
if(B.inpvp == 1 && A.inpvp == 1) monsterbattle(A,B)
if(B.agility > A.agility)
var/mob/C = B
B = A
A = C
C = null
B.battleprompt(B,A)
if(B.inpvp == 1 && A.inpvp == 1) A.battleprompt(A,B)
if(B.inpvp == 1 && A.inpvp == 1) monsterbattle(A,B)
if(A.agility == B.agility)
var/X = rand(1,2)
if(X == 1)
A.battleprompt(A,B)
if(B.inpvp == 1 && A.inpvp == 1) B.npcbattleprompt(B,A)
if(B.inpvp == 1 && A.inpvp == 1) monsterbattle(A,B)
if(X == 2)
var/mob/C = B
B = A
A = C
C = null
B.npcbattleprompt(B,A)
if(B.inpvp == 1 && A.inpvp == 1) A.battleprompt(A,B)
if(B.inpvp == 1 && A.inpvp == 1) monsterbattle(A,B)
mob/proc/npcbattleprompt(mob/A as mob, mob/B as mob)
if(A.key != null)
A << "BUG"
B << "BUG"
var/command = pick(A.skilllist)
if(command == "Fight")
var/damage = round(((A.attack-B.defense)/2)+rand(-2,2))
view() << "[A] attacks!"
if(damage > 0)
B.HP -= damage
view() << "[A] does [damage] damage to [B]!"
B.Death()
else
view() << "[A]'s attack had no effect!"
if(command == "Heal")
view() << "[A] chants the spell of Heal!"
var/increase = rand(A.HP/100,A.HP/10)
view() << "[A] is healed for [increase] HP."
A.HP += increase
What it should do:
-->Create an NPC
-->Move the NPC to the user's right
-->Player/NPC face each other
-->Begin battle
-->Fastest one attacks first
-->Slower one attacks
-->Repeat until one dies
What it does:
-->Create NPC
-->Move NPC
-->Face each other
-->Begin Battle
-->Fastest one--[here's where errors start]
It finds the fastest one.
If its the player, the player attacks fine
If its the NPC, the battle stops.
Sometimes, I can even walk still (whenever inpvp = 1, the Move() proc returns 0)
--EDIT: I can move when I dont get the following runtime,
--------but not when I do
if you see where I have the check on npcbattleprompt() to make sure A.key = null, sometimes when I click the verb it will set up the battle and instead of giving me the battle prompt, I get this:
runtime error: list index out of bounds
proc name: npcbattleprompt (/mob/proc/npcbattleprompt)
usr: Gerbilman (/mob/Soldier)
src: Gerbilman (/mob/Soldier)
call stack:
Gerbilman (/mob/Soldier): npcbattleprompt(Gerbilman (/mob/Soldier), Test (/mob/NPC/Test))
Gerbilman (/mob/Soldier): monsterbattle(Test (/mob/NPC/Test), Gerbilman (/mob/Soldier))
Gerbilman (/mob/Soldier): Fight NPC()
BUG <---that is normal font, outputted by the check
Gerbilman being the user, and "Test" being the name of the NPC.
So obviously its calling the npcbattleprompt on the user instead. This is bad, as the user has no "skilllist" var and the NPC obviously can't use the player's battle prompt.
Its 2 AM and I can't think right now. I'll add to this/fix it myself when I wake up (if I can fix it...I doubt it). At 2 AM I tend to think differantly and I can't finsih what I made at 6 PM and when I wake up I have no idea what I was doing at 2 AM =(
My head will implode if anyone tells me (and is serious about it) to be more thorough this time...
I go to bed now and check this in the morning
[edit]
You're also passing in Gerbilman (PC) in the "A" slot, and then saying that if "A" (Gerbilman) has a key, to output "BUG". This leads me to believe that perhaps you were meaning Test (Currently being passed in as "B") to be checked, just to make sure it's an NPC. Might want to swap the A's and B's, as it appears that PC's don't have a skilllist variable, like NPCs do. :)