• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Help with referencing to items held by offline players

miens

Combos and Freedom
Joined
Nov 6, 2016
Messages
61
Reaction score
8
Hi!
In my ots I wanted to make a spell that would modify weapons attack value but only temporarily. So I Almost made it to work with
PHP:
weapon:setAttribute(ITEM_ATTRIBUTE_ATTACK, 100)
but then I need to take the bonus back after some time. So I decided to use addEvent for this.
PHP:
local parameters = {weapon = wpn, attack = atk, pl = player}
addEvent(UndoStatMod,1500,parameters)
And it was working fine. Until I realized that sever crashes if players logs out before the event fires. I suppose it is because I am referencing to item owned by player who is offline. In the event I added a simple if statement to check if player logged out after event was scheduled and if so the event did nothing. Server didnt crashed then but weapons attribute remained modified.

Does anyone have any idea how to for example modify the item back on player logout or login? Or maybe is there a way to change the item back even if it is held by offline player? Any help is appreciated.
 
The event should confirm the player is online before doing anything. And the code in the event should run onlogin as well, so it will deactivate the item onlogin if the player was offline during the addevent trigger.

If the item attribute has a duration of 1500 seconds, then you can add a storage value of os.time() + 1500 seconds when the attribute is activated. The onlogin can then see if current os.time() is greater than the storage value, in which case the attribute has expired and you can deactivate it.
 
When I save item.uid in storage value it works fine until a the players logs out. Then after he logs in apparently the item has different uid cause when i try to
PHP:
print(Item(player:getStorageValue(1690)))
it comes out as nil.
And player data is actually cleared BEFORE onLogout callback cause output of the above code is exactly the same if called from onLogout. (note: it works when called in spells script)
 
undostatmod
if player offline do nothing

creaturescript onlogout (or onlogin)
execute undoing stats
 
creaturescript onlogout (or onlogin)
execute undoing stats

Im saving item.uid in storage value. As long as player remains logged in executing Item(storagevalue) returns desired item just like it should. But in onLogout and onLogin it returns nil. Most likely because onLogout this item has been unloaded already and onLogin it has been loaded but was given different id.

Edit:
I played with item.uid a bit and got some interesting results. Turns out that when you modify attribute of an item its uid is increased by 1? or something like that. I think I can make my work around it and add one to the value I save with setStorageValue.
 
Last edited:
But theres another problem with this solution. What if player who casted a spell didnt logged out but gave the item to other player and that other player logged out? Server would crash again. Can I forbid player from unequiping item for some time?
 
you can give the item two different itemids (editing otb, xml), one version of the item with boosted attributes, and the other version without attributes, and just use the decay attribute on the boosted version
 
I want the spell to be castable on any weapon so this wont work. Is there an onUnequip event for player?
 
Hmm, tricky indeed. It makes sence that item.uid is not persistent. I think it is the same with creature id.
Perhaps @Evil Hero knows something here? He got some experience with custom item attributes as far as I know. Although its probably C++ modifications.
 
I found out that there is player event named onMoveItem. Does it triggers when player removes item from his hand? Will it come in handy in this situation?
 
Maybe you can add limitations, like make the effect only work while the weapon is equipped. (or onEquip or something)
You can also track which container slot the itemid is and load the item through itemslot instead of item.uid.

onlogout, you could store container slot in storage value instead of item.uid? That way you can find the correct item in onlogin. Even though the uid has changed.
 
ok I got it to work. When players casts a spell I modify the item and schedule the event. If event detects that player is offline it does nothing. Added on logout callback that modifies the item back to its original form. Then I enabled onMoveItem in events.xml and added an if statement there that forbids unequiping the weapon that is enchanted. Also added the same condition in onTradeRequest and onTradeAccept to prevent player from trading the item.

Thanks to all of the above there is no way player can remove the item from the hand and it will be automatically modified back if he logs out.

Thanks for help guys :)
 
Last edited:
ok I got it to work. When players casts a spell I modify the item and schedule the event. If event detects that player is offline it does nothing. Added on logout callback that modifies the item back to its original form. Then I enabled onMoveItem in events.xml and added an if statement there that forbids unequiping the weapon that is enchanted. Also added the same condition in onTradeRequest and onTradeAccept to prevent player from trading the item.

Thanks to all of the above there is no way player can remove the item from the hand and it will be automatically modified back if he logs out.

Thanks for help guys :)

If he dies, will the items transfer to his corpse ondeath before onlogout? You may want to make sure other people can't obtain the enchanted version of the item if they kill the player before it has expired. :p
 
OH GOD, PLEASE STOP!!

This is the worst way imaginable to do what you are trying to do.

Here is how I would do it:
  1. Make a script for all weapons in your game and add it to weapons.xml (you can just call it melee.lua)
  2. Make your spell give the player a storage value
  3. have the weapon script check the storage value, if it is 1, increase the attack.
  4. Set it so when the player logs in, the storage value is set back to -1
  5. Problem solved.
If you want a specific item to change, you can do it similar to enchant staff. Where the item changes into another item, then decays back to the original after a duration.

Otherwise, changing an item is SO EASY for players to abuse. If you change an item, and want to change it back later, there are so many ways players can abuse this.

The only option I can imagine would be have a onEquip script that checks any item you equip to see if it has the bonus, and if it does, remove it. (This would fix most all issues as well)
 
Last edited:
If he dies, will the items transfer to his corpse ondeath
oh yes forgot about that case. I have to apply my nazi scripting there as well thanks for pointing this out :)

This is the worst way imaginable to do what you are trying to do.
I agree that the solution Cipsoft came out with is much cleaner and easier. But it doesn't scale at all. Right now with my system I can virtually modify any items attribute temporarily, and there is no way user can abuse it (unless you see a way then please point it out). With solution proposed by you I would have to add new weapons.xml EACH TIME I want to make different spell that modifies weapon.
 
Back
Top