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

openShopWindow

Oskar1121

Excellent OT User
Joined
Jul 15, 2009
Messages
700
Reaction score
710
Location
Poland
Hello everyone.
I want to when player use an object then opens a window of trade with items what I want.
I have this script, with NPC file (my Grizzly Adams) and when I paste it into actions script this doesn't work, anybody know what is wrong?
PHP:
local huntsMan_rank = { 
                    {id=11208, buy=0, sell=50, name="antlers"}, 
                    {id=10549, buy=0, sell=100, name="bloody pincers"}, 
                    {id=11183, buy=0, sell=35, name="crab pincers"}, 
                    {id=10573, buy=0, sell=55, name="cyclops toe"}, 
                    {id=10564, buy=0, sell=30, name="frosty ear of a troll"}, 
                    {id=11193, buy=0, sell=600, name="hydra head"}, 
                    {id=11366, buy=0, sell=80, name="lancer beetle shell"}, 
                    {id=10578, buy=0, sell=420, name="mutated bat ear"}, 
                    {id=11222, buy=0, sell=400, name="sabretooth"}, 
                    {id=11367, buy=0, sell=20, name="sandcrawler shell"}, 
                    {id=10547, buy=0, sell=280, name="scarab pincers"}, 
                    {id=11365, buy=0, sell=60, name="terramite legs"}, 
                    {id=11363, buy=0, sell=170, name="terramite shell"}, 
                    {id=11184, buy=0, sell=30000, name="terrorbird beak"}, 
                     
                    {id=7398, buy=0, sell=500, name="cyclops trophy"}, 
                    {id=7401, buy=0, sell=500, name="minotaur trophy"} 
                    } 
local items = {} 
for _, item in ipairs(huntsMan_rank) do 
    items[item.id] = {storage = item.storage, item_id = item.id, buyPrice = item.buy, sellPrice = item.sell, subType = 0, realName = item.name} 
end 

local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpacks) 
    if items[item].buyPrice ~= 0 then 
        doPlayerRemoveMoney(cid, amount * items[item].buyPrice) 
        for i = 1, amount do 
            doPlayerAddItem(cid, items[item].item_id, amount) 
        end 
        doNPCTalkALot(cid, 200, {"You bought "..amount.." "..items[item].realName.." for "..items[item].buyPrice * amount.." gold coins."}) 
    end 
end 
  
local onSell = function(cid, item, subType, amount, ignoreCap, inBackpacks) 
    if items[item].sellPrice ~= 0 then 
        doPlayerAddMoney(cid, items[item].sellPrice * amount) 
        doPlayerRemoveItem(cid, items[item].item_id, amount) 
        doNPCTalkALot(cid, 200, {"You sell "..amount.." "..items[item].realName.." for "..items[item].sellPrice * amount.." gold coins."}) 
    end 
end 

openShopWindow(cid, huntsMan_rank, onBuy, onSell)
 
Hello everyone.
I want to when player use an object then opens a window of trade with items what I want.
I have this script, with NPC file (my Grizzly Adams) and when I paste it into actions script this doesn't work, anybody know what is wrong?
PHP:
local huntsMan_rank = { 
                    {id=11208, buy=0, sell=50, name="antlers"}, 
                    {id=10549, buy=0, sell=100, name="bloody pincers"}, 
                    {id=11183, buy=0, sell=35, name="crab pincers"}, 
                    {id=10573, buy=0, sell=55, name="cyclops toe"}, 
                    {id=10564, buy=0, sell=30, name="frosty ear of a troll"}, 
                    {id=11193, buy=0, sell=600, name="hydra head"}, 
                    {id=11366, buy=0, sell=80, name="lancer beetle shell"}, 
                    {id=10578, buy=0, sell=420, name="mutated bat ear"}, 
                    {id=11222, buy=0, sell=400, name="sabretooth"}, 
                    {id=11367, buy=0, sell=20, name="sandcrawler shell"}, 
                    {id=10547, buy=0, sell=280, name="scarab pincers"}, 
                    {id=11365, buy=0, sell=60, name="terramite legs"}, 
                    {id=11363, buy=0, sell=170, name="terramite shell"}, 
                    {id=11184, buy=0, sell=30000, name="terrorbird beak"}, 
                     
                    {id=7398, buy=0, sell=500, name="cyclops trophy"}, 
                    {id=7401, buy=0, sell=500, name="minotaur trophy"} 
                    } 
local items = {} 
for _, item in ipairs(huntsMan_rank) do 
    items[item.id] = {storage = item.storage, item_id = item.id, buyPrice = item.buy, sellPrice = item.sell, subType = 0, realName = item.name} 
end 

local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpacks) 
    if items[item].buyPrice ~= 0 then 
        doPlayerRemoveMoney(cid, amount * items[item].buyPrice) 
        for i = 1, amount do 
            doPlayerAddItem(cid, items[item].item_id, amount) 
        end 
        doNPCTalkALot(cid, 200, {"You bought "..amount.." "..items[item].realName.." for "..items[item].buyPrice * amount.." gold coins."}) 
    end 
end 
  
local onSell = function(cid, item, subType, amount, ignoreCap, inBackpacks) 
    if items[item].sellPrice ~= 0 then 
        doPlayerAddMoney(cid, items[item].sellPrice * amount) 
        doPlayerRemoveItem(cid, items[item].item_id, amount) 
        doNPCTalkALot(cid, 200, {"You sell "..amount.." "..items[item].realName.." for "..items[item].sellPrice * amount.." gold coins."}) 
    end 
end 

openShopWindow(cid, huntsMan_rank, onBuy, onSell)

This is an NPC script, not an Action script. D'oh.
 
Here is script with source:
PHP:
void Player::openShopWindow()
{
	sendShop();
	sendGoods();
}

void Player::closeShopWindow(Npc* npc/* = NULL*/, int32_t onBuy/* = -1*/, int32_t onSell/* = -1*/)
{
	if(npc || (npc = getShopOwner(onBuy, onSell)))
		npc->onPlayerEndTrade(this, onBuy, onSell);

	if(shopOwner)
		sendCloseShop();

	shopOwner = NULL;
	purchaseCallback = saleCallback = -1;
	shopOffer.clear();
}

bool Player::canShopItem(uint16_t itemId, uint8_t subType, ShopEvent_t event)
{
	for(ShopInfoList::iterator sit = shopOffer.begin(); sit != shopOffer.end(); ++sit)
	{
		if(sit->itemId != itemId || ((event != SHOPEVENT_BUY || sit->buyPrice < 0)
			&& (event != SHOPEVENT_SELL || sit->sellPrice < 0)))
			continue;

		if(event == SHOPEVENT_SELL)
			return true;

		const ItemType& it = Item::items[id];
		if(it.isFluidContainer() || it.isSplash() || it.isRune())
			return sit->subType == subType;

		return true;
	}

	return false;
}
Can you edit it?
 
I'm pretty sure that COMMUNITY can solve such a things in short time

Oskar: you forgot sendShop and sendGoods codes, but it doesnt really matter cause its in source anyway

too bad that I have math exam tommorow and have to study bit more cause I really wanna to try this shit xD
 
Back
Top