ID:166170
 
Well, I've just got started creating my RPG. (I had a thread concerning my Level Up system but I thought I should start a fresh one as these are new questions. This is my first RPG ive created, and I'm new to byond code. I've read some tutorials, but I find it much easier using the forums.

Anyway, I have a few questions, and I'd appreciate any answers you can give. I'll add to the questions as I progress. Thanks!

1. How can I stop players from being able to move whilst they are next to an enemy mob? (So they are 'engaged' in battle'. I intend to add an escape command later)

2. How can I create a tab on the command menu so that I can display the stats of the character? I think I can do this, but I don't know how to create a tab.

3. How can I stop numbers (such as HP) from exceeding their maximum? I have a MaxHP value, but I have no coe to say that the HP cannot exceed this value.

I'll show you my code if you need to see it.

Thanks!

mob

var
HP = 30 //define a new variable called HP, with a value of 30
MP = 10
MaxHP=30
MaxMP=10
Level=1
EXP=0
EXPNeeded=15
Strength=2
Magic=1
GP=10

Del()
var/obj/gold/G = new(loc) //create a new obj from the gold blueprint
G.amount = rand(1,100) //set its amount variable randomly
..() //call the parent

Login()
switch(input("Which race would you like to be?") in list ("Human","Elf","Vampire","Lycan","Demon","Angel"))
if("Human")
src.icon = 'human.dmi'
if("Elf")
src.icon = 'elf.dmi'
if("Vampire")
src.icon = 'vampire.dmi'
if("Lycan")
src.icon = 'lycan.dmi'
if("Demon")
src.icon = 'demon.dmi'
if("Angel")
src.icon = 'angel.dmi'

..() //the gender of their key. Then call the parent!
world << "[usr] has entered!"

proc/GainEXP(n) // gain n experience points //start
EXP=(EXP+n)
if(EXP>=EXPNeeded) LevelUp()

proc/LevelUp()
src.Level++
src << "You levelled up! (Level [Level])."
src.MaxHP=26+4*src.Level // 26+(4*1) = 30, the original value
src.MaxMP=6+4*src.Level
src.HP=src.MaxHP
src.MP=src.MaxMP
src.Strength = src.Strength+3
src.Magic = src.Magic+3
src.EXPNeeded=(30+(Level*2))*src.Level //end

proc
DeathCheck(mob/M) //checks to see if an attack is deadly
if (HP <= 0) //if the defender's HP is low enough...
M << "You killed [src]!" //do the death messaging
M.GainEXP(src.EXP)
del(src) //delete whatever just died

verb
say(msg as text) //what the usr says is passed into "msg" as text
world << "[usr]: [msg]" //the world sees chatroom-like output
EXPboost(mob/M)
usr.GainEXP(20)
attack(mob/M as mob in oview(1)) //attack a mob within 1 tile of you
usr << "You attack [M]!" //send this message to the usr
var/damage = rand(1,10)+Strength //assign a random # to a new variable and add strength
usr << "[damage] damage!" //tell the damage to the usr
M.HP -= damage //take away the damage from M
M.DeathCheck(src) //check for death with a proc
if (M.HP>=0)
usr << "[M] attacks you!"
var/Mdamage = rand(1,10)+M.Strength
usr << "You lose [Mdamage] HP!"
usr.HP -= Mdamage
else
..()

cure (mob/M)
usr << "You cast cure on [M]!"
var/healed = rand(1,8)+Magic
usr << "You healed [healed] HP"
M.HP += healed
M.MP -= 5




status(mob/M) //stats
usr << "-----------------------------------------"
usr << "[src] LEVEL [Level]"
usr << "HP = [HP]/[MaxHP]"
usr << "MP = [MP]/[MaxMP]"
usr << "Strength = [Strength]"
usr << "EXP = [EXP]"
usr << "[EXPNeeded-EXP] EXP to level [Level+1]"
usr << "[GP] gold."
usr << "-----------------------------------------"



wolf //new prototype
icon = 'wolf.dmi' //override the parent's icon, which was 'person.dmi'
EXP = 5
Strength = -1

obj
gold //define a "gold" prototype, which is a kind of obj
icon = 'gold.dmi' //set the default icon
var
amount //declare a new variable called "amount"
verb
get() //obj/gold/verb/get()
set src in view(1) //src must be close
usr << "You pick up [amount] gold."
usr.GP += amount //add to usr.GP
del(src) //delete the gold


This is my code. I have a problem - I can attack and kill an enemy, and everything seems to run smoothly, but I recieve the following error:

runtime error: Cannot read null.HP
proc name: attack (/mob/verb/attack)
usr: RoadToDawn (/mob)
src: RoadToDawn (/mob)
call stack:
RoadToDawn (/mob): attack(null)

As far as I can tell the only actual problem is the fact that this error is appearing. As far as I can tell its working. Any clues as to why this keeps popping up each time an enemy dies?
1)
mob/Move(na, direction)
if(locate(/type) in oview(1)) // if mob finds the types of /type in oview(1)
return
return ..()


2)
mob/Stat()
statpanel("name") // a name for a stat panel
stat(usr.bodystr) // a stat


3)
var 
health = 200
healthmax = 3012

mob/verb/Heal()
usr.health = min(max(health, 0), maxhealth)
// max() chooses the maximum value
// min() chooses the minimum value
In response to DivineO'peanut
mob

var
HP = 30 //define a new variable called HP, with a value of 30
MP = 10
MaxHP=30
MaxMP=10
Level=1
EXP=0
EXPNeeded=15
Strength=2
Magic=1
GP=10

Stat()
statpanel("Stats") // a name for a stat panel
stat("[usr]")
stat("Level [usr.Level]")
stat("")
stat("HP: [usr.HP]/[usr.MaxHP]") // a stat
stat("MP: [usr.MP]/[usr.MaxMP]")
stat("STR: [usr.Strength]")
stat("MAG: [usr.Magic]")
stat("Total EXP: [usr.EXP]")
stat("EXP to next level: [usr.EXPNeeded-usr.EXP]")
stat("GP: [usr.GP]")


Del()
var/obj/gold/G = new(loc) //create a new obj from the gold blueprint
G.amount = rand(1,100) //set its amount variable randomly
..() //call the parent

Login()
switch(input("Which race would you like to be?") in list ("Human","Elf","Vampire","Lycan","Demon","Angel"))
if("Human")
src.icon = 'human.dmi'
if("Elf")
src.icon = 'elf.dmi'
if("Vampire")
src.icon = 'vampire.dmi'
if("Lycan")
src.icon = 'lycan.dmi'
if("Demon")
src.icon = 'demon.dmi'
if("Angel")
src.icon = 'angel.dmi'

..() //the gender of their key. Then call the parent!
world << "[usr] has entered!"

proc/GainEXP(n) // gain n experience points //start
EXP=(EXP+n)
if(EXP>=EXPNeeded) LevelUp()

proc/LevelUp()
src.Level++
src << "You levelled up! (Level [Level])."
src.MaxHP=26+4*src.Level // 26+(4*1) = 30, the original value
src.MaxMP=6+4*src.Level
src.HP=src.MaxHP
src.MP=src.MaxMP
src.Strength = src.Strength+3
src.Magic = src.Magic+3
src.EXPNeeded=(30+(Level*2))*src.Level //end

proc
DeathCheck(mob/M) //checks to see if an attack is deadly
if (HP <= 0) //if the defender's HP is low enough...
M << "You killed [src]!" //do the death messaging
M.GainEXP(src.EXP)
del(src) //delete whatever just died

verb
say(msg as text) //what the usr says is passed into "msg" as text
world << "[usr]: [msg]" //the world sees chatroom-like output
attack(mob/M as mob in oview(1)) //attack a mob within 1 tile of you
usr << "You attack [M]!" //send this message to the usr
var/damage = rand(1,10)+Strength //assign a random # to a new variable and add strength
usr << "[damage] damage!" //tell the damage to the usr
M.HP -= damage //take away the damage from M
M.DeathCheck(src) //check for death with a proc
if (M.HP>=0)
usr << "[M] attacks you!"
var/Mdamage = rand(1,10)+M.Strength
usr << "You lose [Mdamage] HP!"
usr.HP -= Mdamage
else
..()

cure (mob/M)
usr.HP = min(max(HP, 0), MaxHP)
usr << "You cast cure on [M]!"
var/healed = rand(1,8)+Magic
usr << "You healed [healed] HP"
M.HP += healed
M.MP -= 5




status(mob/M) //stats
usr << "-----------------------------------------"
usr << "[src] LEVEL [Level]"
usr << "HP = [HP]/[MaxHP]"
usr << "MP = [MP]/[MaxMP]"
usr << "Strength = [Strength]"
usr << "EXP = [EXP]"
usr << "[EXPNeeded-EXP] EXP to level [Level+1]"
usr << "[GP] gold."
usr << "-----------------------------------------"



wolf //new prototype
icon = 'wolf.dmi' //override the parent's icon, which was 'person.dmi'
EXP = 5
HP = 20
MaxHP = 20
GP = 10
Strength = -1

puppet
EXP = 15
icon = 'puppet.dmi'
HP = 50
MaxHP = 50
GP = 30
Strength = 3


obj
gold //define a "gold" prototype, which is a kind of obj
icon = 'gold.dmi' //set the default icon
var
amount //declare a new variable called "amount"
verb
get() //obj/gold/verb/get()
set src in view(1) //src must be close
usr << "You pick up [amount] gold."
usr.GP += amount //add to usr.GP
del(src) //delete the gold


Right. The statpanel works perfectly, thanks.

I'm having a little trouble with the other two though.

Firstly, under mob/verb/cure I cannot seem to get the code you gave me to work. What have I done wrong?

Secondly, the other code. I tred entering the code you showed me, but it said 'inconsistent indentation' no matter how I tried to put it in. Where exactly should this go?

Thanks for your help.
In response to RoadToDawn
Remember, codes are there to show you an example of HOW it works.. NOT to be copied/pasted (saying tis because of the indentation error)

1) What you have done wrong about the min()/max() example is that you placed it first, before the HP was added.. what is the point of checking if the HP went over before you add something to the HP which can make it go over? (Though you could've simply edited the example Div showed you and added the HP+5 within it, saving you a byte or two)

2) Read what I said at the beginning

- GhostAnime
In response to RoadToDawn
i think that means your deathcheck dont work

do you habe it on the end of your attack phase?
In response to GhostAnime
Right, I've got it all working, except for the code to stop players moving when they encounter (stand next to) an enemy.

Where/how exactly do I put that code inot my game?

Thanks