ID:1278513
 
(See the best response by Super Saiyan X.)
Code:
mob/skill
verb
ShootPistol()
src.Health_Bar()
src.Mind_Bar()
src.Action_Bar()
src.Exp_Bar()
if(usr.doing == 0)
usr.doing = 1
var/obj/Projectile/Redlazerbeam/A=new(usr.loc)
A.icon='redlazerbeam.dmi'
A.Owner=usr
A.ForceName="Redlazerbeam"
walk(A,usr.dir)
sleep(10)
usr.doing = 0
obj
projectile
Redlazerbeam
density=1
Move()
..()
src.lifespan-=1
if(lifespan<=0)
del src
Bump(A)
if(ismob(A))
var/damage = ((src.maxmind/2) + (src.gundamage))
var/mob/M=A
if(src.Owner==M)
src.x=M.x
src.y=M.y
else
if(M.ForceProtect)
src.dir=turn(src,180)
src.lifespan=15
walk(src,src.dir)
else
view(src)<<output("[M] has been hit by a [src.ForceName] for [damage]!","combat")
flick("Shoot",usr)
M.health -= damage
M.health = round(M.health)
M.death(M)

del src
else
del src
..()


Problem description:

runtime error: Cannot read 0.exp
proc name: GiveReward (/mob/proc/GiveReward)
source file: inventory.dm,4
usr: 0
src: the sandcat (/mob/Enemies/sandcat)
call stack:
the sandcat (/mob/Enemies/sandcat): GiveReward(the sandcat (/mob/Enemies/sandcat))
the sandcat (/mob/Enemies/sandcat): death(the sandcat (/mob/Enemies/sandcat))
Redlazerbeam (/obj/Projectile/Redlazerbeam): Bump(the sandcat (/mob/Enemies/sandcat))
Redlazerbeam (/obj/Projectile/Redlazerbeam): Move(Dirt (15,229,1) (/turf/dantooine/Dirt), 1)
runtime error: Cannot read 0.exp
proc name: levelup (/mob/proc/levelup)
source file: procedures.dm,3
usr: 0
src: the sandcat (/mob/Enemies/sandcat)
call stack:
the sandcat (/mob/Enemies/sandcat): levelup(the sandcat (/mob/Enemies/sandcat))
the sandcat (/mob/Enemies/sandcat): death(the sandcat (/mob/Enemies/sandcat))
Redlazerbeam (/obj/Projectile/Redlazerbeam): Bump(the sandcat (/mob/Enemies/sandcat))
Redlazerbeam (/obj/Projectile/Redlazerbeam): Move(Dirt (15,229,1) (/turf/dantooine/Dirt), 1)
runtime error: Cannot read 0.exp
proc name: GiveReward (/mob/proc/GiveReward)
source file: inventory.dm,4
usr: 0
src: the sandcat (/mob/Enemies/sandcat)
call stack:
the sandcat (/mob/Enemies/sandcat): GiveReward(the sandcat (/mob/Enemies/sandcat))
the sandcat (/mob/Enemies/sandcat): death(the sandcat (/mob/Enemies/sandcat))
Redlazerbeam (/obj/Projectile/Redlazerbeam): Bump(the sandcat (/mob/Enemies/sandcat))
Redlazerbeam (/obj/Projectile/Redlazerbeam): Move(Dirt (15,229,1) (/turf/dantooine/Dirt), 1)
runtime error: Cannot read 0.exp
proc name: levelup (/mob/proc/levelup)
source file: procedures.dm,3
usr: 0
src: the sandcat (/mob/Enemies/sandcat)
call stack:
the sandcat (/mob/Enemies/sandcat): levelup(the sandcat (/mob/Enemies/sandcat))
the sandcat (/mob/Enemies/sandcat): death(the sandcat (/mob/Enemies/sandcat))
Redlazerbeam (/obj/Projectile/Redlazerbeam): Bump(the sandcat (/mob/Enemies/sandcat))
Redlazerbeam (/obj/Projectile/Redlazerbeam): Move(Dirt (15,229,1) (/turf/dantooine/Dirt), 1)
runtime error: Cannot read 0.exp
proc name: GiveReward (/mob/proc/GiveReward)
source file: inventory.dm,4
usr: 0
src: the sandcat (/mob/Enemies/sandcat)
call stack:
the sandcat (/mob/Enemies/sandcat): GiveReward(the sandcat (/mob/Enemies/sandcat))
the sandcat (/mob/Enemies/sandcat): death(the sandcat (/mob/Enemies/sandcat))
Redlazerbeam (/obj/Projectile/Redlazerbeam): Bump(the sandcat (/mob/Enemies/sandcat))
Redlazerbeam (/obj/Projectile/Redlazerbeam): Move(Dirt (15,229,1) (/turf/dantooine/Dirt), 1)
runtime error: Cannot read 0.exp
proc name: levelup (/mob/proc/levelup)
source file: procedures.dm,3
usr: 0
src: the sandcat (/mob/Enemies/sandcat)
call stack:
the sandcat (/mob/Enemies/sandcat): levelup(the sandcat (/mob/Enemies/sandcat))
the sandcat (/mob/Enemies/sandcat): death(the sandcat (/mob/Enemies/sandcat))
Redlazerbeam (/obj/Projectile/Redlazerbeam): Bump(the sandcat (/mob/Enemies/sandcat))
Redlazerbeam (/obj/Projectile/Redlazerbeam): Move(Dirt (15,229,1) (/turf/dantooine/Dirt), 1)



This happends when i kill a mob with my projectile, that is fired from my shootpistol verb.
Im pretty sure it have somthing to do with Levelup() and GiveReward(), but i dont know how i can make it work properly. So if one of u bright minds on this forum could help me. That would be great :)
Can you show the code for /mob/proc/GiveReward() and /mob/proc/levelup()? The issues are occurring there.
mob/proc
levelup()
if(usr.exp >=usr.maxexp)
usr.level +=1
usr.exp = 0
usr.maxexp = usr.maxexp + rand(10,13)
usr.maxaction+=rand(5,8)
usr.maxhealth+=rand(15,20)
usr.maxmind+=rand(5,8)
usr.defense+=rand(1,3)
usr.regenhp+=5
usr.gundamage += 2
usr.skillpoints += 1
usr.hitspeed -=rand(0.1,0.3)
usr << output("<font color = Yellow>Level up!","system")
usr.RankCheck()
usr.Savemob()
sleep(10)
mob
proc
GiveReward()
usr.exp += src.expgive
usr.money += src.moneygive
if(src.specie == "Sand Cat")
src.Muppet = rand(1,1)
if(Muppet == 1)
new/Item/equippable/weapons/crudesword(src.loc)
usr << output("<font color = Yellow>Drop:</font>[specie] dropped a Crude Sword","system")
if(src.specie == "Dusk Cat")
src.Muppet = rand(1,1)
if(Muppet == 1)
new/Item/equippable/weapons/pistol(src.loc)
usr << output("<font color = Yellow>Drop:</font>[specie] dropped a Crude Sword","system")
Can you show an example of where/how they're called?
From the runtimes, it looks like they're called in /mob/Enemies/sandcat/death()? (or somewhere farther up the chain)
Hmmm, this is how all my mobs are made:

mob
Enemies
stormtrooper
icon = 'mobs.dmi'
icon_state = "stormtrooper"
density = 1
health = 1000
maxhealth = 1000
attackspeed = 10
action = 150
defense = 150
moneygive = 50
expgive = 400
level = 150
attacked = 0


The Death() should be called when somthing hits 0 hp, and then give the Expgive and moneygive.
and i used my shootpistol() to call the Death(), but i dont know if im doing it the right way.

Just as a side note: This way works fine with my attack(), but i might have to change somthing im not aware of?
Can you show the death proc, then?
mob
proc
death(mob/M)
if(src.health <= 0)
if(src.client)
world << output("<font color = red><b>Death Info:</font>[src] have been killed by [usr]","system")
src.Muppet = rand(1,14)
if(Muppet == 1)
src.moveable = 0
src.loc = locate(2,253,15)
src.sight |= BLIND
sleep(200)
src.sight &= ~BLIND
src.action = src.maxaction
src.mind = src.maxmind
src.Cloning()
if(Muppet == 2)
src.moveable = 0
src.loc = locate(2,249,15)
src.sight |= BLIND
sleep(200)
src.sight &= ~BLIND
src.action = src.maxaction
src.mind = src.maxmind
src.Cloning()
if(Muppet == 3)
src.moveable = 0
src.loc = locate(2,245,15)
src.sight |= BLIND
sleep(200)
src.sight &= ~BLIND
src.action = src.maxaction
src.mind = src.maxmind
src.Cloning()
if(Muppet == 4)
src.moveable = 0
src.loc = locate(2,242,15)
src.sight |= BLIND
sleep(200)
src.sight &= ~BLIND
src.action = src.maxaction
src.mind = src.maxmind
src.Cloning()
if(Muppet == 5)
src.moveable = 0
src.loc = locate(2,239,15)
src.sight |= BLIND
sleep(200)
src.sight &= ~BLIND
src.action = src.maxaction
src.mind = src.maxmind
src.Cloning()
if(Muppet == 6)
src.moveable = 0
src.loc = locate(2,235,15)
src.sight |= BLIND
sleep(200)
src.sight &= ~BLIND
src.action = src.maxaction
src.mind = src.maxmind
src.Cloning()
if(Muppet == 7)
src.moveable = 0
src.loc = locate(2,232,15)
src.sight |= BLIND
sleep(200)
src.sight &= ~BLIND
src.action = src.maxaction
src.mind = src.maxmind
src.Cloning()
if(Muppet == 8)
src.moveable = 0
src.loc = locate(36,253,15)
src.sight |= BLIND
sleep(200)
src.sight &= ~BLIND
src.action = src.maxaction
src.mind = src.maxmind
src.Cloning()
if(Muppet == 9)
src.moveable = 0
src.loc = locate(36,249,15)
src.sight |= BLIND
sleep(200)
src.sight &= ~BLIND
src.action = src.maxaction
src.mind = src.maxmind
src.Cloning()
if(Muppet == 10)
src.moveable = 0
src.loc = locate(36,245,15)
src.sight |= BLIND
sleep(200)
src.sight &= ~BLIND
src.action = src.maxaction
src.mind = src.maxmind
src.Cloning()
if(Muppet == 11)
src.moveable = 0
src.loc = locate(36,242,15)
src.sight |= BLIND
sleep(200)
src.sight &= ~BLIND
src.action = src.maxaction
src.mind = src.maxmind
src.Cloning()
if(Muppet == 12)
src.moveable = 0
src.loc = locate(36,239,15)
src.sight |= BLIND
sleep(200)
src.sight &= ~BLIND
src.action = src.maxaction
src.mind = src.maxmind
src.Cloning()
if(Muppet == 13)
src.moveable = 0
src.loc = locate(36,235,15)
src.sight |= BLIND
sleep(200)
src.sight &= ~BLIND
src.action = src.maxaction
src.mind = src.maxmind
src.Cloning()
if(Muppet == 14)
src.moveable = 0
src.loc = locate(36,232,15)
src.sight |= BLIND
sleep(200)
src.sight &= ~BLIND
src.action = src.maxaction
src.mind = src.maxmind
src.Cloning()

else
GiveReward(M)
levelup(M)
sleep(2)
del(src)


This is the death()
You should be passing src.Owner to death, not M. M is the ai, src.Owner is the one that fired.

Right now your saying that the ai that is dieing gets the rewards.
Well im not really that good at projectiles, and no way how i put it, it still will give a runtime error. Do you have a suggestion to where or how i put the death()?
You're abusing usr everywhere. Even though you're taking arguments, you're not passing the right values, and you're even not using them in the procs. Is this code even yours? This is insane.
Well, if im putting src. instead of usr. in the lvlup proc, it dont do anything. And yea, some of the codes are some i found in demos, but most are some i made up.
Like i stated above, im not good at projectiles, so i found a demo on how to do projectiles, and edited it. But what does that have to do whith anything? The case is that it wont work, and if any of u see somthing i dont, please help me then.
Well, you have a few issues in the code.
When you call things like GiveReward(), you're passing 'M' as an argument, rather than calling the proc on them: M.GiveReward()

This would also require you to replace all of the 'usr' in your procedures with 'src'.
Hmm, then it gives a runtime error in Offensive(). Can you see why?

mob
verb
Offensive()
set category = "Commands"
set name = "Offensive"
if(src.KO==0)
if(src.doing == 0)
src.Health_Bar()
src.Mind_Bar()
src.Action_Bar()
src.Exp_Bar()
var/damage = src.maxaction
var/hitspeed = src.hitspeed
for(var/mob/M in get_step(src,src.dir))
if(M.client == 1)
if(src.swordequipped == 1)
src.doing = 1
damage -= (M.defense/0.8)
if(damage <= 0)
damage = 1
view(6) << output("<font color = white>[usr] hits [M] for [damage]!","combat")
flick("Sword Slash",usr)
M.health -= damage
M.health = round(M.health)
M.KO()
sleep(hitspeed)
src.doing = 0
return
if(src.swordequipped == 0)
src.doing = 1
damage -= (M.defense/0.8)
if(damage <= 0)
damage = 1
view(6) << output("<font color = white>[usr] hits [M] for [damage]!","combat")
flick("melee",usr)
M.health -= damage
M.health = round(M.health)
M.KO()
sleep(src.hitspeed)
src.doing = 0
return
else
if(src.swordequipped == 1)
src.doing = 1
damage -= (M.defense/0.8)
if(damage <= 0)
damage = 1
view(6) << output("<font color = white>[usr] hits [M] for [damage]!","combat")
flick("Sword Slash",usr)
src.health -= damage
src.health = round(M.health)
src.death()
sleep(src.hitspeed)
src.doing = 0
return
if(src.swordequipped == 0)
src.doing = 1
damage -= (M.defense/0.8)
if(damage <= 0)
damage = 1
view(6) << output("<font color = white>[usr] hits [M] for [damage]!","combat")
flick("melee",usr)
M.health -= damage
M.health = round(M.health)
M.death()
sleep(src.hitspeed)
src.doing = 0
return



else
src<< output("You can't attack while being KO!","combat")



runtime error: Cannot execute null.GiveReward().
proc name: death (/mob/proc/death)
source file: Battle System.dm,172
usr: Sleaze (/mob/Players)
src: the sandcat (/mob/Enemies/sandcat)
call stack:
the sandcat (/mob/Enemies/sandcat): death(null)
Sleaze (/mob/Players): Offensive()

When you're calling death in offensive; you're never passing the argument to it; which appears to be the mob who kills the the other mob. That argument is essential to your death proc.
I'm assuming it'd be
M.death(src)
Alright, now it kills the mob, and it checks for reward() and Levelup(), but the mob that is killed is not passing on the exp to the user. Got any idea on that?
Best response
In death(), you had this:
GiveReward(M)
levelup(M)
I suggested you change it to M.GiveReward(), what you probably want though is:
death()
//etc
M.GiveReward(src) //src is the mob dying?

//and then your GiveReward proc would look like this:
mob
proc
GiveReward(mob/died)
exp += died.expgive
money += died.moneygive
//etc



Basically, be careful where and how you call your procs; be sure the person you are calling the proc on is the right person; and be sure you're passing the right arguments and accessing them correctly.

Try not to use usr in procs (unless it's in Click(), or other obj-related things.)
'src' is the target of the proc (in M.GiveReward, src would be equal to M),
usr would be the person who first clicked the verb, but that gets funky along the way, so try not to use.
Alright that worked! Thanks alot mate!

i made it like this now

mob
proc
GiveReward(mob/died)
exp += died.expgive
money += died.moneygive
if(src.specie == "Sand Cat")
src.Muppet = rand(1,1)
if(Muppet == 1)
new/Item/equippable/weapons/crudesword(src.loc)
src << output("<font color = Yellow>Drop:</font>[specie] dropped a Crude Sword","system")
if(src.specie == "Dusk Cat")


The exp and money is passed on to the killer, but what do i need to put into
if(src.specie == "Sand Cat")
src.Muppet = rand(1,1)
if(Muppet == 1)
new/Item/equippable/weapons/crudesword(src.loc)
src << output("<font color = Yellow>Drop:</font>[specie] dropped a Crude Sword","system")

inorder to make the mob drop the crudesword? Because when it is like this, it dont drop and it dont pass the output to the killer.
You're checking the specie of the src - the killer - rather than the thing that died.
Alright now it works :D Thanks alot mate, and sorry for being an idiot :P