• 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 Action Use only once

adrenyslopez

Member
Joined
Dec 22, 2015
Messages
201
Reaction score
15
Hello, help me with this scripts so that it can only be used 1 time per player or per IP

Me using: otbr tfs 1.3

Lua:
local addcustom1 = Action()

function addcustom1.onUse(cid, item, fromPosition, itemEx, toPosition)
    local mountid = math.random(1,32) -- you have to change 32 for your highest mount id
    doPlayerAddMount(cid, mountid) --add the mount
    doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "Has received a mount!") --message in console (red)
    doSendMagicEffect(getCreaturePosition(cid), CONST_ME_FIREWORK_RED) --effect on player
    doRemoveItem(item.uid, 1) -- remove the item
    return TRUE
end

addcustom1:id(10141)
addcustom1:register()
 
Solution
Lua:
local addcustom1 = Action()

function addcustom1.onUse(cid, item, fromPosition, itemEx, toPosition)

    if cid:getStorageValue(9539) == 1 then
        doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You alredy used the doll.!")
        return true
    end
    local mountid = math.random(1,32) -- you have to change 32 for your highest mount id
    doPlayerAddMount(cid, mountid) --add the mount
    cid:setStorageValue(9539, 1)
    doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "Has received a mount!") --message in console (red)
    doSendMagicEffect(getCreaturePosition(cid), CONST_ME_FIREWORK_RED) --effect on player
    doRemoveItem(item.uid, 1) -- remove the item
    return TRUE
end

addcustom1:id(10141)...
Lua:
local addcustom1 = Action()

function addcustom1.onUse(cid, item, fromPosition, itemEx, toPosition)

    if player:getStorageValue(9539) == 1 then
        doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You alredy used the doll.!")
        return true
    end
    local mountid = math.random(1,32) -- you have to change 32 for your highest mount id
    doPlayerAddMount(cid, mountid) --add the mount
    player:setStorageValue(9539, 1)
    doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "Has received a mount!") --message in console (red)
    doSendMagicEffect(getCreaturePosition(cid), CONST_ME_FIREWORK_RED) --effect on player
    doRemoveItem(item.uid, 1) -- remove the item
    return TRUE
end

addcustom1:id(10141)
addcustom1:register()
 
Lua:
local addcustom1 = Action()

function addcustom1.onUse(cid, item, fromPosition, itemEx, toPosition)

    if player:getStorageValue(9539) == 1 then
        doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You alredy used the doll.!")
        return true
    end
    local mountid = math.random(1,32) -- you have to change 32 for your highest mount id
    doPlayerAddMount(cid, mountid) --add the mount
    player:setStorageValue(9539, 1)
    doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "Has received a mount!") --message in console (red)
    doSendMagicEffect(getCreaturePosition(cid), CONST_ME_FIREWORK_RED) --effect on player
    doRemoveItem(item.uid, 1) -- remove the item
    return TRUE
end

addcustom1:id(10141)
addcustom1:register()
Lua:
Lua Script Error: [Scripts Interface]
/home/forgottenserver/data/scripts/actions/mount1.lua:callback
/home/forgottenserver/data/scripts/actions/mount1.lua:5: attempt to index global 'player' (a nil value)
stack traceback:
        [C]: in function '__index'
        /home/forgottenserver/data/scripts/actions/mount1.lua:5: in function </home/forgottenserver/data/scripts/actions/mount1.lua:3>
 
Lua:
local addcustom1 = Action()

function addcustom1.onUse(cid, item, fromPosition, itemEx, toPosition)

    if cid:getStorageValue(9539) == 1 then
        doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You alredy used the doll.!")
        return true
    end
    local mountid = math.random(1,32) -- you have to change 32 for your highest mount id
    doPlayerAddMount(cid, mountid) --add the mount
    cid:setStorageValue(9539, 1)
    doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "Has received a mount!") --message in console (red)
    doSendMagicEffect(getCreaturePosition(cid), CONST_ME_FIREWORK_RED) --effect on player
    doRemoveItem(item.uid, 1) -- remove the item
    return TRUE
end

addcustom1:id(10141)
addcustom1:register()

If you prefer new coding style of tfs 1.x

Lua:
local addcustom1 = Action()

function addcustom1.onUse(player, item, fromPosition, itemEx, toPosition)

    if player:getStorageValue(9539) == 1 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You alredy used it!.')
        return true
    end
    local mountid = math.random(1,32) -- you have to change 32 for your highest mount id
    player:addMount(mountid) --add the mount
    player:setStorageValue(9539, 1)
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have received a mount!.')
    player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_RED)
    item:remove(1) -- remove the item
    return true
end

addcustom1:id(10141)
addcustom1:register()
 
Solution
Back
Top