• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

[Help/request(?)] Trade script~

Serginov

Onkonkoronkonk
Joined
Jun 28, 2008
Messages
1,321
Reaction score
18
Location
Sweden - Dalarna
I need help with a npc script

I'll explain it fast
When you completed a quest you get a storage.
To trade with the NPC you need to complete the quest before, else you can't trade with him.

Thanks in advance




TFS 0.3.4pl2
 
Code:
local itemWindow = {
	{id=2160, subType=0, buy=10000, sell=10000, name="Test1"},
	{id=2152, subType=0, buy=100, sell=100, name="Test2"},
	{id=2148, subType=0, buy=1, sell=1, name="Test3"},
	{id=2173, subType=0, buy=10000, sell=5000, name="Test4"}
}

local items = {}
for _, item in ipairs(itemWindow) do
	items[item.id] = {buyPrice = item.buy, sellPrice = item.sell, subType = item.subType, realName = item.name}
end

local function getPlayerMoney(cid)
	return ((getPlayerItemCount(cid, 2160) * 10000) +
	(getPlayerItemCount(cid, 2152) * 100) +
	getPlayerItemCount(cid, 2148))
end

local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpacks)
	if(items[item] == nil) then
		selfSay("Ehm.. sorry... this shouldn't be there, I'm not selling it.", cid)
		return
	end

	if(getPlayerMoney(cid) >= amount * items[item].buyPrice) then
		local itemz, i = doNpcSellItem(cid, item, amount, subType, ignoreCap, inBackpacks)
		if(i < amount) then
			if(i == 0) then
				selfSay("Sorry, but you don't have space to take it.", cid)
			else
				selfSay("I've sold some for you, but it seems you can't carry more than this. I won't take more money than necessary.", cid)
				doPlayerRemoveMoney(cid, i * items[item].buyPrice)
			end
		else
			selfSay("Thanks for the money!", cid)
			doPlayerRemoveMoney(cid, amount * items[item].buyPrice)
		end
	else
		selfSay("Stfu noob, you don't have money.", cid)
	end
end

local onSell = function(cid, item, subType, amount, ignoreCap, inBackpacks)
	if(items[item] == nil) then
		selfSay("Ehm.. sorry... this shouldn't be there, I'm not buying it.", cid)
	end

	if(subType < 1) then
		subType = -1
	end
	if(doPlayerRemoveItem(cid, item, amount, subType) == TRUE) then
		doPlayerAddMoney(cid, items[item].sellPrice * amount)
		selfSay("Here you are.", cid)
	else
		selfSay("No item, no deal.", cid)
	end
end

function onCreatureSay(cid, type, msg)

if (msg == "trade") then
	if (getPlayerStorageValue(cid, 12345) == -1) then
		selfSay("I can\'t trade with you!", cid)
	else
		openShopWindow(cid, itemWindow, onBuy, onSell)
		selfSay("It\'s my offer.", cid)
	end
end

end
 
Will test it!
I will tell you if it works or not :)


EDIT; I think I'm in love :) Thank you <3 It's working exactly how I wanted it to.

EDIT2; If you could help me once more :p
How to make an NPC to just responce on "Hi" when you got a certain condition?
Something like message greet(msg, 'hi') and condition="1" then xD
Hope you get what I mean
 
Last edited:
Back
Top