ID:148176
 
I have in my game where you run into a monster to fight it. And to make it so that not more than 1 person fights a monster, I have a code to stop you, and the monster from moving. Well, if people log out in combat, the monster stays frozen and no one can fight it. This is a problem because some monsters are blocking your path, and people get d/ced and now no one can get passed without me rebooting, and sometimes i'm not there. Here's a monster's code:

mob
monster
Slime
icon = 'slimes.dmi'
icon_state = "blue"
name = "Slime"
hp = 6
mp = 0
expreward = 3
jobexpreward = 0
gold = 2
attack = 5
defense = 2
intelligence = 5
agility = 4
Bumped(O)
if(src.islocked == 1)
usr << "<font color = blue><b>Someone is already fighting this monster!"
else
usr.islocked=1
src.islocked=1
Battle(O)


and heres the logout code(if it will help):

mob
Logout()
if(usr.lib == 1)
src.islocked = 0
if(src.color == null)
return ..()
world << "<font color = teal><b>[src.name]([src.key]) logs out."//tell the world the client logged out
usr.savex = usr.x
usr.savey = usr.y
usr.savez = usr.z
..()


The var lib is made 1 when u enter combat.
In your battle code(somewhere that repeats each attack loop), check for if(!O.client). Under that if, put in code such as src.islocked = 0.
In response to Jon88
I made the whole code, i never put that in, where should i put it(do u want a copy of my attack code?)
In response to Metroid
That would be helpful.
usr is not safe in Logout(), and you should by no means be using it in Bumped().

Lummox JR
In response to Lummox JR
Yes, but that's not his current problem.(although it does need fixing)
In response to Jon88
Jon88 wrote:
Yes, but that's not his current problem.(although it does need fixing)

First rule of debugging: Fix the obvious problems first; they tend to clutter up the bigger problems and make them impossible to fix.

Actually this one is a pretty easy fix to make based on the value you assign to the islocked var. The problem is essentially a design flaw: Too many authors have a lack of imagination when it comes to using vars, so they set up a var to have a simple yes/no value when it should be providing more information than that. Information such as, for example, who they're fighting.

Lummox JR
In response to Jon88
Here:

Attack(mob/M)
var
chancetohit = rand(0,10)
damage = (M.attack - src.defense) + rand(-5,5)
luckchance = rand(0,19)
hitchance = rand(0,3)
critdamage = damage * 3 - rand(-10,10)
if(chancetohit == 5)
M << "<b><font color = blue>You attack the [src]!"
M << 'attack.wav'
sleep(10)
M << "<b><font color = blue>You missed!"
M << 'dodge.wav'
sleep(10)
NPCDeathCheck(M)
else if(damage <= 0)
M << "<b><font color = blue>You attack the [src]!"
M << 'attack.wav'
sleep(10)
if(hitchance == 1)
M << "<b><font color = blue>You barely hit the [src] hitting it for 1 HP!"
M << 'hit.wav'
src.hp -= 1
else
M << "<b><font color = blue>The [src] dodges the attack!"
M << 'dodge.wav'
sleep(10)
NPCDeathCheck(M)
else if(luckchance == 10)
M << "<b><font color = blue>You attack the [src]!"
M << 'attack.wav'
sleep(10)
M << "<b><font color = blue>Critical hit!"
M << 'criticalhit.wav'
sleep(10)
if(chancetohit == 5)
M << "<b><font color = blue>You miss!"
M << 'dodge.wav'
sleep(10)
NPCDeathCheck(M)
else if(critdamage <= 0)
M << "<b><font color = blue>The [src] dodges your attack!"
M << 'dodge.wav'
sleep(10)
NPCDeathCheck(M)
else
M << "<b><font color = blue>You hit the [src] for [critdamage] HP!"
M << 'hit.wav'
src.hp -= critdamage
sleep(10)
NPCDeathCheck(M)
else
M << "<b><font color = blue>You attack the [src]!"
M << 'attack.wav'
sleep(10)
M << "<b><font color = blue>You hit the [src] for [damage] HP!"
M << 'hit.wav'
src.hp -= damage
sleep(10)
NPCDeathCheck(M)
In response to Metroid
Attack(mob/M)
> var
> chancetohit = rand(0,10)
> damage = (M.attack - src.defense) + rand(-5,5)
> luckchance = rand(0,19)
> hitchance = rand(0,3)
> critdamage = damage * 3 - rand(-10,10)
>//Changes start here
> if(!M.client)
> src.islocked = 0
> return 0
>//Changes end here
> if(chancetohit == 5)
> M << "<b><font color = blue>You attack the [src]!"
> M << 'attack.wav'
> sleep(10)
> M << "<b><font color = blue>You missed!"
> M << 'dodge.wav'
> sleep(10)
> NPCDeathCheck(M)
> else if(damage <= 0)
> M << "<b><font color = blue>You attack the [src]!"
> M << 'attack.wav'
> sleep(10)
> if(hitchance == 1)
> M << "<b><font color = blue>You barely hit the [src] hitting it for 1 HP!"
> M << 'hit.wav'
> src.hp -= 1
> else
> M << "<b><font color = blue>The [src] dodges the attack!"
> M << 'dodge.wav'
> sleep(10)
> NPCDeathCheck(M)
> else if(luckchance == 10)
> M << "<b><font color = blue>You attack the [src]!"
> M << 'attack.wav'
> sleep(10)
> M << "<b><font color = blue>Critical hit!"
> M << 'criticalhit.wav'
> sleep(10)
> if(chancetohit == 5)
> M << "<b><font color = blue>You miss!"
> M << 'dodge.wav'
> sleep(10)
> NPCDeathCheck(M)
> else if(critdamage <= 0)
> M << "<b><font color = blue>The [src] dodges your attack!"
> M << 'dodge.wav'
> sleep(10)
> NPCDeathCheck(M)
> else
> M << "<b><font color = blue>You hit the [src] for [critdamage] HP!"
> M << 'hit.wav'
> src.hp -= critdamage
> sleep(10)
> NPCDeathCheck(M)
> else
> M << "<b><font color = blue>You attack the [src]!"
> M << 'attack.wav'
> sleep(10)
> M << "<b><font color = blue>You hit the [src] for [damage] HP!"
> M << 'hit.wav'
> src.hp -= damage
> sleep(10)
> NPCDeathCheck(M)


Assuming that the Attack proc gets called again from the deathcheck, that should work. What it does is if the player(M), doesn't have a client attacked to it(ie: logged out), it sets islocked to 0 and ends the attack proc. I don't understand why you have it calling the Battle() proc in your code, but posted a Attack() proc. The code I changed should end up in your Battle() proc, since that's what you called earlier.
In response to Jon88
See, what happens is when u start combat, it asks what u want to do (Battle proc) and u choose and it goes to the Attack proc(what I posted) then when all that stuff is done, it checks to see if the NPC is dead, if he is, then it ends, if it isnt, then it goes to enemy attack which then goes to check if your dead, if you are stuff happens, if you arent, it goes back to the battle proc for your command again.

Either way, my attack code, is it fixed?
In response to Metroid
The thing is that code has to be called for it to do anything. Since the NPC seems to be waiting for the player to choose what to do before attacking, probably not. Since if the player goes, the code doesn't get called.
In response to Jon88
But the problem here is, How Do I Fix The Problem?
In response to Metroid
maybe del the NPC when the player who is fighting it logs out... then have it reappear when the player logs back in....