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

[TFS 1.2/1.3] Free scripting service

Status
Not open for further replies.
are you talking about updating the addItem function to set the time it was added when the item is given?
i can scan the player easy i just wanna know how you expect it to be done
if you dont know ill just use debug.sethook on addItem
Um Im not sure I dont know what you mean by debug.sethook but here is an example of what I mean
/scanplayer Test, 25664
Scan results for 25664 on Test:
Backpack: 1, added on DATE
Depot: 0
House: 0
I dont know if its possible but if its not im fine with just the amount of items and where he has them :p

Edit:
Kinda realized that it'd be trouble if a player has more than 1 so maybe change it to
/scanplayer Test, 25664
Scan results for 25664 on Test:
Backpack: 1
Depot: 0
House: 0
Last 25664 recieved was on: DATE
 
Last edited:
Can you script an event that is an automated trivia?

Event would be like this.
Event starts every hour
Event is a global broadcast that asks a questions every 60 seconds, players must answer questions using "$" "#" "&" or something to
answer the broadcast script
After a player has answered 3 answers correctly, the event shall finish adding an item to the player that won the event.
globalevents/globalevents.xml
XML:
 <globalevent name="trivia" interval="3600000" script="trivia.lua"/>

globalevents/scripts/trivia.lua
Lua:
local startTime = 3 -- Minutes until the event will start

function onThink(interval)
    Game.broadcastMessage("[TRIVIA] A trivia event will start in ".. startTime .." minutes.", MESSAGE_STATUS_CONSOLE_BLUE)
    addEvent(runTrivia, startTime * 60 * 1000)
    return true
end

talkactions/talkactions.xml
XML:
<talkaction words="!answer" separator=" " script="trivia.lua"/>

talkactions/scripts/trivia.lua
Lua:
--// Config

--// All question answers must be in lowercase, if the answer is a number it must be a string (example: 6 -> "6")
local questions = {
    {text = "What is 3+3?", answer = "6"},
    {text = "What is 2+2?", answer = "4"},
    {text = "What is 1+1?", answer = "2"}
}

--// Random reward for the winner
local rewards = {
    {id = 2148, count = {1, 100}}
}

local broadcastType = MESSAGE_STATUS_CONSOLE_BLUE -- Message type used for broadcasting
local messageType = MESSAGE_STATUS_CONSOLE_ORANGE -- Message type used for sending player messages (not broadcasts)
local autoQuestion = 60 -- Amount of seconds that a question should automatically be sent
local nextQuestion = 60 -- Amount of seconds that a question will be sent after a player answers correctly
local maxAnswers = 3 -- Amount of answers needed to recieve a reward

--\\

--// Non-config
if awaitingEvent then
    stopEvent(awaitingEvent)
end
playerAnswers = {}
questionCache = {}
currentQuestion = 0
--\\

function selectQuestion()
    local index = math.random(#questions)
    if (#questions == #questionCache) then
        return endTrivia(false, " No questions left.")
    end
    while isInArray(questionCache, index) do
        index = math.random(#questions)
    end
    questionCache[#questionCache+1] = index
    currentQuestion = index
    return questions[index]
end

function endTrivia(silent, reason)
    currentQuestion = 0
    questionCache = {}
    playerAnswers = {}
    stopEvent(awaitingEvent)
    if not silent then
        Game.broadcastMessage("[TRIVIA] Trivia event has been ended.".. reason or "", broadcastType)
    end
end

--// Silently end current event on reload
endTrivia(true)

function runTrivia(forced)
    if forced then
        Game.broadcastMessage("[TRIVIA] No one won the previous round.", broadcastType)
    end
    local question = selectQuestion()
    if not question then
        return
    end
    awaitingEvent = addEvent(runTrivia, autoQuestion * 1000, true)
    Game.broadcastMessage("[TRIVIA] ".. question.text, broadcastType)
end

function onSay(player, words, param)
    local activeQuestion = questions[currentQuestion]
    if (currentQuestion == 0) then
        player:sendTextMessage(messageType, "There is no active question.")
        return false
    end
    if (param == "") then
        player:sendTextMessage(messageType, "Input an answer.")
        return false
    end
    if (param:lower() ~= activeQuestion.answer) then
        player:sendTextMessage(messageType, "Incorrect answer.")
        return false
    end
    local guid = player:getGuid()
    local name = player:getName()
    playerAnswers[guid] = (playerAnswers[guid] or 0) + 1
    if (playerAnswers[guid] == maxAnswers) then
        local reward = rewards[math.random(#rewards)]
        player:addItem(reward.id, math.random(reward.count[1], reward.count[2]))
        player:sendTextMessage(messageType, "You have answered ".. maxAnswers .." questions correctly, you have won a reward.")
        endTrivia(false, " ".. name .. " has won the event.")
    else
        player:sendTextMessage(messageType, ("You have answered the question correctly. You now have [%d / %d] points."):format(playerAnswers[guid], maxAnswers))
        Game.broadcastMessage(('%s has answered the question correctly. The correct answer was "%s". Next question in %d seconds.'):format(name, activeQuestion.answer, nextQuestion), broadcastType)
        currentQuestion = 0
        stopEvent(awaitingEvent)
        addEvent(runTrivia, nextQuestion * 1000)
    end
    return false
end

will run each hour, send questions every 60 seconds
answer questions with "!answer <answerhere>"
the symbols you requested are impossible to use since tibia client refuses them

Um Im not sure I dont know what you mean by debug.sethook but here is an example of what I mean
/scanplayer Test, 25664
Scan results for 25664 on Test:
Backpack: 1
Depot: 0
House: 0

I dont know if its possible but if its not im fine with just the amount of items and where he has them :p
i wouldn't really advise using the function i made for actual use, mkalo just made me do it to see if i could
it's not well made at all and is most likely slow
i could remake the function if that's what you'd like, but i won't bother making it compatible with offline players, i don't like having to deal with a bunch of queries in scripts

about your edit:
this isn't possible for items that a player already has, you can only start looking at dates if you set them to an attribute whenever they're added to the player
 
Last edited:
I´d like to request a script that allows a player to get 1 min stamina after hitting training monk. I´m making a training room for players. When they attack a training monk for 2 minutes they recive 1 min stamina.
 
I´d like to request a script that allows a player to get 1 min stamina after hitting training monk. I´m making a training room for players. When they attack a training monk for 2 minutes they recive 1 min stamina.

events/scripts/creature.lua
Lua:
local minutes = 2 * 60
local stamina = 1
local training = {}

local function addSeconds(cid, pos)
    local player = Player(cid)
    if not player then
        training[cid] = nil
        return
    end
    if (player:getPosition() == pos) then
        if training[cid] >= minutes then
            player:addStamina(stamina)
            training[cid] = 0
        end
        training[cid] = training[cid]+1
    else
        training[player:getId()] = 0
    end
    addEvent(addSeconds, 1000, cid, pos)
end

function Creature:onTargetCombat(target)
    if self:isPlayer() and (target:getName() == "Training Monk") then
        training[self:getId()] = 0
        addSeconds(self:getId(), self:getPosition())
        self:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "For Every 2 minutes you hit a monk you recive 1 minute of stamina")
    end
    return true
end
 
Last edited:
I would like to ask for script onStepIn, if player step on tile with uniqueID 11111 he get storageID 1000 and script send text to player "you got it"
 
I would like to ask for script onStepIn, if player step on tile with uniqueID 11111 he get storageID 1000 and script send text to player "you got it"
Lua:
local config = {
    storage = 123456,
    value = 1,
    uid = 11111,
    text = "you got it"
}

function onStepIn(creature, item, position, fromPosition)
    if creature:isPlayer() and item.uid == config.uid then
        if creature:getStorageValue(config.storage) ~= config.value then
            creature:setStorageValue(config.storage, config.value)
            creature:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, config.text)
        end
    end
    return true
end
 
Lua:
local config = {
    storage = 123456,
    value = 1,
    uid = 11111,
    text = "you got it"
}

function onStepIn(creature, item, position, fromPosition)
    if creature:isPlayer() and item.uid == config.uid then
        if creature:getStorageValue(config.storage) ~= config.value then
            creature:setStorageValue(config.storage, config.value)
            creature:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, config.text)
        end
    end
    return true
end

It's work, thanks but how can i change to see text above me no in console?
 
It's work, thanks but how can i change to see text above me no in console?
Lua:
local config = {
    storage = 123456,
    value = 1,
    uid = 11111,
    text = "you got it"
}
function onStepIn(creature, item, position, fromPosition)
    if creature:isPlayer() and item.uid == config.uid then
        if creature:getStorageValue(config.storage) ~= config.value then
            creature:setStorageValue(config.storage, config.value)
            creature:say(config.text, TALKTYPE_MONSTER_SAY)
        end
    end
    return true
end
 
Lua:
local config = {
    storage = 123456,
    value = 1,
    uid = 11111,
    text = "you got it"
}
function onStepIn(creature, item, position, fromPosition)
    if creature:isPlayer() and item.uid == config.uid then
        if creature:getStorageValue(config.storage) ~= config.value then
            creature:setStorageValue(config.storage, config.value)
            creature:say(config.text, TALKTYPE_MONSTER_SAY)
        end
    end
    return true
end
pretty advanced to learn how tfs code works and the functions used/needed for someone that just started last night
 
hello I need a talkaction script that you set skills to the items
exemple:
Code:
/attr skill_key value
I have a base for it
Code:
function onSay(player, words, param)

    if not player:getGroup():getAccess() then
        return true
    end

    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        return false
    end

    local t = param:split(" ", 1)
    local attr = t[1]
    local value = (t[2])

    local position = player:getPosition()
    position:getNextPosition(player:getDirection())

    local tile = position:getTile()
    if not tile then
        player:sendCancelMessage("Object not found.")
        return false
    end

    local thing = tile:getTopVisibleThing(player)
    if not thing then
        player:sendCancelMessage("Thing not found.")
        return false
    end
    if thing:isItem() then
        if attr == "skillfist" then
            thing:setAttribute(SKILLHERE?, tonumber(value))
        else
            player:sendCancelMessage("Bad Attribute.")
            return true
        end
    end

    position:sendMagicEffect(CONST_ME_MAGIC_RED)
    return false
end
 
I'd like to request a script for TFS 1.2.

A globalevent which executes each 5 seconds that tries to send a list of items (registered in a sql table) checking if the player has available slots and free capacity to carry.
The will never stop to try to send the item for the player until he have available slot and free capacity to carry.

The table may contains (suggestion): player_id, item_id, item_count, item_name
The item_name is a custom name for the received item (it will appear only on the receive message, not change the item name properly).

Also, a function to add an item to the sql table will be needed.
Something like (suggestion) Player.addItemByServer(item_id[, item_count[, item_name]]), which item_count and item_name is optional.


Thanks in advance.
 
I'd like to request a script for TFS 1.2.

A globalevent which executes each 5 seconds that tries to send a list of items (registered in a sql table) checking if the player has available slots and free capacity to carry.
The will never stop to try to send the item for the player until he have available slot and free capacity to carry.

The table may contains (suggestion): player_id, item_id, item_count, item_name
The item_name is a custom name for the received item (it will appear only on the receive message, not change the item name properly).

Also, a function to add an item to the sql table will be needed.
Something like (suggestion) Player.addItemByServer(item_id[, item_count[, item_name]]), which item_count and item_name is optional.


Thanks in advance.
why bother with sql in the first place?
 
Status
Not open for further replies.
Back
Top