• 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!

Lua Little help with this system

icekis

Member
Joined
Jan 18, 2018
Messages
91
Reaction score
5
Hello to everyone!

I am trying to make one trade premium days script using talkactions + creaturescripts with TFS 0.4

The script is working perfectly, but i got a problem and i would like your help.

Lua:
function onSay(cid, words, param, param2, channel)

local t = string.explode(param, ",")
local target = getCreatureByName(t[1])
local points = tonumber(t[2])
local item = 1968
local storage = 2122

if(param == '') then
    return doPlayerSendTextMessage (cid, MESSAGE_INFO_DESCR, '!tradepremium name days')
end

if (target ~= nil) and isPlayer(target) then
    if (points ~= nil) and (type(points) == 'number') and (points>1) then
                    if getPlayerTradeState(cid) >= 1 then
                return false
            end
                    if getPlayerPremiumDays(cid) > points then
                        local addItem = doPlayerAddItem(cid, item, 1)
                        doItemSetAttribute(addItem, "description", "trasfer premium days")
                        doStartTrade(cid, target, addItem)
                        setPlayerStorageValue(cid, storage, points)
                    else
                        return false
                    end
    else
        return false
    end
else
return false
end

return true
end

when i type !tradepremium name days, script creates an item (1968) and starts a trade window with the target. If I accept the trade action, itemID 1968 will be transferred from player(cid) to the target, but if i cancel the trade action itemID 1968 will remain in the player's(cid) backpack and I would like it to disappear.

Could someone help me?
 
Last edited:
Solution
You can set a new duration to an item created this way, and make it start decaying so if it's not used until a certain time, it will disappear.

Lua:
 doItemSetAttribute(addItem, "duration", 3600)
doDecayItem(addItem)

Alternatively, if you want more control over what happens with the item, you can assign some timestamp to the item (generated by os.time()) and add it to the item via doItemSetAttribute.
Now, I don't know for sure if 0.4 doItemSetAttribute allows custom named attributes by default. You should check this.
If yes, you can do:
Lua:
doItemSetAttribute(addItem, "myTimeStamp", os.time())

If not, you can always use the "specialdescription" attr to store this timestamp there.

In the action...
Unless you have some way to detect when the trade is cancelled, I don't see a way around the issue with the way your script is currently.

You'd have to think of another way to have a mutual trade between players.
 
Last edited:
Rules for the Support board
#5

But yeah, unless you have some way to detect when the trade is cancelled, I don't see a way around the issue with the way your script is currently.

You'd have to think of another way to have a mutual trade between players.

Hello @Xikini !

I've changed the topic saying that i use TFS 0.4.



Well, I already expected an answer like yours for my my issue.

I was testing some TFS 0.4 functions and i changed

Lua:
local addItem = doPlayerAddItem (cid, item, 1)

to

Code:
local addItem = doCreateItemEx (item)

No item was created in my backpack. Simply generated a trade window with item (1968).

My problem now is if the action is completed, item(1968) appears in the target's backpack, and then the server crash.



I think about using an addevent to remove item(1968) using onTradeAccept but I'm not sure how to use those functions
 
Last edited:
Hello @Xikini !

I've changed the topic saying that i use TFS 0.4.



Well, I already expected an answer like yours for my my issue.

I was testing some TFS 0.4 functions and i changed

Lua:
local addItem = doPlayerAddItem (cid, item, 1)

to

Code:
local addItem = doCreateItemEx (item)

No item was created in my backpack. Simply generated a trade window with item (1968).

My problem now is if the action is completed, item(1968) appears in the target's backpack, and then the server crash.



I think about using an addevent to remove item(1968) using onTradeAccept but I'm not sure how to use those functions
Yeah, like I said the way it's currently scripted, it's not feasible.

I'm having to assume that this item gives the other person x number of days when they use the item.
Why not just have the talkaction create the item, and then have the action script give the days?
Let the players do the trading manually.

At least that's the way I'd do it.
 
Yeah, like I said the way it's currently scripted, it's not feasible.

I'm having to assume that this item gives the other person x number of days when they use the item.
Why not just have the talkaction create the item, and then have the action script give the days?
Let the players do the trading manually.

At least that's the way I'd do it.


Good point.

Some time ago i did it this way, but the player can remove his days of premium and save for many time. If i make this exchange imediatly he will spend his premium days, you know?

Would it be possible create an item that if not used, go discounting premium days that were assigned to it?
 
You can set a new duration to an item created this way, and make it start decaying so if it's not used until a certain time, it will disappear.

Lua:
 doItemSetAttribute(addItem, "duration", 3600)
doDecayItem(addItem)

Alternatively, if you want more control over what happens with the item, you can assign some timestamp to the item (generated by os.time()) and add it to the item via doItemSetAttribute.
Now, I don't know for sure if 0.4 doItemSetAttribute allows custom named attributes by default. You should check this.
If yes, you can do:
Lua:
doItemSetAttribute(addItem, "myTimeStamp", os.time())

If not, you can always use the "specialdescription" attr to store this timestamp there.

In the action script for this item that was generated, add a piece of code that will check how much time has passed between the time when the scroll was generated and the time the scroll was used.
(e.g.)

Code:
local timePassed = os.time() - timeStampFromItem
, and you will get the amount of seconds that have passed.

Then you can make another variable "local allowedTime = 60*60*24", for example, and do:

Lua:
local timePassed = os.time() - timeStampFromItem
local allowedTime = 60*60*24
if timePassed > allowedTime then
    --something that happens if player waited more than 24 hours to activate this scroll
else
    --normal scroll behavior
end

Just a couple suggestions :)
 
Solution
Back
Top