• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

Action [TFS 1.0] House market (buy/sell)

zbizu

Legendary OT User
Joined
Nov 22, 2010
Messages
3,323
Solutions
26
Reaction score
2,696
Location
Poland
Offline house market.
Lets you trade your items without losing their attributes.
Do not post that script on other forums without my permission

YOU NEED NEWEST TFS OR PLAYERS MAY STEAL YOUR MARKET

Screenshots:
1z64183.png

hx7pf4.png

kf5wnn.png


To create your own market:
1. place a basket on house edge
2. put container with items you want to sell
3. put an item which handles textfields inside a basket and type something like that:
Sell[demon shield, 40000; mace, 30; skull staff, 6000]
Buy[stuffed dragon, 5000; mace, 15;]
*Sell means item you SELL, Buy means item you want to BUY

To do: limit of items player wants to buy, "child" containers support

Query to hold inbox items queue:
Code:
CREATE TABLE IF NOT EXISTS `onlogin_sendtoinbox` (
  `player_id` int(11) NOT NULL DEFAULT '0',
  `itemtype` smallint(6) NOT NULL DEFAULT '0',
  `count` smallint(5) NOT NULL DEFAULT '0',
  `price` bigint(20) unsigned NOT NULL DEFAULT '0',
  `actionid` bigint(20) unsigned NOT NULL DEFAULT '0',
  `description` varchar(255) NOT NULL DEFAULT '',
  `text` varchar(1023) NOT NULL DEFAULT '',
  `writer_guid` int(11) NOT NULL DEFAULT 0,
  `written_at` bigint(20) NOT NULL,
  FOREIGN KEY (`player_id`) REFERENCES `players`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB

Script:
/data/actions/scripts/house_shop.lua: http://wklej.to/N3ntS

actions.xml:
<action itemid="1989" script="house_shop.lua"/>

/data/events/events.xml(just set enabled to 1)
<event class="Player" method="onMoveItem" enabled="1"/>
player.lua replace this:
Code:
function Player:OnMoveItem(item, count, fromPosition, toPosition)
   return true
end
to this:
Code:
function Player:onMoveItem(item, count, fromPosition, toPosition)
  function isHousetile(position)
   local t = Tile(position)
   if t == nil then
   return false
   end
   return t:hasFlag(TILESTATE_HOUSE)
   end
   if isHousetile(item:getPosition()) then   -- yup, it's a housetile
     if self:getAccountType() == ACCOUNT_TYPE_GOD and self:getGroup():getAccess() then -- is server admin
       return true
     end
     if Tile(item:getPosition()):getHouse():getOwnerGuid() == self:getGuid() then -- is house owner
       return true
     end
     if isHousetile(self:getPosition()) then -- is inside a house
       return true
     end
     -- random player
     self:sendCancelMessage("Sorry, not possible.")
     return false
   end
return true
end

/data/events/events.xml (just enable it)
<event class="Player" method="onTradeRequest" enabled="1"/>

/data/events/scripts/player.lua:
Code:
function Player:onTradeRequest(target, item)
   if isHousetile(item:getPosition()) then   -- is this a house
     if self:getAccountType() == ACCOUNT_TYPE_GOD and self:getGroup():getAccess() then -- is server admin
       return true
     end

     if Tile(item:getPosition()):getHouse():getOwnerGuid() == self:getGuid() then -- is house owner
       return true
     end

     if isHousetile(self:getPosition()) then -- is inside a house
       return true
     end
     -- random player
     self:sendCancelMessage("This item doesn't belong to you.")
     return false
   end
return true
end

add to /data/creaturescripts/scripts/login.lua(above return true):
Code:
  home_market_spend = 0
   home_market_items = {}
   home_market_items_msg = ""

   for i = 1, 30 do
   -- don't let them send milions of trash and then get it at once!
      local a = db.storeQuery("SELECT * FROM `onlogin_sendtoinbox` WHERE `player_id` = " .. getPlayerGUID(cid) .. " LIMIT 1")
      if a then
       local it_id = Player(cid):getInbox():addItem(result.getDataInt(a, "itemtype"), result.getDataInt(a, "count"), true, 1)
       it_id:setAttribute(1, result.getDataInt(a, "actionid"))
       it_id:setAttribute(4, result.getDataString(a, "description"))
       it_id:setAttribute(8, result.getDataString(a, "text"))
       it_id:setAttribute(32, getPlayerNameByGUID(result.getDataInt(a, "writer_guid")))
       it_id:setAttribute(16, getPlayerNameByGUID(result.getDataInt(a, "written_at")))
       home_market_spend = home_market_spend + result.getDataInt(a, "price")
       table.insert(home_market_items, {getItemName(result.getDataInt(a, "itemtype")), result.getDataInt(a, "count")})
       db.query("DELETE FROM `onlogin_sendtoinbox` WHERE `player_id` = " .. getPlayerGUID(cid) .. " LIMIT 1")
      else
       break
      end
   end

   if #home_market_items > 0 then
     for i = 1, #home_market_items do
       home_market_items_msg = home_market_items_msg .. i_ar(home_market_items[i][1], home_market_items[i][2]) .. " " .. i_n(home_market_items[i][1], home_market_items[i][2])
       if #home_market_items ~= 1 and i ~= #home_market_items then
         home_market_items_msg = home_market_items_msg .. ", "
       end
     end

     doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "[Store]: During your absence, players sold you " .. #home_market_items .. " item(s) for " .. home_market_spend .. " gold coins in total.")
     if #home_market_items < 31 then
       doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "[Store]: Items you bought: " .. home_market_items_msg)
     else
       doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "[Store]: Check your inbox to see items you received.")
     end
   end
 
Last edited:
I found critical problem with this system.
DO NOT USE IT BEFORE TFS DEVS DO SOMETHING TO BLOCK TRADE REQUESTS
 
Well done even if its not working yet!
Keep it up!

Kind Regards,
Eldin
.
 
Well done even if its not working yet!
Keep it up!

Kind Regards,
Eldin
.
Even if they don't implement missing feature, I'll keep this script here. Maybe someone find alternative solution.
 
Last edited:
Even if they don't implement missing feathure, I'll keep this script here. Maybe someone find alternative solution.
zbizu Great Work. i have made the same thing time before it was Based on A Real Market with Places it was like this
2 Teleport
--
1-Customer
2-Seller
--
if you join as a customer you join at the middle of the market
if you join as a seller.there must be enough space.max it 150 seller for now.you will be in such square
0 = tile, 1 = player
000
010
000
And You Put your items on the 0.When you put an item it automatically get an action id and you get storage
--
c++ part
The function onMove.So Players Can't Steal Items,Reset Price when you take item again,for custom to buy it will take money from him and give it to you and give him the item
Function onSpeak.when you add item.you say the price you want.

Hope You Got Me :)

EDIT

onTradeRequest
http://speedy*****malware.localhost/BeEbx/tradeRequest.rar
How To Use:
Code:
function onTradeRequest(cid,target,item)
if item.itemid == 5500 then
return doPlayerSendCancel(cid, "You Can't Trade This Item") and false
end

if getPlayerStorageValue(cid, 9001) == 1 then
return false
end
 
Last edited:
@tetra20
I managed to fix your code
I'll send a pull request and post new tfs working with this script.
 
Last edited:
This isn't working for me, I get the npc window... But it's empty.
 
This isn't working for me, I get the npc window... But it's empty.
first(from the left) item in basket needs to be something to write(scroll, letter, label, whatever)
second item is container to put items you want to sell
if you have 0 gold in bank balance - buy offers won't show up, because you can't pay for items you want to buy
if you didn't put to container item you wrote that you're selling, it won't show up either, because you can't sell something you don't have

Do it as seen on screenshot and it should work.
 
All check and not working for me.
I tried changing the letter to a label and I get this error:
116db8d8dc.png
 
All check and not working for me(...)

ah, I forgot that I use 0.4 compat lib
add this to global.lua:
Code:
string.trim = function (str)
return str:gsub("^%s*(.-)%s*$", "%1")
end

string.explode = function (str, sep, limit)
if(type(sep) ~= 'string' or isInArray({tostring(str):len(), sep:len()}, 0)) then
   return {}
end

local i, pos, tmp, t = 0, 1, "", {}
for s, e in function() return string.find(str, sep, pos) end do
  tmp = str:sub(pos, s - 1):trim()
  table.insert(t, tmp)
  pos = e + 1

  i = i + 1
  if(limit ~= nil and i == limit) then
  break
  end
end

tmp = str:sub(pos):trim()
table.insert(t, tmp)
return t
end
 
Is still not working, no errors at all, just no items in the npc window :(

@Edit: I don't really know what is happening, but now is working XD
 
Sometimes window doesn't refresh itself. I don't know what causes that and I can't find a solution. It's random.
About placement issue: I'll do "for" loop later to find item with textfield
 
It's okay @tetra20. I learnt some c++ by fixing that ^^

Updated first post(code in wklej.to link)
From now:
- my script looks in all containers for item to sell
- letter/scroll/label with offers can be placed on any slot(main container only).

I still need help to match this pattern for gsub function to make offer amount smaller:
itemid, price, amount;
where itemid and , should be matched
price ignored
amount matched between , and ; (if there is price in the middle)
so I can make buy limit and players won't sell you 20 of item, while you need 5 only
 
Last edited:
It's okay @tetra20. I learnt some c++ by fixing that ^^

Updated first post(code in wklej.to link)
From now:
- my script looks in all containers for item to sell
- letter/scroll/label with offers can be placed on any slot(main container only).

I still need help to match this pattern for gsub function to make offer amount smaller:
itemid, price, amount;
where itemid and , should be matched
price ignored
amount matched between , and ; (if there is price in the middle)
so I can make buy limit and players won't sell you 20 of item, while you need 5 only
Really Sorry I Can't Help You With tfs 1.0 lua Because i hate metatables and the scripting of tfs 1.0.i can help you with any c++ if you need and a little of tfs 1.0 scripting
 
Really Sorry I Can't Help You With tfs 1.0 lua Because i hate metatables and the scripting of tfs 1.0.i can help you with any c++ if you need and a little of tfs 1.0 scripting
Well, take a look here: https://github.com/otland/forgottenserver/pull/610
I know you hate metatables(I don't like them either), but I want this feathure to be merged for good, because I plan to use this system in my ot without moving away from master branch.
 
Back
Top