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

Switch Script

Eternal Life

New Member
Joined
May 15, 2011
Messages
148
Reaction score
1
Location
Aguadilla,Puerto Rico
Ok...I have posted tons of threads asking for a switchs script but none of them seemed to be working properly some have error and some arent working at ALL.

So here it is again, what i am asking for is a script that gives you the possibility to buy items by using (holes,switch or traps) and the item use to buy the item is a piece of royal steel (5887) each item will cost 1,2,3,4 piece of royal steel depends on the item is how many royal steel it will take away :)



Like this



switchs.jpg
 
Last edited:
Lua:
local SwitchId = XXX -- ID of the switch
local Token = XXX, X -- ID of the token (ID, count)
local Item = XXX, X -- ID of item to buy (ID, count)
function onUse(cid, item, frompos, item2, topos)
	if item.itemid == SwitchId and getPlayerItemCount(cid, Token) == TRUE then
		doPlayerRemoveItem(cid, Token)
		doPlayerAddItem(cid, item)
	else
		doPlayerSendCancel(cid,"You Dont Have Any Tokens")
	end
return 1
end
 
local SwitchId = XXX -- ID of the switch
local Token = XXX, X -- ID of the token (ID, count)
local Item = XXX, X -- ID of item to buy (ID, count)
function onUse(cid, item, frompos, item2, topos)
if item.itemid == SwitchId and getPlayerItemCount(cid, Token) == TRUE then
doPlayerRemoveItem(cid, Token)
doPlayerAddItem(cid, Item)
else
doPlayerSendCancel(cid,"You Dont Have Any Tokens")
end
return 1
end
 
ok am it doesnt seem to have any erros but for some reason it says i dont have the token when i do.

This is what i have


local SwitchId = 1512 -- ID of the switch
local Token = 5887, 1 -- ID of the token (ID, count)
local Item = 2447, 1 -- ID of item to buy (ID, count)
function onUse(cid, item, frompos, item2, topos)
if item.itemid == SwitchId and getPlayerItemCount(cid, Token) == TRUE then
doPlayerRemoveItem(cid, Token)
doPlayerAddItem(cid, item)
else
doPlayerSendCancel(cid,"You Dont Have Any Vip Tokens")
end
return 1
end
 
Lua:
function onUse(cid, item, frompos, item2, topos)
local SwitchId = 1512 -- ID of the switch
local Token = 5887, 1 -- ID of the token (ID, count)
local Item = 2447, 1 -- ID of item to buy (ID, count)
if item.itemid == SwitchId and getPlayerItemCount(cid, Token) == TRUE then
doPlayerRemoveItem(cid, Token)
doPlayerAddItem(cid, item)
else
doPlayerSendCancel(cid,"You Dont Have Any Vip Tokens")
end
return 1
end
 
Lua:
local underItem = 1642 -- the item you have under the item you want
local distance = x -- the amount of squares away from the lever the items are, needs to be the same for all directions

local items = {
	[itemid] = x, -- change the itemid to the actual itemid and then change the x to the amount of tokens needed for this item
	[itemid2] = x, -- same again
	[itemid3] = x -- same again until you have all items or they only need 1 token to buy them
	}

function onUse(cid, item, fromPosition, itemEx, topos)
local itemx = {0, 0, 0, 0}
	if item.itemid == 1945 or item.itemid == 1946 then

		itemx[1] = getThingfromPos({x=topos.x, y=topos.y-distance, z=topos.z, stackpos=1}) 
		itemx[2] = getThingfromPos({x=topos.x+distance, y=topos.y, z=topos.z, stackpos=1})
		itemx[3] = getThingfromPos({x=topos.x, y=topos.y+distance, z=topos.z, stackpos=1})
		itemx[4] = getThingfromPos({x=topos.x-distance, y=topos.y, z=topos.z, stackpos=1})
		
		if itemx[1].itemid == underItem then
			make = getThingfromPos({x=topos.x, y=topos.y-distance, z=topos.z, stackpos=3})-- might have to change stackpos
		elseif itemx[2].itemid == underItem then
			make = getThingfromPos({x=topos.x+distance, y=topos.y, z=topos.z, stackpos=3})
		elseif itemx[3].itemid == underItem then
			make = getThingfromPos({x=topos.x, y=topos.y+distance, z=topos.z, stackpos=3})
		elseif itemx[4].itemid == underItem then
			make = getThingfromPos({x=topos.x-distance, y=topos.y, z=topos.z, stackpos=3})
		end

		if getItemNameById(make.itemid) ~= '' then
			if items[make.itemid] then
				if (doPlayerRemoveItem(cid,5887, items[make.itemid])) then
					doPlayerSendTextMessage(cid, 22, "U got a '" .. getItemNameById(make.itemid) .. ", for " .. items[make.itemid] .. " tokens.")
					doPlayerAddItem(cid, make.itemid, 1)
				else
					doPlayerSendTextMessage(cid, 22, "U dont have " .. items[make.itemid] .. " tokens!")
				end
			else
				if (doPlayerRemoveItem(cid,5887,1)) then
					doPlayerAddItem(cid, make.itemid, 1)
					doPlayerSendTextMessage(cid, 22, "U got a '" .. getItemNameById(make.itemid) .. ", for 1 token.")
				else
					doPlayerSendTextMessage(cid, 22, "U dont have 1 token!")
				end
			end
		end	
	if item.itemid == 1945 then
		doTransformItem(item.uid, item.itemid + 1)
	elseif item.itemid == 1946 then
		doTransformItem(item.uid, item.itemid - 1)
	end
	end
	return TRUE
end

this script will work like in the picture.. if you haven't added the itemid in items it will take only 1 token

this way you don't have to make a script for each item.. =)
 
Last edited:
Why so many shit
Lua:
local t = {
[itemid] = cost,
[itemid] = cost,
[itemid] = cost,
[itemid] = cost,
[itemid] = cost,
[itemid] = cost,
[itemid] = cost,
[itemid] = cost,
[itemid] = cost,
[itemid] = cost,
[itemid] = cost
} --itemID = cost of royal steels
function onUse(cid, item, fromPosition, itemEx, toPosition)
fromPosition.stackpos = 2
for k, v in pairs(t) do
    if getThingfromPos(fromPosition).itemid == k then
       if doPlayerRemoveItem(cid, 5887, v[1]) then
          doPlayerAddItem(cid, k, 1)
          break;
       else
           doPlayerSendCancel(cid, "You do not have enough " .. getItemName(5887) .. ".")
       end
    end
end
 
Last edited:
Back
Top