• 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 Typical "Pull lever then do add or remove item"

auda

Advanced OT User
Joined
Jun 29, 2014
Messages
273
Reaction score
233
Location
Sweden
Just in case someone get mad on me for posting such an obvious script, but as an excuse I have searched through my server distro (Avesta 0.6.5) without any luck, as well as OTLand.

In my case - if you pull the specific lever a fire field(which is not decaying) will be removed at a spot nearby, and if you pull the lever again it will reappear.

Now, I didn't get it to work at the first part where it should remove the fire field (actionid = 201 for lever, 202 for fire field)

Code:
function onUse(cid, item, frompos, item2, topos)
    if(item.actionid == 201) then
        doRemoveItem(item.actionid, 202)
    return TRUE
    end

end

I know, simple but not useable yet :s Thanks!
 
You can also do it like this.
Code:
local pos = {x = 100, y = 100, z = 7}

function onUse(cid, item, frompos, item2, topos)
     local thing = getTileItemById(pos, 1487).uid
     if thing > 0 then
         doRemoveItem(thing, 1)
     else
         doCreateItem(1487, 1, pos)
     end  
     return doTransformItem(item.uid, item.itemid == 1945 and 1946 or 1945)
end
Good thing with using getTileItemById is when there are other items on that position, the script will still work.
 
You can also do it like this.
Code:
local pos = {x = 100, y = 100, z = 7}

function onUse(cid, item, frompos, item2, topos)
     local thing = getTileItemById(pos, 1487).uid
     if thing > 0 then
         doRemoveItem(thing, 1)
     else
         doCreateItem(1487, 1, pos)
     end 
     return doTransformItem(item.uid, item.itemid == 1945 and 1946 or 1945)
end
Good thing with using getTileItemById is when there are other items on that position, the script will still work.

I tried the script Gsp sent me through the link without success but your script did work except that the switch wont change into ID 1946, or back again. It stays at 1945! :)
 
I added the transform about 1 min later, maybe you used the first version I posted?

I have it alright :ss

Code:
local pos = {x = 1150, y = 987, z = 3}

function onUse(cid, item, frompos, item2, topos)
     local thing = getTileItemById(pos, 1487).uid
     if thing > 0 then
         doRemoveItem(thing, 1)
     else
         doCreateItem(1487, 1, pos)
     end 
     return doTransformItem(item.uid, item.itemid == 1945 and 1946 or 1945)
end
 
local firepos = {x=1000, y=1000, z=7, stackpos=1}
function onUse(cid, item, fromPos, item2, toPos)
if item.actionid == ID and item.itemid == 1945 then
doCreateItem(FIREID, 1, pos)
else
doRemoveItem(getThingfromPos(firepos).uid)
doTransformItem(item.uid,1946)
end

try this
 
local firepos = {x=1000, y=1000, z=7, stackpos=1}
function onUse(cid, item, fromPos, item2, toPos)
if item.actionid == ID and item.itemid == 1945 then
doCreateItem(FIREID, 1, pos)
else
doRemoveItem(getThingfromPos(firepos).uid)
doTransformItem(item.uid,1946)
end

try this

This one worked flawless - Thank you Limos and Gsp! (Had to change place of doCreateItem and doRemoveItem to get them in the correct order, but I managed to do that! :) <3
 
Better use getTileItemById for such scripts, if someone throws items on that position, it won't work anymore when you use getThingfromPos, since it doesn't look for itemid.
 
Back
Top