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

Remove Item

Gazzy

Server Owner
Joined
Sep 25, 2013
Messages
55
Reaction score
3
I need to make a command (talkaction) that removes an item on the map and then puts the item back. I need this command to only be usable by staff and I need it to broadcast a message too. I need this for 2 positions so the params will be:
Code:
!barrier off (1 or 2) - Removes the item
!barrier on (1 or 2) - Adds the item
Code:
Item ID: 5313
Position 1:545 789 7
Position 2:551 789 7
I really need help for this so can I get help urgently? Thanks

TFS 1.0
 
local barrierpos = {x=1000, y=1000, z=7}
local barrier2pos = {x=1000, y=1000, z=7}
local ITEMID = ITEM

function onSay(cid, words, param)

if getTileItemById(barrierpos, ITEMID).uid < 0 then
doCreateItem(ITEMID, 1, barrierpos)
doCreateItem(ITEMID, 1, barrier2pos)
doBroadcastMessage("MSG")

end
return TRUE
end

<talkaction log="yes" words="/barrieron" access="3" event="script" value="barrier.lua"/>
 
@up, it's for TFS 1.0 :p
Code:
local config = {
     [1] = {pos = Position(545, 789, 7), itemid = 5313, text = {"Item1 is created.", "Item1 is removed."}},
     [2] = {pos = Position(551, 789, 7), itemid = 5313, text = {"Item2 is created.", "Item2 is removed."}}
}

function onSay(cid, words, param)
     local player = Player(cid)
     if not player:getGroup():getAccess() then
         return false
     end

     local split = {}
     for s in string.gmatch(param, "%S+") do
         table.insert(split, s)
     end
     if not tonumber(split[2]) then
         player:sendCancelMessage("Missing or invalid param. Example: !barrier on 1")
         return false
     end

     local x, message = config[tonumber(split[2])], ""
     local thing = pushThing(Tile(x.pos):getItemById(x.itemid)).uid
     if split[1] == "off" then
         if thing > 0 then
             Item(thing):remove(1)
             message = x.text[2]
         else
             player:sendCancelMessage("Item is already removed.")
         end
     elseif split[1] == "on" then
         if thing < 1 then
             Game.createItem(x.itemid, 1, x.pos)
             message = x.text[1]
         else
             player:sendCancelMessage("Item is already created.")
         end
     else
         player:sendCancelMessage("Choose between off and on.")
     end
     if message ~= "" then
         broadcastMessage(message)
     end
     return true
end
 
Last edited:
@up, it's for TFS 1.0 :p
Code:
local config = {
     [1] = {pos = Position(545, 789, 7), itemid = 5313, text = {"Item1 is created.", "Item1 is removed."}},
     [2] = {pos = Position(551, 789, 7), itemid = 5313, text = {"Item2 is created.", "Item2 is removed."}}
}

function onSay(cid, words, param)
     local player = Player(cid)
     if not player:getGroup():getAccess() then
         return false
     end

     local split = {}
     for s in string.gmatch(param, "%S+") do
         table.insert(split, s)
     end
     if not tonumber(split[2]) then
         player:sendCancelMessage("Missing or invalid param. Example: !barrier on 1")
         return false
     end

     local x, message = config[tonumber(split[2])], ""
     local thing = pushThing(Tile(x.pos):getItemById(x.itemid)).uid
     if split[1] == "off" then
         if thing > 0 then
             Item(thing):remove(1)
             message = x.text[2]
         else
             player:sendCancelMessage("Item is already removed.")
         end
     elseif split[1] == "on" then
         if thing < 1 then
             Game.createItem(x.itemid, 1, x.pos)
             message = x.text[1]
         else
             player:sendCancelMessage("Item is already created.")
         end
     else
         player:sendCancelMessage("Choose between off and on.")
     end
     if message ~= "" then
         broadcastMessage(message)
     end
     return true
end

Can you make it for TFS 0.4 but with globalevents timer ?
 
@up, it's for TFS 1.0 :p
Code:
local config = {
     [1] = {pos = Position(545, 789, 7), itemid = 5313, text = {"Item1 is created.", "Item1 is removed."}},
     [2] = {pos = Position(551, 789, 7), itemid = 5313, text = {"Item2 is created.", "Item2 is removed."}}
}

function onSay(cid, words, param)
     local player = Player(cid)
     if not player:getGroup():getAccess() then
         return false
     end

     local split = {}
     for s in string.gmatch(param, "%S+") do
         table.insert(split, s)
     end
     if not tonumber(split[2]) then
         player:sendCancelMessage("Missing or invalid param. Example: !barrier on 1")
         return false
     end

     local x, message = config[tonumber(split[2])], ""
     local thing = pushThing(Tile(x.pos):getItemById(x.itemid)).uid
     if split[1] == "off" then
         if thing > 0 then
             Item(thing):remove(1)
             message = x.text[2]
         else
             player:sendCancelMessage("Item is already removed.")
         end
     elseif split[1] == "on" then
         if thing < 1 then
             Game.createItem(x.itemid, 1, x.pos)
             message = x.text[1]
         else
             player:sendCancelMessage("Item is already created.")
         end
     else
         player:sendCancelMessage("Choose between off and on.")
     end
     if message ~= "" then
         broadcastMessage(message)
     end
     return true
end

[13/07/2014 18:21:31] Lua Script Error: [Test Interface]
[13/07/2014 18:21:31] data/talkactions/scripts/barrier.lua
[13/07/2014 18:21:31] data/talkactions/scripts/barrier.lua:2: attempt to call global 'Position' (a nil value)
[13/07/2014 18:21:31] stack traceback:
[13/07/2014 18:21:31] [C]: in function 'Position'
[13/07/2014 18:21:31] data/talkactions/scripts/barrier.lua:2: in main chunk
[13/07/2014 18:21:31] Warning: [Event::checkScript] Can not load script. /scripts/barrier.lua
 
Do you use latest TFS 1.0?
You can also try to change
Code:
Position(545, 789, 7)
To
Code:
{x = 545, y = 789, z = 7}
 
[13/07/2014 18:21:29] The Forgotten Server - Version 0.2.15 (Mystic Spirit).
[13/07/2014 18:21:29] Compilied on Apr 30 2013 21:52:32 for arch x86

It's 9.81 protocol
 
Wow that was a fast bump, 6 minutes is not exactly 24 hours :p
You need to wait 24 hours to bump your thread.

Change the metatables parts to TFS 0.2 functions.
Code:
player:sendCancelMessage("Missing or invalid param. Example: !barrier on 1")
Should be
Code:
doPlayerSendCancel(cid, "Missing or invalid param. Example: !barrier on 1")
Same goes for the other cancel messages.

Change this
Code:
local thing = pushThing(Tile(x.pos):getItemById(x.itemid)).uid
to
Code:
local thing = getTileItemById(x.pos, x.itemid).uid

This
Code:
Item(thing):remove(1)
To
Code:
doRemoveItem(thing, 1)

And last the createitem.
Code:
Game.createItem(x.itemid, 1, x.pos)
To
Code:
doCreateItem(x.itemid, 1, x.pos)

And change the positions in the table like I posted above.
 
[13/07/2014 18:43:59] Lua Script Error: [Test Interface]
[13/07/2014 18:43:59] data/talkactions/scripts/barrier.lua
[13/07/2014 18:43:59] data/talkactions/scripts/barrier.lua:2: attempt to call global 'Position' (a nil value)
[13/07/2014 18:43:59] stack traceback:
[13/07/2014 18:43:59] [C]: in function 'Position'
[13/07/2014 18:43:59] data/talkactions/scripts/barrier.lua:2: in main chunk
[13/07/2014 18:43:59] Warning: [Event::checkScript] Can not load script. /scripts/barrier.lua
 
Thanks, I can use !barrier and no words appear but when I used !barrier on 1 etc it doesn't work and shows in the chat box

____
Code:
[13/07/2014 18:49:26] Lua Script Error: [TalkAction Interface]
[13/07/2014 18:49:26] data/talkactions/scripts/barrier.lua:onSay
[13/07/2014 18:49:26] data/talkactions/scripts/barrier.lua:7: attempt to call global 'Player' (a nil value)
[13/07/2014 18:49:26] stack traceback:
[13/07/2014 18:49:26]     [C]: in function 'Player'
[13/07/2014 18:49:26]     data/talkactions/scripts/barrier.lua:7: in function <data/talkactions/scripts/barrier.lua:6>
Shows when I do !barrier, referring to
Code:
     local player = Player(cid)
 
Last edited by a moderator:
Remove that to, that's for the TFS 1.0 metatables.
And this.
Code:
if not player:getGroup():getAccess() then
    return false
end
Remove that too.

You can use getPlayerAccess(cid) instead
Code:
if getPlayerAccess(cid) < 1 then
    return false
end
 
Last edited:
So what do I put here instead:
Code:
function onSay(cid, words, param)
     if not player:getGroup():getAccess() then
         return false
     end

___
Can't use !barrier on 1 etc and !barrier returns this error:
Code:
[13/07/2014 18:59:34] Lua Script Error: [TalkAction Interface]
[13/07/2014 18:59:34] data/talkactions/scripts/barrier.lua:onSay
[13/07/2014 18:59:34] data/talkactions/scripts/barrier.lua:16: attempt to call a boolean value
[13/07/2014 18:59:34] stack traceback:
[13/07/2014 18:59:34]     [C]: at 0x00384730
[13/07/2014 18:59:34]     data/talkactions/scripts/barrier.lua:16: in function <data/talkactions/scripts/barrier.lua:6>
 
Last edited by a moderator:
Remove that to, that's for the TFS 1.0 metatables.
And this.
Code:
if not player:getGroup():getAccess() then
    return false
end
Remove that too.

You can use getPlayerAccess(cid) instead
Code:
if getPlayerAccess(cid) < 1 then
    return false
end
Change to getPlayerAccess(cid)
 
Change to getPlayerAccess(cid)
Done, that error's gone. What about
Can't use !barrier on 1 etc and !barrier returns this error:
Code:
[13/07/2014 18:59:34] Lua Script Error: [TalkAction Interface]
[13/07/2014 18:59:34] data/talkactions/scripts/barrier.lua:onSay
[13/07/2014 18:59:34] data/talkactions/scripts/barrier.lua:16: attempt to call a boolean value
[13/07/2014 18:59:34] stack traceback:
[13/07/2014 18:59:34]     [C]: at 0x00384730
[13/07/2014 18:59:34]     data/talkactions/scripts/barrier.lua:16: in function <data/talkactions/scripts/barrier.lua:6>
 
Code:
local config = {
     [1] = {pos = {x = 545, y = 789, z = 7}, itemid = 5313, text = {"Item1 is created.", "Item1 is removed."}},
     [2] = {pos = {x = 551, y = 789, z = 7}, itemid = 5313, text = {"Item2 is created.", "Item2 is removed."}}
}

function onSay(cid, words, param)
     if not getPlayerAccess(cid) then
         return false
     end

     local split = {}
     for s in string.gmatch(param, "%S+") do
         table.insert(split, s)
     end
     if not tonumber(split[2]) then
         doPlayerSendCancel(cid, "Missing or invalid param. Example: !barrier on 1")("Missing or invalid param. Example: !barrier on 1")
         return false
     end

     local x, message = config[tonumber(split[2])], ""
    local thing = getTileItemById(x.pos, x.itemid).uid
     if split[1] == "off" then
         if thing > 0 then
             doRemoveItem(thing, 1)
             message = x.text[2]
         else
             doPlayerSendCancel("Item is already removed.")
         end
     elseif split[1] == "on" then
         if thing < 1 then
    doCreateItem(x.itemid, 1, x.pos)
             message = x.text[1]
         else
             doPlayerSendCancel("Item is already created.")
         end
     else
         doPlayerSendCancel("Choose between off and on.")
     end
     if message ~= "" then
         broadcastMessage(message)
     end
     return true
end

___
changed
Code:
doPlayerSendCancel(cid, "Missing or invalid param. Example: !barrier on 1")("Missing or invalid param. Example: !barrier on 1")
to
Code:
doPlayerSendCancel(cid, "Missing or invalid param. Example: !barrier on 1")

But I still can't do "!barrier off 1" etc and !barrier gives no errors
 
Last edited by a moderator:
Back
Top