obj/Arrow
icon = 'weapons.dmi'
icon_state="Arrow_Moving"
density = 1
Bump(mob/b)
if(ismob(b))
if(b.isplayer==0)
b.hp -= 25
b.death_check()
else
del(src)
else
del(src)
obj/proc/Fire(var/obj/O
var/L
var/PL
start
PL = L
step(O,O:dir)
L = O:loc
sleep(10)
if(PL == L)
del(O)
else
goto start
mob/verb/Fire()
var/obj/O = new /obj/Arrow(usr.loc)
O:dir = usr.dir
O:owner=usr.key
O:Fire(O)
Death_Check Code:
proc/death_check(mob/M as mob)//handles death
if(src.hp <= 0)
M <<"You killed [src]!"
if(src.client)
src <<"[M] killed you!"
src.loc = locate(7,290,1)
src.hp = src.maxhp
src.canbuild = 0
else
var/YIN=rand(1,10)
var/BYIN=rand(25,100)
src.loc=locate(0,0,0)
if(ismob(M))
if(src.GOOGLEPLEX==1)
M.crowns+=BYIN
M.contents+=new/Items/Frog_Head
M<<"Congratulations! You got the Frog Head from the Evil Frog!!"
world<<"[M] has killed the Evil Frog!"
else
M.crowns+=YIN
sleep(1200)
src.loc=locate(src.sx,src.sy,src.sz)
src.hp=src.maxhp
else
usr=M.owner
usr.crowns+=YIN
if(src.GOOGLEPLEX==1)
usr.contents+=new/Items/Frog_Head
usr<<"Congratulations! You got the Frog Head from the Evil Frog!!"
world<<"[M] has killed the Evil Frog!"
del(M)
sleep(1200)
src.loc=locate(src.sx,src.sy,src.sz)
Problem description:
When I kill the monster, I get this runtime error:
runtime error: Cannot read null.owner
proc name: death check (/mob/proc/death_check)
source file: RisingEmpire.dm,1524
usr: 0
src: Frog (/Enemies/Normal)
call stack:
Frog (/Enemies/Normal): death check(null)
Arrow (/obj/Arrow): Bump(Frog (/Enemies/Normal))
Arrow (/obj/Arrow): Fire(Arrow (/obj/Arrow))
{OWNER} Mikal (/mob/character): Fire()
I believe the arrow is deleted before it can read the owner. Please help if you can. =)
I believe the arrow is deleted before it can read the owner. Please help if you can. =)
Actually, it doesn't look like the arrow is getting deleted until it moves to the spot occupied by the enemy. Your main problem is easily fixable, but will present more problems afterwards (like the arrow never getting deleted, or hitting more people).
Starting from top to bottom, the main problem lies in Bump(). You're not sending the owner (that variable should point to the mob itself, though) of the arrow to death_check(). I know you have death_check() set up to receive an arrow, but you didn't send it and it's better to just send the mob. =) Also, it looks like you want the arrow to be deleted whenever it bumps into anything, but I'm going to guess you don't want it sitting on the edge of the map when there's nothing to Bump() either so we'll save the deleting for the Fire proc.
Fire, apart from having a few common no-nos, has the distinct problem of assuming that the arrow will eventually end up in O's loc. It will if there happens to be a person on the same x or y axis that you're facing, but there's a much better way. step() will return a FALSE value if movement fails (if something is in the way (Bump()ed), or if there is no location to move to (the edge of the map)). Since you'll only want this loop going while the arrow is still around (and the arrow should be moving while it's around), while() is clearly a better choice than goto.
Consider type casting as an alternative to using the colon operator. It actually saves you typing here. =) Also, remember that I'm making owner hold the mob instead of the key.
I don't really know your plan here, so I'm short on some ideas. I would suggest that the item be created inside of M instead of added to the contents list, contents is a special list and I'm not sure how it responds to that. Refilling the enemies health before placing them on them map makes more sense to me, but I doubt anyone could actually attack it in such a short amount of time. =) Of course, since we're not sending any arrows to death_check(), we can get rid of the second half of this proc. =)