Ok, so I've been working on this dukey, little RPG game, and I have a bug or two I'd like to figure out. Please, don't reccomend deleting my code and started over because I have heard that enough and once more will burst my bubble. Also, don't reffer me to any demo or library or help site or anything, give me the line of codes that I need. If you can't do this, don't help me. Now, the first code is, I'm trying to add simple verbs to all of my /obj/Weapons thing. But I can't figure out how to add an src to my contents, I'll show you...
obj
Weapons
verb
Get()
set src in oview(0)
usr.contents.Add(new src)
usr<<"You picked up a(n) [src]!"
del src
Now I've tried this and, foccusing on the "usr.contents.Add(newsrc)" line, My inventory doesn't add any weapons. Yes I've coded the actual src into the /obj/Weapons part, and I am useing mob/Stat()/statpanel("Inventory",contents), but It's not working. If you know what I'm doing wrong, please tell me. Second, I haven't official tested this, but I don't think it's working considering the way I coded it to. There aren't any bugs in it, and it's playable but I want more... Here is everything having to do with my code...
Move()
..()
if(src.client)
for(var/mob/Monster/M in view())
if(M.after == 0)
M.after = src.name
M.stepto()
proc
stepto()
for(var/mob/M in view())
if(src.after == M.name)
if(get_dist(src,M) == 1)
src.dir = get_dir(src,M)
step(src,src.dir)
sleep(src.atdel)
src.stepto()
else
step_to(src,M)
sleep(src.atdel)
src.stepto()
else
src.after = 0
return
mob/Monster
Bump(mob/M)
if(M.client)
var/dmg = src.str - M.def + rand(src.neg,src.pos)
if(dmg <= 0)
dmg = 1
M.hp -= dmg
M<<"[src] hit you for [dmg]!"
if(M.hp <= 0)
M.loc = locate(7,5,1)
world<<"[M] has been killed by [src]!"
M.hp = M.maxhp
M.gold = 1/2 * M.gold
var/goldd = round(M.gold)
M.gold = goldd
else
return
Now, that basically tells every monster in my view, after i move, to go after me and once it is next to me bump into me, calling the mob/Monster/Bump() thing. I have all the vars as atom, if that counts for anything... the problem is, once I am out of the monsters view, say I die, it's "after" var doesn't set back to 0. I want to know why, and how to fix it. Hit up any questions you have for me in my code...
ID:173088
Feb 18 2004, 9:14 am
|
|
Feb 18 2004, 11:18 am
|
|
Ok maybe that wasn't so quick... We'll change it to long question.
|
First, when picking up items, all you have to doo is use Move(usr). Also, instead of having a(n), you can just use \a, which will usually give you the correct a/an thing (I say usually because there are som words where it can be both, like "history", depending on how you pronounce it.)
Second, everywhere you have view(), it's defaulting to view(usr). You should change that to view(src). usr is not safe in procs, especially your step_to proc. Since in a single-player game, usr tends to usually be the player playing (but not always), you'll usually be in view(usr), so the monster will never stop chasing you. Fourth, whenever you're recursively calling a proc like stepto(), you should use spawn() stepto(), or spawn(src.atdel) stepto(). Otherwise, the calls will just build up, each new one waiting for the last one to finish, until eventually it exceeds the memory it's been allocated, and crashes. Fifth, mobs should have their own proc for checking how they die, instead of having a general one in whatever the attack procs are. Sixth, your monsters will probably get stuck in difficult terrain. You should probably use step_to() to use pathfinding, and then when the monster is close enough, use step_towards() to not use pathfinding, so the monster will bump into the mob. |