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

Buy items by Lever

Tul

New Member
Joined
Apr 19, 2011
Messages
60
Reaction score
0
Hello, i need a script that i can buy items via lever, if you got 20 Tokens (item id 9020) so you can buy a item via lever.! THANKS
 
data/action/scripts
create token.lua
and paste this script.
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
		if getPlayerMoney(cid) >= 20000 then 
			doPlayerRemoveMoney(cid,20000)
		        doPlayerAddItem(cid,9020,20)
doSendMagicEffect(getPlayerPosition(cid), 13)
        else
           doPlayerSendTextMessage(cid,19,"You need 20k to buy an tokens.")
doSendMagicEffect(getPlayerPosition(cid), 2)
        end
	return TRUE
end

data/action open action.xml
paste
Lua:
<action actionid="9020" script="token.lua"/>

Only edit 20000 price.. token
 
Lua:
local t = {
	[1000] = {{3721, 1}, {9020, 1}}
	--[actionid] = {{item, count}, {tokensid, count}}
	}
function onUse(cid, item, fromPosition, itemEx, toPosition)
local v = t[getItemAttribute(item.uid, 'aid')]
	if doPlayerRemoveItem(cid, v[2][1], v[2][2]) then
		doPlayerGiveItem(cid, v[1][1], v[1][2])
	else
		doPlayerSendCancel(cid, "Sorry, you need "..v[2][2].." tokens to buy this item!")
	end
return TRUE
end
 
Last edited:
Bogart, could i add more items into the script?

like:

PHP:
local t = {
	[1000] = {{3721, 1}, {9020, 1}},
	[1000] = {{371, 1}, {9020, 1}}
	--[actionid] = {{item, count}, {tokensid, count}}
	}
fuction onUse(cid, item, fromPosition, itemEx, toPosition)
local v = t[getItemAttribute(item.uid, 'aid')
	if doPlayerRemoveItem(cid, v[2][1], v[2][1]) then
		doPlayerGiveItem(cid, v[1][1], v[1][2])
	else
		doPlayerSendCancel(cid, "Sorry, you need "..v[2][2].." tokens to buy this item!")
	end
return TRUE
end
 
Yes, that's why I used that config.
Code:
local t = {
	[[COLOR="#0000FF"][B]1000[/B][/COLOR]] = {{[COLOR="#008000"][B]3721[/B][/COLOR], [COLOR="#FFA500"][B]1[/B][/COLOR]}, {[COLOR="#FF0000"][B]9020[/B][/COLOR], [B]1[/B]}}
	--[[B][COLOR="#0000FF"]actionid[/COLOR][/B]] = {{[COLOR="#008000"][B]item[/B][/COLOR],[B][COLOR="#FFA500"] count[/COLOR][/B]}, {[COLOR="#FF0000"][B]tokensid[/B][/COLOR], [B]count[/B]}}
	}
function onUse(cid, item, fromPosition, itemEx, toPosition)
local v = t[getItemAttribute(item.uid, 'aid')]
	if doPlayerRemoveItem(cid, v[2][1], v[2][2]) then
		doPlayerGiveItem(cid, v[1][1], v[1][2])
	else
		doPlayerSendCancel(cid, "Sorry, you need "..v[2][2].." tokens to buy this item!")
	end
return TRUE
end
 
Last edited:
i get this error

PHP:
[Error - LuaScriptInterface::loadFile] data/actions/scripts/donshop/first.lua:5: '=' expected near 'onUse'
[Warning - Event::loadScript] Cannot load script (data/actions/scripts/donshop/first.lua)
data/actions/scripts/donshop/first.lua:5: '=' expected near 'onUse'

i use this

PHP:
local t = {
	[5100] = {{2500, 1}, {9020, 10}}
	--[actionid] = {{item, count}, {tokensid, count}}
	}
fuction onUse(cid, item, fromPosition, itemEx, toPosition)
local v = t[getItemAttribute(item.uid, 'aid')
	if doPlayerRemoveItem(cid, v[2][1], v[2][1]) then
		doPlayerGiveItem(cid, v[1][1], v[1][2])
	else
		doPlayerSendCancel(cid, "Sorry, you need "..v[2][2].." tokens to buy this item!")
	end
return TRUE
end
 
thanks J.Dre!

Small mistake was made. Here's the fixed version!

data/actions/actions.xml
Code:
<action actionid="1337" event="script" value="script.lua"/>
data/actions/scripts/script.lua
Lua:
local SHOP = {
	[1337] = {
		i = {7898, 1},
		c = 10
	},
	[1338] = {
		i = {7898, 1},
		c = 10
	},
}

local k = 0
local result = ""
function onUse(cid, item, fromPosition, itemEx, toPosition)
	local t = SHOP[item.actionid]
	if t then
		if getPlayerItemCount(cid, 9020) >= t.c then
			k = doCreateItemEx(t.i[1], t.i[2] or 1)
			if doPlayerAddItemEx(cid, k, false) ~= RETURNVALUE_NOERROR then
				result = "You cannot carry this item."
			else
				doPlayerRemoveItem(cid, 9020, t.c)
				result = "You have found a " .. getItemName(k) .. "."
				doSendMagicEffect(getThingPosition(cid), CONST_ME_MAGIC_BLUE)
			end
		else
			result = "You do not have enough tokens."
		end
	end
	
	return doTransformItem(item.uid, item.itemid == 1945 and 1946 or 1945), doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, result), true
end
 
Last edited:
ok np , but another question could you add for me 2 more items?

actionid [1337]
after it should come [1338] and so on? you know what i mean ? :D THANKS
 
I know it's already solved but I fixed the script, forgot to add ] and fixed a little typo
 
Last edited:
Back
Top