• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.
Resource icon

[TFS 1.4.2] Item Rental System! 2024-05-31

No permission to download
Note that I have implemented a block so that if an item has a custom 'owner' attribute, it cannot be moved to the ground or the trash. Items inside a backpack with the custom 'owner' attribute also cannot be moved along with the backpack. If the backpack contains normal items without the custom 'ownerGuid' attribute, it can be moved normally. Additionally, I have added a check to prevent these items from being moved to the depot. This should resolve all the issues.

View attachment 84992
See another quick GIF: one item was rented and is using the custom attribute 'ownerGuid', and another item is normal and not using the custom attribute 'ownerGuid'.

View attachment 84993
Check when the client player logs out and stays offline for some time. The item should be able to return to the owner
View attachment 85020

When both the player client and the owner are offline, the system should be able to verify and return the original item to the owner's depot. This is working correctly

View attachment 85021


I've already updated the file there. Just download and review the script. If someone can look at it and correct any optimizations needed, let me know, and I'll try to fix it. I would appreciate any help as I'm still learning TFS 1.x. xD.

I tested with the player client dying multiple times, and the item returned to the owner normally. I also set up the database to store the rental item and handle real-time expiration, removing the item directly from the database both offline and online normally.
Just a few things from a brief look at the new code:
1) Move containsCustomOwner outside of the callback, there is no need to re-define this function everytime the event callback is executed.
2) This recursion now happens everytime someone moves any item in the game. As I suggested earlier, it's better to only execute this whole callback for players that have rented an item. On login (if an active rental is assigned via the new rental db table), or when an item is rented, register an event to the player, and check if this event is present in the onMoveItem. This will minimise the amount of recursion checks being made.

I'll check it out more in detail tomorrow (it's very late here right now)
 
Just a few things from a brief look at the new code:
Thank you for reviewing the script and providing feedback. I was getting tired, and it was getting to my head. Thanks again. I'll be waiting for further updates. Thanks.
Post automatically merged:

Improved a bit as you suggested, take a look to see if it's correct, and if it's not, I'll wait for you to review and correct it. Thanks for the correction, thx!
 
Last edited:
Thank you for reviewing the script and providing feedback. I was getting tired, and it was getting to my head. Thanks again. I'll be waiting for further updates. Thanks.
Post automatically merged:

Improved a bit as you suggested, take a look to see if it's correct, and if it's not, I'll wait for you to review and correct it. Thanks for the correction, thx!
This will still execute the event callback for everyone. Register the event "blockRentalItemMove" (onLogin), and then inside the onMoveItem eventcallback, loop through the player's events and check for that event. If it doesn't exist, just return NOERROR so it doesn't execute the rest of the callback.

You can also limit 1 in the onLogin SQL query.
 
This will still execute the event callback for everyone. Register the event "blockRentalItemMove" (onLogin), and then inside the onMoveItem eventcallback, loop through the player's events and check for that event. If it doesn't exist, just return NOERROR so it doesn't execute the rest of the callback.

You can also limit 1 in the onLogin SQL query.
Why the loop. Just use global table if hasRentedItem[pid] then.
 
Back
Top