Joe Rod
Discord: 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:
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
data/creaturescripts/creaturescripts.xml
add this:
data/creaturescripts/scripts/priceItem.lua
add this:
not tested at all
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: