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

CreatureEvent Show Item Price onLook

Joe Rod

Discord: joerod1
Joined
Mar 16, 2011
Messages
499
Solutions
2
Reaction score
172
GitHub
joerod1
Hi, this is a simple code to add something extra value on description of an item: its price.
this was requested here

is displayed by this way:
Code:
14:35 You see an Ice Stone. A peculiar stone that may cause some pokemon to evolve. It weights 10 oz. Price: 5000 gp.
14:35 You see 99 Ice Stones. A peculiar stone that may cause some pokemon to evolve. They weight 990 oz. Price: 495000 gp.

Works on TFS 0.3.6/0.4(i guess), but it could be easy change to another version (i guess)


data/creaturescripts/scripts/login.lua
add this before: return true
Code:
registerCreatureEvent(cid, "PriceItem")

data/creaturescripts/creaturescripts.xml
add this:
Code:
<event type="look" name="PriceItem" event="script" value="priceItem.lua"/>

data/creaturescripts/scripts/priceItem.lua
add this:
Code:
function round(num, idp) --by Cykotitan
   return tonumber(string.format("%." .. (idp or 0) .. "f", num))
end

function getItemCount(item)
  return item and (getItemWeight(item.uid) > 0 and getItemWeight(item.uid)/getItemWeightById(item.itemid) or 1) or 0
end

local priceList =
{ --HERE YOU ADD AN ITEM BY THIS WAY : [itemid or itemname] = price,
  ["Ice Stone"] = 5000,
  [11453] = 7000,
  [2394]  = 500
}
function onLook(cid, thing, position, lookDistance)
  if (not isCreature(thing.uid)) then
  local priceItem = false
  local itemId = thing.itemid
  local itemName = getItemNameById(itemId)

  if (priceList[itemId]) then
  priceItem = priceList[itemId]
  elseif (priceList[itemName]) then
  priceItem = priceList[itemName]
  end

  if (priceItem) then
  local quantity = getItemCount(thing)
  local str = "You see ".. (quantity > 1 and quantity or getArticle(itemName))
  str = str .. " "..getItemNameById(itemId).. (quantity > 1 and "s" or "")..". "..getItemDescriptionsById(itemId).description
  
  str = str.. (quantity > 1 and " They weight " or " It weights ")
  str = str..round(getItemWeight(thing.uid),2) .. " oz."
  totalPrice = priceItem * quantity
  str = str .." Price: "..totalPrice.." gp." 
  doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, str)
  return false
  end

  end
  return true
end

not tested at all
 
Last edited:
Thank you very much for your effort!

Edit: MY BAD! SORRY!

Its working pretty well, you are amazing!
 
Last edited:
But is there any way to include some other attributes from the itens?

1:54 You see a fire rod (Atk:1, protection fire +50%).
It weighs 23.00 oz.

Durability: 200/200. It can absorb fire attacks by 50 percent.
ItemID: [2191].
Position: [X: 1096] [Y: 1210] [Z: 7].
21:55 You see a fire rod. Durability: 200/200. It can absorb fire attacks by 50 percent. Price: 5000 gp.
 
yes, use: getItemAttack(uid) to check the attack. The weight is there at function getItemCount(uid), check how i did it... and percent i don't know how to check it
 
Well Joe, thank you very much! I will learn how exactly the code works, find the other functions i need and will try to include then.
Hope i can help you someday!!!
 
for TFS 1.1:
\data\events\scripts\player.lua

above
Code:
	self:sendTextMessage(MESSAGE_INFO_DESCR, description)
end

add
Code:
	if thing:isItem() then
		local itt = thing:getType()
		local it_id = itt:getId()
		local it_n = itt:getName()
		local priceItem = nil
	
		if (priceList[it_id]) then
			priceItem = priceList[it_id]
		elseif (priceList[it_n]) then
			priceItem = priceList[it_n]
		end

		if priceItem then
			description = description .. "\nWorth: ".. math.max(1, thing:getCount()) * priceItem .." gp."
		end
	end

and add this at beggining of file(line 1)
Code:
local priceList =
{
  ["fire sword"] = 5000,
  [11453] = 7000,
  [2394]  = 500
}
 
Last edited:
I use 0.3.7, and it's working as intended.
Currently it shows,
Code:
You see a backpack.  Price: 10 gp.
Is it possible to instead simply add this line as an extra description on the object instead of overwriting the normal on-look function?
Code:
You see a backpack (Vol:20).
It weighs 931.54 oz.
Price: 10gp.
ItemID: [1988].
Position: [X: 1386] [Y: 1342] [Z: 7].
 
I use 0.3.7, and it's working as intended.
Currently it shows,
Code:
You see a backpack.  Price: 10 gp.
Is it possible to instead simply add this line as an extra description on the object instead of overwriting the normal on-look function?
Code:
You see a backpack (Vol:20).
It weighs 931.54 oz.
Price: 10gp.
ItemID: [1988].
Position: [X: 1386] [Y: 1342] [Z: 7].


Items.xml
Code:
        <attribute key="description" value="It's price is X gold coins." />
 
Items.xml
Code:
        <attribute key="description" value="It's price is X gold coins." />
Yes I could do that, however changing the 'price' later would be very tedious.
Having it in an external script using a table would allow me to remove the prices altogether, or change the prices much faster if they need changing in the future.
 
Yes I could do that, however changing the 'price' later would be very tedious.
Having it in an external script using a table would allow me to remove the prices altogether, or change the prices much faster if they need changing in the future.

Thats what i was looking for too, maybe insert into the sources another attribute key like description?
 
Isn't there "worth" attribute in 0.3.7 items.xml? Saw it in tryller's tfs.
 
Worth is for money itens. If worth value is 1, then its 1 gp, if its 10, its the same as 10 gp... it works for coins
 
But is there any way to include some other attributes from the itens?

1:54 You see a fire rod (Atk:1, protection fire +50%).
It weighs 23.00 oz.
Durability: 200/200. It can absorb fire attacks by 50 percent.
ItemID: [2191].
Position: [X: 1096] [Y: 1210] [Z: 7].
21:55 You see a fire rod. Durability: 200/200. It can absorb fire attacks by 50 percent. Price: 5000 gp.

Edited, now it shows the weight:

Code:
14:35 You see an Ice Stone. A peculiar stone that may cause some pokemon to evolve. It weights 10 oz. Price: 5000 gp.
14:35 You see 99 Ice Stones. A peculiar stone that may cause some pokemon to evolve. They weight 990 oz. Price: 495000 gp.
 
Last edited:
thank you Joe, but now im getting this error:

Description:
[22/03/2015 20:46:54] data/creaturescripts/scripts/lookpriceotland.lua:33: attempt to call field 'round' (a nil value)
[22/03/2015 20:46:54] stack traceback:
[22/03/2015 20:46:54] data/creaturescripts/scripts/lookpriceotland.lua:33: in function <data/creaturescripts/scripts/lookpriceotland.lua:15>
 
oh man, not again! kkkkkk
24qoais.jpg
 
my bad xD, copy again
btw, don't use Dreamwaver, use Sublime Text 3 or Notepad++
 
Back
Top