ID:264040
 
Code:
mob
proc/UserDcheck(mob/M)
if(M.hp<=0 && M.monster == 0 && src.gym1poke == 0)
if(M.tourny == 0)
M<<"<I><small><font color = white><font face = 'Comic Sans MS'>You died!"
M.hp=M.maxhp
M.loc=locate(1,3,1)
M.PK=0
if(M.hp <= 0 && M.monster == 0 && src.gym1poke == 0)
if(M.tourny == 1)
FightFinish(M)
if(src.hp < 0 && src.monster == 1 && src.gym1poke == 0)
respawn(src.type, src.loc, 100)
del(src)
if(src.hp<=0 && src.monster == 0 && src.gym1poke == 0)
usr.hp=M.maxhp
usr.loc=locate(1,3,1)
else
if(src.hp < 0 && src.monster == 1 && src.gym1poke == 1)
del(src)
view(8) << "Sky: Nice work, you've proven yourself worthy for the Swift Badge, with this badge you may now cut down the tree's blocking the path to Absolife city. Good Luck."
usr.contents+= new/obj/Badges/Swift_Badge


    verb
Tackle()
set category = "Pokemon"
for(var/mob/M in get_step(usr,usr.dir))
var/dmg = rand(src.strength-M.defense,src.strength)
if(src.Pokemon == 1 && M.Battle == 1 && dmg > 0 && src.Tackle_Again == 0 && src.tourny == 0)
usr << "<font face = 'Comic Sans MS'><font color=red>You Tackle [M.name] for [dmg] HP!"
M << "<font color = white><font face = 'Comic Sans MS'>[src] Tackles you for [dmg] damage!!"
s_damage(M,dmg,"white")
usr.Tackle_Again = 1
sleep(usr.speed)
usr.Tackle_Again = 0
if(M.hp <= 0 && M.monster == 0 && M.tourny == 0)
usr << "<font face = 'Comic Sans MS'><font color=red><b><i>You have defeated [M.name]!"
usr.exp += rand(30,35)
M.hp = M.maxhp
M.loc = locate(1,3,1)
M.Battle = 0
UserDcheck(M)
if(usr.exp >= usr.expneeded && usr.monster == 0 && usr.tourny == 0)
usr.LevelUp()
M << "<font face = 'Comic Sans MS'><font color=red><i>You fainted!"
M.hp = M.maxhp
M.loc = locate(1,3,1)
M.Battle = 0

if(src.Pokemon == 1 && M.Battle == 1 && dmg > 0 && src.Tackle_Again == 0 && src.tourny == 1)
usr << "<font face = 'Comic Sans MS'><font color=red>You Tackle [M.name] for [dmg] HP!"
M << "<font color = white><font face = 'Comic Sans MS'>[src] Tackles you for [dmg] damage!!"
s_damage(M,dmg,"white")
usr.Tackle_Again = 1
sleep(usr.speed)
usr.Tackle_Again = 0
if(M.hp <= 0 && M.monster == 1 && M.gym1poke == 1 && M.tourny == 0)
usr << "<font face = 'Comic Sans MS'><font color=red><b><i>You have defeated [M.name]!"
UserDcheck(M)
if(M.hp <= 0 && M.monster == 0 && M.tourny == 0)
usr << "<font face = 'Comic Sans MS'><font color=red><b><i>You have defeated [M.name]!"
usr.exp += rand(30,35)
M.hp = M.maxhp
M.loc = locate(1,3,1)
FightFinish()
M.Battle = 0
UserDcheck(M)
if(usr.exp >= usr.expneeded && usr.monster == 0 && usr.tourny == 1)
usr.LevelUp()
M << "<font face = 'Comic Sans MS'><font color=red><i>You fainted!"
M.hp = M.maxhp
FightFinish()
M.loc = locate(1,3,1)
M.Battle = 0

if(M.Battle == 1 && usr.monster == 0 && dmg > 0)
M.hp -= dmg
if(usr.level >= 10 && usr.Battle == 1)
usr.exp += rand(50,75)
if(usr.exp >= usr.expneeded)
usr.LevelUp()
return

if(usr.level >= 20 && M.Battle == 1)
if(src.Pokemon == 1 && usr.monster == 0)
usr.exp += rand(150,200)
if(usr.exp >= usr.expneeded)
usr.LevelUp()
return

if(M.Battle == 0 && usr.monster == 0)
usr << "<font face = 'Comic Sans MS'><font color=white>You must be in a battle zone to battle, ask a moderator for more info on battle zones."
return

if(dmg < 1 && M.Battle == 1)
usr << "<font face = 'Comic Sans MS'><font color=white>Your move was uneffective."
return


mob
Skys_Pidgeotto
icon = 'Pidgey.dmi'
name = "Sky's Pidgeotto"
icon_state = "3"
desc = "Gym 1"
hp = 3000
Pidgey = 1
gym1poke = 1
maxhp = 3000
player = 0
strength = 100
Expg = 2
level = 70
monster = 1
Pokemon = 1
PK = 1
NPC = 0
New()
. = ..()
spawn()
Wander()
proc/Wander()
while(src)
var/mob/Pokemon/P = locate() in oview(src)
if(P)
step_towards(src,P)
else
step_rand(src)
sleep(5)

sleep(5)
spawn(5)
Wander()
Bump(mob/Pokemon/M)
if(ismob(M))
Fight(M)
..()
else
return
proc/Fight(var/mob/Pokemon/M)
var/damage = src.strength
if(src.hp<=0 && src.desc == "Gym 1")
usr.BeatGym1 = 1
usr << "<font color = white><font face = 'Comic Sans MS'> You recieved a Swift Badge from Blake"
UserDcheck(src)
if(src.hp<=0 && src.monster == 1)
usr.BeatGym1 = 1
usr << "<font color = white><font face = 'Comic Sans MS'> You recieved a Cheri berry from [src]'s drop."
UserDcheck(src)
else
if(M.hp <= 0 && M.monster == 0)
M.hp -= damage
M << "<font color = white><font face = 'Comic Sans MS'>[src] attacks you for [damage] damage!!"
src<<"<font color = white><font face = 'Comic Sans MS'>You attack [M] for [damage] damage!!"
UserDcheck(M)
if(M.hp >= 0 && M.monster == 0)
M.hp -= damage
M << "<font color = white><font face = 'Comic Sans MS'>[src] attacks you for [damage] damage!!"
src<<"<font color = white><font face = 'Comic Sans MS'>You attack [M] for [damage] damage!!"
UserDcheck(M)


Problem description: I'm trying to make npc gym leaders that creates a pokemon with the variable, gym1poke = 1, and i'm trying to make it so if you defeat the pokemon it
will give that pokemon the badge(Swift Badge) when it is defeated, but for some reason It won't give the player the badge, and won't say what Sky is supposed to say to the player. Any help with this? The codes in order are, The death code, The Tackle code, and the Pidgeotto with the gym1 poke = 1 variable.
That's incredibly hard to read. Can you clean it up by changing your if(somevar==0) to if(!somevar) and if(somevar==1) to if(somevar). They do the same thing, and makes it look less messy.
In response to Jeff8500
Yeah, Its just that I learned basic coding off a tutorial that used the == 0, or == 1 vars. I'll to fix it,but what code are you talking about?
In response to Element Hero creator
All the code with the long if procs. They get distracting >_>
In response to Jeff8500
K.
In response to Element Hero creator
Also, instead of using...

        if(M.hp<=0 && M.monster == 0 && src.gym1poke == 0)
if(M.tourny == 0)
M<<"<I><small><font color = white><font face = 'Comic Sans MS'>You died!"
M.hp=M.maxhp
M.loc=locate(1,3,1)
M.PK=0
if(M.hp <= 0 && M.monster == 0 && src.gym1poke == 0)
if(M.tourny == 1)
FightFinish(M)


Use

        if(M.hp<=0 && M.monster == 0 && src.gym1poke == 0)
if(M.tourny == 0)
M<<"<I><small><font color = white><font face = 'Comic Sans MS'>You died!"
M.hp=M.maxhp
M.loc=locate(1,3,1)
M.PK=0
else
FightFinish(M)



Didn't notice that until after you posted.
In response to Jeff8500
:/ It doesn't feel the same when I change it and I'm gonna get confused, so I'm not gonna change it.
Also, your tackle code is incredibly inneficient. Try setting up a few procs to handle everything so you don't reuse it. If you use that for every attack, you would probably hit BYOND's max resource limit fast. For example...

mob/verb/Attack()
for(var/mob/M in get_step(usr,usr.dir))
usr.Damage(M,rand(1,10),"Dark")

mob/proc/Damage(var/mob/M,var/damage,var/type)
damage = round((src.attack-M.defense)+damage)
damage = M.effect_check(damage,type)
if(damage<=0)
src<<"You didn't hurt [M]. You, sir, fail."
return
M.HP-=damage
M.Death_Check(src)

mob/proc/effect_check(var/damage,var/type)
if(type in src.weaknesses) return damage*=2
else return damage //etc etc

mob/proc/Death_Check(var/mob/killer)
if(src.HP <= 0)
killer.exp+=9000
etc etc
del(src)


I did this fast, so it probably has mistakes and/or poor coding. It was just to give an example anyway though.

In response to Element Hero creator
You should. Kaioken gave some reasons in this post. http://www.byond.com/developer/forum/?id=639216
Oh yeah, I forgot the real problem xD. No usr in procs.
I'm surprised nobody in this thread caught this problem. It looks complex until you know where to look, then it's actually pretty simple:

        else
if(src.hp < 0 && src.monster == 1 && src.gym1poke == 1)
del(src)
view(8) << "Sky: Nice work, you've proven yourself worthy for the Swift Badge, with this badge you may now cut down the tree's blocking the path to Absolife city. Good Luck."
usr.contents+= new/obj/Badges/Swift_Badge


"del(src)" deletes the object this proc belongs to, instantly killing the proc in its tracks. No code after that line will be executed, so the easy fix is to put the line where you delete the object at the very end of this procedure.

Always be on the look out for bugs like this, as they can be hard to diagnose. It helps to use the text output to mark how far a given procedure is progressing until it stops working- in this case, you already knew it wasn't getting as far as the "Sky: Nice work..." line.

That's not to say you shouldn't fix your other problems like blatent usr abuse, mind. Remember: view() and related procedures default to usr!
Read this for more information. The important argument here is "Center".
In response to Elation
Like I said before, long if()'s get distracting >_>
In response to Elation
TY, God bless people like you Elation.
In response to Elation
:(. Another problem, now the player isn't getting the badge, it only says ...Nice work... can you help out with this?
In response to Element Hero creator
new/obj/Badges/Swift_Badge(M)
In response to Jemai1
Jemai1 wrote:
new/obj/Badges/Swift_Badge(M)

Thanks, but it didn't work either.
In response to Element Hero creator
Here's a thought:

In UserDcheck, what are src, usr, and M?
In response to Garthor
Ok I've managed to make it so it drops the badge, with this code.

        else
if(src.hp < 0 && src.monster == 1 && src.gym1poke == 1)
view(8) << "Nice work, you've proven yourself worthy for the Swift Badge, with this badge you may now cut down the tree's blocking the path to Absolife city. Good Luck."
new/obj/Badges/Swift_Badge(M.loc)
del(src)


And it gets located right under where the monster died it. I tried usr, src, M, and all of them lead under the where the pokemon died it. I need help with making sure that the player is M >,>
In response to Element Hero creator
Well, look at it this way. You've got a deathcheck() proc. It needs to know two mobs:

1) who is dying
2) who is killing

Now, you're using usr, src, and M. That's three. You need to remove one from the proc entirely, and then write it accordingly.

Hint: usr is not valid in procs.

Here's a properly written deathcheck():

mob/proc/deathcheck(var/mob/killer)
world << "[killer] killed [src]!"

mob/verb/kill(var/mob/M)
M.deathcheck(src)
In response to Garthor
Garthor wrote:
Well, look at it this way. You've got a deathcheck() proc. It needs to know two mobs:

1) who is dying
2) who is killing

Now, you're using usr, src, and M. That's three. You need to remove one from the proc entirely, and then write it accordingly.

Hint: usr is not valid in procs.

Here's a properly written deathcheck():

mob/proc/deathcheck(var/mob/killer)
> world << "[killer] killed [src]!"
>
> mob/verb/kill(var/mob/M)
> M.deathcheck(src)


Now I'm confused where you put M.deathcheck(src) so, are both of them dying? Look this is my current Deathcheck verb, can you give me some examples to fix it?

mob
proc/UserDcheck(mob/M)
if(M.hp<=0 && M.monster == 0 && src.gym1poke == 0)
if(M.tourny == 0)
M<<"<I><small><font color = white><font face = 'Comic Sans MS'>You fainted!"
M.hp=M.maxhp
M.loc=locate(1,3,1)
M.PK=0
else
FightFinish(M)
if(M.hp <= 0 && M.monster == 0 && src.gym1poke == 0)
if(M.tourny == 1)
FightFinish(M)
if(src.hp < 0 && src.monster == 1 && src.gym1poke == 0)
respawn(src.type, src.loc, 100)
del(src)
if(src.hp<=0 && src.monster == 0 && src.gym1poke == 0)
usr.hp=M.maxhp
usr.loc=locate(1,3,1)
else
if(src.hp < 0 && src.monster == 1 && src.gym1poke == 1)
view(8) << "Nice work, you've proven yourself worthy for the Swift Badge, with this badge you may now cut down the tree's blocking the path to Absolife city. Good Luck."
Assign_Swift_Badge()
del(src)
Page: 1 2