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

Solved (Solved) Delay for talkaction #Lua

Blackheart OT

Defense in depth
Joined
Nov 21, 2014
Messages
26
Reaction score
2
Location
USA
Hello Otland community,

I've spent a couple hours trying to find a thread that could explain this at the level of a beginner in lua with previous programming knowledge in Java and Matlab, and I have failed, so I resort to asking the community.

I'm trying to prevent abuse of the talkaction system on my server. I would like to set up a delay before which a player cannot submit the same talkaction twice.

Ill show you what I have so far; its pretty bad; I'm sorry.

Code:
function onSay(cid, words, param, channel)
    local storage = 6707
    local delaytime = 2 * 60 * 1000 -- 2 minutes

    local condition = createCreatureCondition(cid, CONDITION_EXHAUST)
    condition:setConditionParam(CONDITION_PARAM_TICKS, delaytime)

    if not getCreatureCondition(cid, CONDITION_EXHAUST) then
        -- Do talkaction
    end
    return true
end

What I was trying to do with above code was create a toggle that would go false once ticks had occurred, and reset when you called getCreatureCondition. Honestly, I'm sort of making that up because I cant find any documentation for these functions anywhere on the internet. I only found a list of the functions in the script tutorial section of this website.

Perhaps the above strategy is incorrect and I have to reset the timer each time? (I.e. create an else for the if loop where I reset counter.)

I am running TFS 1.1, and the error message is that createCreatureCondition can only be used while first loading the script. Please let me know if I left out any crucial information.

I sincerely appreciate your help,

Mike
 
Last edited:
Which server do you use? You can look at potion scripts for example how to do it.
Add the condition above function onSay.

Hello Limos,

Thank you for answering. I added the server and error message to my original post. Could this be caused by the fact that I am creating the condition inside the function, and not the script?

-Mike
 
I have solved the problem using Limos' insight. The following is the code solution for anyone that might have a similar problem:

Code:
local delaytime = 2 * 60 * 1000 -- 2 minutes

local exhaust = Condition(CONDITION_EXHAUST)
exhaust:setParameter(CONDITION_PARAM_TICKS, delaytime)

function onSay(cid, words, param, channel)
    local player = Player(cid)
       
    if player:getCondition(CONDITION_EXHAUST) then
        -- send exhaust message
        return true
    end

    player:addCondition(exhaust)
    -- do talkaction
    return true
end
 
Back
Top