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

script problem

Darqneez

ShaC-Ohhhh
Joined
Dec 30, 2009
Messages
72
Reaction score
2
Location
Poland/Wroclaw
I am beginner at lua scripting. I've made this script to learn something, but I dont know where did I make a mistake. Script should give you sudden death rune for 6500 gp. but I am using an item with uid 7001, I have 6500 gp, but I cant buy sd rune. Why?
script is very simple, but I am still learning :p

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

if
item.itemuid == 7001 then
doPlayerRemoveMoney (cid, 6500)
doPlayerAddItem (cid, 7591, 1)
doPlayerSendTextMessage (cid, MESSAGE_INFO_DESCR, "You have bought a sudden death rune.")
else
doPlayerSendTextMessage (cid, MESSAGE_INFO_DESCR, "You can't buy this thing.")
end
return TRUE
end
 
Try this
function onUse(cid, item, fromPosition, itemEx, toPosition)

if item.uid == 7001 then
doPlayerRemoveMoney (cid, 6500)
doPlayerAddItem (cid, 7591, 1)
doPlayerSendTextMessage (cid, MESSAGE_INFO_DESCR, "You have bought a sudden death rune.")
else
doPlayerSendTextMessage (cid, MESSAGE_INFO_DESCR, "You can't buy this thing.")
end
return TRUE
end
 
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
	if doPlayerRemoveMoney(cid, 6500) then
		doPlayerAddItem(cid, 2268, 3)
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have bought a sudden death rune.")
	else
		doPlayerSendTextMessage (cid, MESSAGE_INFO_DESCR, "You can't buy this thing.")
	end
	return true
end
 
nice Cykotitan, it really works, first I thought that it won't work because there is no unique ID of a lever I use to 'summon' sd rune, but it's not necessary :)
Rep++ for sure

Edit: again I have some problems :D, I tried to modify this script so that item which You buy couldn't fall on ground. But TFS 0.3.6 says, there's a bug and I don't know how to make it work. Here's this script:

local item = {
[7001] = {cost = 6500, item_id = 2268, item_id_count = 100, count = 1, drop = false}
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
local items = item[item.uid]
if getPlayerMoney(cid) >= items.cost then
doPlayerRemoveMoney(cid, items.cost)
doPlayerAddItem(cid, items.item_id, items.item_id_count)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have bought a sudden death rune.")
else
doPlayerSendTextMessage (cid, MESSAGE_INFO_DESCR, "You can\'t buy this thing.")
end
else
doPlayerSendTextMessage (cid, MESSAGE_INFO_DESCR, "You don\'t have enough money")
end
return true
end
 
Last edited:
Try this
[Tested on TFS 0.3.6]
Lua:
local rune = {cost = 6500, item_id = 2268, item_id_count = 100, count = 1, drop = false} 
function onUse(cid, item, fromPosition, itemEx, toPosition)
	if getPlayerMoney(cid) >= rune.cost then
		if	doPlayerAddItem(cid, rune.item_id,rune.item_id_count,false) then
			doPlayerRemoveMoney(cid, rune.cost)
			doPlayerAddItem(cid, rune.item_id,rune.item_id_count,false)
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have bought a sudden death rune.")
		else
		doPlayerSendTextMessage (cid, MESSAGE_INFO_DESCR, "You don\'t have enough container")
		end
	else
	doPlayerSendTextMessage (cid, MESSAGE_INFO_DESCR, "You don\'t have enough money")
	end
end
 
Back
Top