ID:145852
 
Code:
mob
Bat
name = "Bat"
icon = 'turf/Enemies.dmi'
icon_state = "bat"
powerlevel = 10
str = 3
end = 2
agi = 1
exp = 5
Bumped(O)
usr.lock = 1
usr.loc = src.loc
usr.loc = locate(usr.x,usr.y-3,usr.z)
usr.dir = NORTH
usr.inbattle = 1
if(usr.agi > src.agi)
usr.AttackPanel()
else
usr.MonsterAttack()
proc
Bumped(O)
Bump(O)
..()
if(ismob(O))
O:Bumped(src)

mob/proc
AttackPanel()
usr.isturn = 1

MonsterAttack(src)
var/attack = rand(1,5)
if(attack == 5)
var/damage = str * 3
usr << "<font color=green>The [src] [pick("hit","damaged","attacked")] [usr.player] with a critcal for [damage]!</font>"
usr.powerlevel -= damage
usr.AttackPanel()
else
var/damage = str * 2
usr << "<font color=green>The [src] [pick("hit","damaged","attacked")] [usr.player] for [damage]!</font>"
usr.powerlevel -= damage
usr.AttackPanel()

Death()
if(src.powerlevel <= 0)
usr.exp += src.exp
usr.gold += src.gold
LevelUp()
usr.lock = 0
del src

LevelUp()
if(usr.exp == usr.neededexp)
usr << "<font color=green>You have gained a level! Your level is now [usr.level]!</font>"
usr.level += 1
usr.powerlevel += rand(50,100)
usr.str += rand(1,5)
usr.end += rand(1,3)
usr.stmmax += rand(1,2)
usr.agi += rand(1,3)


Problem description: Well, if you haven't heard by now, I've made it my mission to make a none ripped DBZ based game before I leave for bootcamp February 16th. For some reason this combat code I made up just doesn't seem to work. When you bump into the monster it does show text, but the src is either blank or yourself. Any ideas?
No put usr in proc, Ungh
In response to Mysame
Thanks for that oh so wonderful piece of information. I've tried it 3 different ways. Your advice does not tell me a god damn thing. Will you people learn that it doesn't help to say "No usr in proc"? I don't think so. I've tried defining the enemy, I've tried changing alot of things, none have worked. Thanks for making me waste my time typing this.
In response to Plagu3r
If you know, why not use it?
In response to Mysame
Because this was my last ditch effort and I got pissed and posted it the way I last tried using it.
I can understand your frustration with the "usr proc ungh" crap, but that IS part of your problem. I think it would help you to understand more about just how a proc works. The ()'s are there for you to pass arguments to a proc. In the case of Bump(O), O is the entity being bumped by the src. Usr can be anything in this case, it's usually a player hitting a direction key, but not always. You didn't use usr in Bump(), however, so you're good there. Src will be the entity that's doing the bumping, always. You then execute a proc you created , Bumped(), with O (the entity that's being bumped) as it's src, and src (the entity that's doing the bumping) as it's argument. Now, take a look at your Bumped() proc for your bat. You have the argument there for O, which, from before, will now be the entity that did the bumping (probably your player), but you never use it anywhere in your proc. You've used usr, however, which is most likely undefined, or irrelevant. Src, in the Bumped() proc, refers to the mob that was bumped, the bat. Since O is most likely your player, you probably just want to change all your usr's in Bumped(O) to O's. Before you do that though, change Bumped(O) to Bumped(mob/O). This is will let BYOND know that O, in this case, will always be a mob, and you won't get errors for undefined variables. Alternatively, you'd have to use the :, like you did in the Bump proc. (I'd advise you to change that to mob/O as well) Using the colon will prevent BYOND from picking up potential errors with your code at compile time, and may cause procs to crash during runtime.

Hopefully this has been helpful to you. A bit more than "no usr proc ungh"
In response to DerDragon
Okay, I get what your saying. And yes, it did help alot more. Thanks.
This is really getting on my nerves, I did what Der said and I get no where..

mob
Bat
name = "Bat"
icon = 'turf/Enemies.dmi'
icon_state = "bat"
powerlevel = 10
str = 3
end = 2
agi = 1
exp = 5
Bumped(mob/M)
M.lock = 1
M.loc = src.loc
M.loc = locate(src.x,src.y-3,src.z)
M.dir = NORTH
M.inbattle = 1
if(M.agi > src.agi)
M.AttackPanel()
else
M.MonsterAttack()
proc
AttackPanel()
src.isturn = 1

MonsterAttack(mob/M)
var/attack = rand(1,5)
if(attack == 5)
var/damage = src.str * 3
//Error
M << "<font color=green>The [src] [pick("hit","damaged","attacked")] [M.player] with a critcal for [damage]!</font>"
M.powerlevel -= damage
M.AttackPanel()
else
var/damage = src.str * 2
//Error
M << "<font color=green>The [src] [pick("hit","damaged","attacked")] [M.player] for [damage]!</font>"
M.powerlevel -= damage
M.AttackPanel()
if(attack == 3)
M << "<font color=green>The [src] missed!</font>"
M.AttackPanel()

Death(mob/M)
if(src.powerlevel <= 0)
M.exp += src.exp
M.gold += src.gold
M.LevelUp()
M.lock = 0
del src

LevelUp()
if(src.exp == src.neededexp)
src << "<font color=green>You have gained a level! Your level is now [src.level]!</font>"
src.level += 1
src.powerlevel += rand(50,100)
src.str += rand(1,5)
src.end += rand(1,3)
src.stmmax += rand(1,2)
src.agi += rand(1,3)

Bumped(mob/M)
Bump(mob/M)
..()
if(ismob(M))
M:Bumped(src)


The error is:

runtime error: Cannot read null.player
proc name: MonsterAttack (/mob/proc/MonsterAttack)
source file: Battle System.dm,29
usr: Plagu3r (/mob/choose)
src: Plagu3r (/mob/choose)
call stack:
Plagu3r (/mob/choose): MonsterAttack(null)
Bat (/mob/Bat): Bumped(Plagu3r (/mob/choose))
Plagu3r (/mob/choose): Bump(Bat (/mob/Bat))
Plagu3r (/mob/choose): Move(Dragonball: Self Proclaimed (20,74,2) (/turf/grass), 1)

If anyone could maybe show me a working example or anything like that, that would be greatly appreciated.
In response to Plagu3r
wich line is 29...?
In response to Mysame
I don't know, maybe the line after the //Error..
In response to Plagu3r
Those are 2 blank lines. And even if it's AFTER the blank part, it are still 2.
In response to Mysame
It could be either on, I did count the lines. You can't figure out that M.player is null.player?
In response to Plagu3r
'Kay then, first off all:
What's the M.player?
Second:
The Mysame hit Plagu3r. Doesn't sound right, does it?

Clearly M isn't a defined mob (duh), so it'd give an error on the M.powerlevel-= damage when you'd try to put it after //
In response to Mysame
First off, Bumped(mob/M).
Second off, its not a PvP system. It's a god damn monster system. Check the code.

Here is a breakdown:

M.player is the name of the player. I was going to use name but have a problem with the logout telling the world the ckey has logged out.

Next, "The [M]" sounds fine to me since you are fighting a monster. The [Bat], [Chicken], etc.

And clearly mob/M is defined, its the mob/player that bumps into the src.
In response to Plagu3r
I think one of your main problems is, like me when I first started, you're confused about how processes send information along. I notice you fed mob/M through the Bump, to Bumped, but it never made it to MonsterAttack(). Not to mention, I think your feeding of the variable was slightly backwards. The processes you're running are mob ran processes. When a process is ran by a mob, that mob is already a variable in the process (src). So any remaining variables (such as monsters its attacking) will need to be fed on to the process.

Let's see if I can help break it down for you.

The bat bumps the mob..
Bump(mob/M)//calls bump
..()//calls parent
if(ismob(M))//if M is a mob
src.Bumped(M)//have the BUMPER (the NPC in this case) call Bumped with M as the arguement


Now here's Bumped.
Bumped(mob/M)//Bumped, the enemy being the src (since it called the proccess), M being a player
M.lock = 1// Sets all vars and such for the mob that got bumped (namely, the player)
M.loc = src.loc
M.loc = locate(src.x,src.y-3,src.z)
M.dir = NORTH
M.inbattle = 1
if(M.agi > src.agi)
M.AttackPanel() // I'm not sure what this is for, so I probably set it up wrong.
else
src.MonsterAttack(M)//Have the monster call the process with the player as the arguement.

/*Before, you were having the player call MonsterAttack (M.MonsterAttack()),
but it's much better if called by the attacking monster*/


Now the MonsterAttack(mob/M) process might be able to work right, since it's actually getting an arguement in the place of M.
I can't guarantee that a copy/paste of this will work, and I wouldn't recommend it. Hope this helps, and if anything is unclear, feel free to ask.

-Edit-

To Lou, below:
I agree, wholeheartedly. That'd be like going..
"Oh, there's a problem with that code, right there." And walking away. Your advice is absolutely pointless, if they don't know what the hell you're talking about.
I don't use that phrase unless I follow it up with an explanation.
In response to Detnom
You know what? Please, PLEASE stop the "Ugh, don't use usr in proc" crap.
In response to Lou
Lou wrote:
You know what? Please, PLEASE stop the "Ugh, don't use usr in proc" crap.

It's generally quite good advice.
In response to Elation
Elation wrote:
Lou wrote:
You know what? Please, PLEASE stop the "Ugh, don't use usr in proc" crap.

It's generally quite good advice.
Yeah, but it's pointless when you're talking to someone who's new, and has no idea wtf you're talking about.
Some people say that in reference to input() being done wrong, for example. Any new person's going to look at the code and say... "... Where am I using usr..?" and if anything, just get frustrated at the lame, open ended advice given to them. If you're going to take the time to post something like that, why not at least help the person with something that makes some sense?

I have nothing against the phrase, unless it's all by itself. Utterly pointless.
In response to Detnom
mob
Bat
name = "Bat"
icon = 'turf/Enemies.dmi'
icon_state = "bat"
powerlevel = 10
str = 3
end = 2
agi = 1
exp = 5
Bumped(mob/M)
M.lock = 1
M.loc = src.loc
M.loc = locate(src.x,src.y-3,src.z)
M.dir = NORTH
M.inbattle = 1
if(M.agi > src.agi)
M.AttackPanel(M)
else
src.MonsterAttack(M)
proc
AttackPanel(mob/M)
M.isturn = 1

MonsterAttack(mob/M)
var/attack = rand(1,5)
if(attack == 5)
var/damage = src.str * 3
M << "<font color=green>The [src] [pick("hit","damaged","attacked")] [M.player] with a critcal for [damage]!</font>"
M.powerlevel -= damage
M.AttackPanel()
else
var/damage = src.str * 2
M << "<font color=green>The [src] [pick("hit","damaged","attacked")] [M.player] for [damage]!</font>"
M.powerlevel -= damage
M.AttackPanel()
if(attack == 3)
M << "<font color=green>The [src] missed!</font>"
M.AttackPanel()

Death(mob/M)
if(src.powerlevel <= 0)
M.exp += src.exp
M.gold += src.gold
M.LevelUp()
M.lock = 0
del src

LevelUp()
if(src.exp == src.neededexp)
src << "<font color=green>You have gained a level! Your level is now [src.level]!</font>"
src.level += 1
src.powerlevel += rand(50,100)
src.str += rand(1,5)
src.end += rand(1,3)
src.stmmax += rand(1,2)
src.agi += rand(1,3)

Bumped(mob/M)
Bump(M)
..()
if(ismob(M))
src.Bumped(M)


Now when you walk into the bat it does nothing at all. And the AttackPanel() adds the Attack Panel. Just for reference, this the AttackPanel():

        if(usr.isturn == 1)
statpanel("Attack")
stat("Double click an attack to execute.")
stat(new/obj/Ki/KiBlast)
else
return
In response to Plagu3r
Oh, crap. That was completely my fault.

I thought the BAT was bumping into the person, not the other way around. -.- Why don't you have it working that way?

-Edit-

It should work this way, then:
Bump(M)
..()
if(ismob(M))
M.Bumped(src)//have the monster call Bumped with src as the argument


But you'll find that when you bump into other players, it tries to call Bumped. You might want to add a check, for if M is an NPC.
Page: 1 2