ID:269310
 
My training code, it is called by clicking on a HUD, then it calls the STRAIN proc from the Training Bag in oview(1). Here is the code.
obj
Training
Trainable = 1
proc
STrain()
return

Punching_Bag
icon = 'Objects.dmi'
icon_state = "P Bag"
density = 1
STrain(mob/M)
var/mob/Player/P = M
if(P.Stamina<=0)
P << "<b><font color=blue>You need to rest!"
return
else
P.Training = 1
flick("Punch",P)
P.Stamina -= rand(1,5)
P.Strength += rand(0.06,0.14)
P.MaxPL += rand(1,8)
P.Training = 0
P.Skill_Check()
return

But when I try to train I get a DS i get a run-time error.
Why don't you post the HUD code, and what exactly are you trying to do? This is what I can give you without that information, though. This is not for an HUD code. You simply Click the Punching Bag and you're training.

obj/Training
var/Trainable = 1
Punching_Bag
icon = 'Objects.dmi'
icon_state = "P Bag"
density=1
Click()
set src in oview(1)
usr.STrain()

mob/proc/STrain()
if(src.Stamina<=0) {src << "You need to rest.",return}
src.Training = 1
flick("Punch",P)
src.Stamina-=rand(1,5)
src.Strength += rand(0.06,0.14)
src.MaxPL += rand(1,8)
src.Training=0
src.Skill_Check()
return
Why don't you post the HUD code, and what exactly are you trying to do? This is what I can give you without that information, though. This is not for an HUD code. You simply Click the Punching Bag and you're training.
obj/Training
var/Trainable = 1
Punching_Bag
icon = 'Objects.dmi'
icon_state = "P Bag"
density=1
Click()
set src in oview(1)
usr.STrain()

mob/proc/STrain()
if(src.Stamina<=0) {src << "You need to rest.",return}
src.Training = 1
flick("Punch",P)
src.Stamina-=rand(1,5)
src.Strength += rand(0.06,0.14)
src.MaxPL += rand(1,8)
src.Training=0
src.Skill_Check()
return

That probabaly works, I hope.
In response to CaptFalcon33035
mob
verb
Train()
set hidden = 1
for(var/obj/Training/P in oview(1))
if(src.Training||src.Flying)
return
else
P:STrain()
return

You call that then it should call STRAIN for the punching bag
obj
Training
Trainable = 1
proc
STrain()
return

Punching_Bag
icon = 'Objects.dmi'
icon_state = "P Bag"
density = 1
STrain(mob/M)
var/mob/Player/P = M
usr = P
if(P.Stamina<=0)
P << "<b><font color=blue>You need to rest!"
return
else
P.Training = 1
flick("Punch",P)
P.Stamina -= rand(1,5)
P.Strength += rand(0.06,0.14)
P.MaxPL += rand(1,8)
P.Training = 0
P.Skill_Check()
return
In response to ITG Master
Your using the colon operator where you should be using the period. Especially in this case as you have P defined using a period should work fine.

The reason nothing is happening is that P is null in STrain(). You have an argument set to be passed (mob/M) and are passing nothing. You then have P being set to M (since M was null P also becomes null). Setting usr to P is also pointless as its never actually used, and should not be used within a proc.

mob
verb
Train()
set hidden = 1
for(var/obj/Training/P in oview(1))
if(src.Training||src.Flying)
return
else
P.STrain(usr)
return
obj
Training
Trainable = 1
proc
STrain()
return

Punching_Bag
icon = 'Objects.dmi'
icon_state = "P Bag"
density = 1
STrain(mob/player/M)
if(M.Stamina<=0)
M << "<b><font color=blue>You need to rest!"
return
else
M.Training = 1
flick("Punch",M)
M.Stamina -= rand(1,5)
M.Strength += rand(0.06,0.14)
M.MaxPL += rand(1,8)
M.Training = 0
M.Skill_Check()
return
In response to Nick231
- edited -