• 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

JoeRod #1189
Joined
Mar 16, 2011
Messages
499
Solutions
2
Reaction score
165
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:

Vesgo

Member
Joined
Dec 4, 2009
Messages
356
Solutions
1
Reaction score
15
Location
Brasil
Thank you very much for your effort!

Edit: MY BAD! SORRY!

Its working pretty well, you are amazing!
 
Last edited:

Vesgo

Member
Joined
Dec 4, 2009
Messages
356
Solutions
1
Reaction score
15
Location
Brasil
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.
 
OP
OP
Joe Rod

Joe Rod

JoeRod #1189
Joined
Mar 16, 2011
Messages
499
Solutions
2
Reaction score
165
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
 

Vesgo

Member
Joined
Dec 4, 2009
Messages
356
Solutions
1
Reaction score
15
Location
Brasil
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!!!
 

zbizu

Legendary OT User
Joined
Nov 22, 2010
Messages
3,161
Solutions
23
Reaction score
2,313
Location
Poland
GitHub
Zbizu
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:

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,825
Solutions
438
Reaction score
3,967
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].
 

Jacobs

Webdev, mapper
Joined
Jun 22, 2014
Messages
418
Solutions
4
Reaction score
316
Location
Slovakia
GitHub
Jacobs63
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." />
 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,825
Solutions
438
Reaction score
3,967
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.
 

Vesgo

Member
Joined
Dec 4, 2009
Messages
356
Solutions
1
Reaction score
15
Location
Brasil
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?
 

zbizu

Legendary OT User
Joined
Nov 22, 2010
Messages
3,161
Solutions
23
Reaction score
2,313
Location
Poland
GitHub
Zbizu
Isn't there "worth" attribute in 0.3.7 items.xml? Saw it in tryller's tfs.
 

Vesgo

Member
Joined
Dec 4, 2009
Messages
356
Solutions
1
Reaction score
15
Location
Brasil
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
 
OP
OP
Joe Rod

Joe Rod

JoeRod #1189
Joined
Mar 16, 2011
Messages
499
Solutions
2
Reaction score
165
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:

Vesgo

Member
Joined
Dec 4, 2009
Messages
356
Solutions
1
Reaction score
15
Location
Brasil
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>
 

Vesgo

Member
Joined
Dec 4, 2009
Messages
356
Solutions
1
Reaction score
15
Location
Brasil
oh man, not again! kkkkkk
24qoais.jpg
 
OP
OP
Joe Rod

Joe Rod

JoeRod #1189
Joined
Mar 16, 2011
Messages
499
Solutions
2
Reaction score
165
my bad xD, copy again
btw, don't use Dreamwaver, use Sublime Text 3 or Notepad++
 
Top