[FIXED] OnEquip script fires on server re-start.

Here we stuff all the bugs we've managed to squash/squish/squelch.
Locked
stranf
UOX3 Guru
Posts: 939
Joined: Wed Jan 04, 2006 3:59 pm
Has thanked: 0
Been thanked: 0

OnEquip script fires on server re-start.

Post by stranf »

I noticed a bug with my magic weapons script and I'm not sure how to fix this.

Apperently, when your PC logs into the world, he "re-puts on" his/her clothing and weapons. This fires the "on-equip" script. Problem is, is if you never take them off, the "on-unequip" never fires.

The result?

As long as my PC wears his gloves of strength, every time the server re-starts the strength increase is permenant. I went from 79 str to 94 by simply loading UOx3 (for debug purposes) 14 times. I wasn't even logged into my PCs account.

Anyway I can fix this? This could be a terrible exploit for nearly all my magic weapon scripts.
stranf
UOX3 Guru
Posts: 939
Joined: Wed Jan 04, 2006 3:59 pm
Has thanked: 0
Been thanked: 0

Post by stranf »

I just logged into an account of a player who had his accuracy sword equipped for a server restart. As far as I can tell, his tactics was not permenantly increased.

This seems to be an issue with either attributes only, or related specifically to armor and not weapons.
Grimson
Developer
Posts: 802
Joined: Sat Jun 04, 2005 1:52 am
Location: Germany
Has thanked: 0
Been thanked: 0

Post by Grimson »

stranf wrote:Apperently, when your PC logs into the world, he "re-puts on" his/her clothing and weapons. This fires the "on-equip" script. Problem is, is if you never take them off, the "on-unequip" never fires.
I guess this happens when the char is load on world loads, I'll have a look at this tomorrow.
stranf wrote:Anyway I can fix this? This could be a terrible exploit for nearly all my magic weapon scripts.
You could eighter check the .online property, or check if the .socket property is not NULL, and only add the bonus when the player is online.
stranf
UOX3 Guru
Posts: 939
Joined: Wed Jan 04, 2006 3:59 pm
Has thanked: 0
Been thanked: 0

Post by stranf »

Thanks for checking into this.

The question is, is when does "dressing" the PC occur? If it occurs during worldstart, having a if "PC.online == true" check would bypass the entire issue.

If the "dressing" occurs when the PC logs in, then I'd have the same problem.

I could test this myself, and quickly write a "is online" check.

What is the correct syntax?

mChar.online = 1?
Grimson
Developer
Posts: 802
Joined: Sat Jun 04, 2005 1:52 am
Location: Germany
Has thanked: 0
Been thanked: 0

Post by Grimson »

stranf wrote:Thanks for checking into this.

The question is, is when does "dressing" the PC occur? If it occurs during worldstart, having a if "PC.online == true" check would bypass the entire issue.
After a quick look, it happens when the world get's loaded and not when the PC logs in. As the "dressing" is the same for PCs and NPCs, and NPCs will never log in ;).

Edit: Forgot the second answer:
stranf wrote: I could test this myself, and quickly write a "is online" check.

What is the correct syntax?

mChar.online = 1?
There are two ways, I prefer this at the beginning of the function:

Code: Select all

if( !mChar.online ) 
      return;
Means if the char isn't online just abort here.

You could also use

Code: Select all

if( mChar.online )
{
     do some stuff only when the char is online
}
stranf
UOX3 Guru
Posts: 939
Joined: Wed Jan 04, 2006 3:59 pm
Has thanked: 0
Been thanked: 0

Post by stranf »

I like your first way, I originally tried:

If (mChar.online == true)
{

}

which added unnessary brackets.
giwo
Developer
Posts: 1780
Joined: Fri Jun 18, 2004 4:17 pm
Location: California
Has thanked: 0
Been thanked: 0

Post by giwo »

Grimson, if this is happening at world load, it is probably happening when the item is created (and thus layer and container is set). Try adding a IsPostLoaded() check around the OnEquip call, this should fix the issue.

Also, just to note... that online check will mean that NPC's don't gain the benefit of the items.
Scott
Grimson
Developer
Posts: 802
Joined: Sat Jun 04, 2005 1:52 am
Location: Germany
Has thanked: 0
Been thanked: 0

Post by Grimson »

giwo wrote:Grimson, if this is happening at world load, it is probably happening when the item is created (and thus layer and container is set). Try adding a IsPostLoaded() check around the OnEquip call, this should fix the issue.
Will do it with my next commit.
giwo wrote:Also, just to note... that online check will mean that NPC's don't gain the benefit of the items.
Good point, I didn't think of that.
stranf
UOX3 Guru
Posts: 939
Joined: Wed Jan 04, 2006 3:59 pm
Has thanked: 0
Been thanked: 0

Post by stranf »

giwo wrote:
Grimson, if this is happening at world load, it is probably happening when the item is created (and thus layer and container is set). Try adding a IsPostLoaded() check around the OnEquip call, this should fix the issue.


Will do it with my next commit.
Grimson, shoot me a PM when this change is available, and I'll switch to my original script and debug.
Also, just to note... that online check will mean that NPC's don't gain the benefit of the items.
Yeah, I thought of that. In the meantime I'm surviving my just making the NPCs tough with the GM. IE: 'set tactics 1200, instead of 1000.
Locked