TFS 1.X+ Talk

alcapone

Member
Joined
Jan 13, 2021
Messages
44
Reaction score
5
Lua:
local testatalk = TalkAction("!testatalk")

function testatalk.onSay(player, words, param)
       local player = Player(player)
    local inbox = player:getSlotItem(CONST_SLOT_STORE_INBOX)
 
    if param == ""   then     
         player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'text')
         return false
    end
    
    if player:getStorageValue(1769359) > os.time() then
        player:sendCancelMessage('exaust')
        
        else
        
    if param == "nome1" then
 
    player:setStorageValue(1769359, os.time() + (60 * 1200))
    player:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
    elseif player:getVocation():getId() == 1 or player:getVocation():getId() == 5  then
    inbox:addItem(32129, 100)
    elseif  player:getVocation():getId() == 2 or player:getVocation():getId() == 6 then
    inbox:addItem(32128, 100)
    elseif  player:getVocation():getId() == 3 or player:getVocation():getId() == 7 then
    inbox:addItem(32127, 100)
    elseif  player:getVocation():getId() == 4 or player:getVocation():getId() == 8 then
    inbox:addItem(32124, 100)
    inbox:addItem(32125, 100)
    inbox:addItem(32126, 100)
     return true
    end
 
 
     if param == "nome2" then     
    player:setStorageValue(1769359, os.time() + (60 * 1200))
    player:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
    elseif player:getVocation():getId() == 1 or player:getVocation():getId() == 5  then
    inbox:addItem(32129, 100)
    elseif  player:getVocation():getId() == 2 or player:getVocation():getId() == 6 then
    inbox:addItem(32128, 100)
    elseif  player:getVocation():getId() == 3 or player:getVocation():getId() == 7 then
    inbox:addItem(32127, 100)
    elseif  player:getVocation():getId() == 4 or player:getVocation():getId() == 8 then
    inbox:addItem(32124, 100)
    inbox:addItem(32125, 100)
    inbox:addItem(32126, 100)
    return true
    end
    
 
    
    
 
    
    return
    end 
        

        
    return false
end


testatalk:separator(" ")
testatalk:register()


the problem that when a player says '!testatalk' with some other name he is getting the items infinitely he should receive the error message saying 'text'
 
Solution
There were if/elseif that checked:
  • 'if player said XXX' -> set storage
  • if said anything else, but has vocation X -> give items
so it gave items on any other text. It also did not give items to player that said 'nome1' or 'nome2'. Only set player storage.

Fixed code:
Code:
local testatalk = TalkAction("!testatalk")

function testatalk.onSay(player, words, param)
    local player = Player(player)
    local inbox = player:getSlotItem(CONST_SLOT_STORE_INBOX)

    if param == "" then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "text")
        return false
    end

    if player:getStorageValue(1769359) > os.time() then
        player:sendCancelMessage("exaust")
    else
        if param == "nome1" then...
OP
A

alcapone

Member
Joined
Jan 13, 2021
Messages
44
Reaction score
5
Paste it to tool that will format it by if/for/function:
and you will see what is wrong with IFs.
I'll try!
edit-
I did the test and the player keeps picking up infinite items
 

Gesior.pl

Mega Noob&LOL 2012
Senator
Premium User
Joined
Sep 18, 2007
Messages
2,304
Solutions
38
Reaction score
1,685
Location
Poland
GitHub
gesior
There were if/elseif that checked:
  • 'if player said XXX' -> set storage
  • if said anything else, but has vocation X -> give items
so it gave items on any other text. It also did not give items to player that said 'nome1' or 'nome2'. Only set player storage.

Fixed code:
Code:
local testatalk = TalkAction("!testatalk")

function testatalk.onSay(player, words, param)
    local player = Player(player)
    local inbox = player:getSlotItem(CONST_SLOT_STORE_INBOX)

    if param == "" then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "text")
        return false
    end

    if player:getStorageValue(1769359) > os.time() then
        player:sendCancelMessage("exaust")
    else
        if param == "nome1" then
            player:setStorageValue(1769359, os.time() + (60 * 1200))
            player:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
            if player:getVocation():getId() == 1 or player:getVocation():getId() == 5 then
                inbox:addItem(32129, 100)
            elseif player:getVocation():getId() == 2 or player:getVocation():getId() == 6 then
                inbox:addItem(32128, 100)
            elseif player:getVocation():getId() == 3 or player:getVocation():getId() == 7 then
                inbox:addItem(32127, 100)
            elseif player:getVocation():getId() == 4 or player:getVocation():getId() == 8 then
                inbox:addItem(32124, 100)
                inbox:addItem(32125, 100)
                inbox:addItem(32126, 100)
            end

            return true
        end

        if param == "nome2" then
            player:setStorageValue(1769359, os.time() + (60 * 1200))
            player:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
            if player:getVocation():getId() == 1 or player:getVocation():getId() == 5 then
                inbox:addItem(32129, 100)
            elseif player:getVocation():getId() == 2 or player:getVocation():getId() == 6 then
                inbox:addItem(32128, 100)
            elseif player:getVocation():getId() == 3 or player:getVocation():getId() == 7 then
                inbox:addItem(32127, 100)
            elseif player:getVocation():getId() == 4 or player:getVocation():getId() == 8 then
                inbox:addItem(32124, 100)
                inbox:addItem(32125, 100)
                inbox:addItem(32126, 100)
            end

            return true
        end

    end

    return false
end

testatalk:separator(" ")
testatalk:register()

Changes:
 
Solution
Top