sharinn
Active Member
- Joined
- Aug 27, 2011
- Messages
- 156
- Solutions
- 8
- Reaction score
- 42
- GitHub
- ArturKnopik
- Twitch
- krecikondexin
Hello, I created a script with a chest(we can use all containers) when you move an item out of the chest you buy it.
Place code in good place for good formating or items description
Requirements(look on help code):
Container requires a setCustomAttribute("sellChest", 1)
Items in chest require setCustomAttribute("sellPrice", value) where value = price in gp
stackable items - number items on stuck = maximum number of items that can be purchased
add in
add in
add in
add script (revscript)
help code(revscript): generate sample chest
on my ot whe i use item with id 6540, i generate this chest(no problem move this code to startup script), action 100 on my ot make item unmovable/untradeable
Place code in good place for good formating or items description
Requirements(look on help code):
Container requires a setCustomAttribute("sellChest", 1)
Items in chest require setCustomAttribute("sellPrice", value) where value = price in gp
stackable items - number items on stuck = maximum number of items that can be purchased
add in
Code:
function Player:onMoveItem(item, count, fromPosition, toPosition, fromCylinder, toCylinder)
Lua:
-- custom shop unmovable
if item:getCustomAttribute("sellChest") then
self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
return false
end
-- custom shop anty trash
if toCylinder:isContainer() then
if toCylinder:getCustomAttribute("sellChest") then
self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
return false
end
end
if not fromPosition.x ~= CONTAINER_POSITION then
local itemChect
if CONTAINER_POSITION ~= toPosition.x then
itemChect = Tile(toPosition):getTopDownItem()
end
if itemChect then
if itemChect:getCustomAttribute("sellChest") then
self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
return false
end
end
end
-- custom shop
local itemPrice = item:getCustomAttribute("sellPrice")
if itemPrice then
if self:removeMoney(itemPrice*count) then
doPlayerAddItem(self, item:getId(), count)
self:sendTextMessage(MESSAGE_INFO_DESCR, "You buy " .. count .. " " .. item:getName().. " for " .. itemPrice*count .. "gp.")
return false
else
if count == 1 then
self:sendTextMessage(MESSAGE_INFO_DESCR, "You need more gold to buy " .. item:getName() .. "!")
else
self:sendTextMessage(MESSAGE_INFO_DESCR, "You need more gold to buy " ..count .. " " .. item:getName() .. "!")
end
return false
end
end
add in
Code:
function Player:onLook(thing, position, distance)
Code:
--Shop item price
if thing:getCustomAttribute("sellPrice") then
description = description .. "\nCost: ".. thing:getCustomAttribute("sellPrice").. "gp "
end
add in
Code:
function Player:onTradeRequest(target, item)
Code:
if item:getCustomAttribute("sellChest") or item:getCustomAttribute("sellPrice") then
self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
return false
end
add script (revscript)
Code:
local unuseable = Action()
function unuseable.onUse(player, item, fromPosition, target, toPosition, isHotkey)
if item:getCustomAttribute("sellPrice") then
player:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
return false
end
return true
end
unuseable:aid(100)
unuseable:register()
help code(revscript): generate sample chest
on my ot whe i use item with id 6540, i generate this chest(no problem move this code to startup script), action 100 on my ot make item unmovable/untradeable
Lua:
local sellChest = Action()
function sellChest.onUse(player, item, fromPosition, target, toPosition, isHotkey)
local itemBox = Game.createItem(1738, 1, player:getPosition())
--itemBox:setActionId(100)
itemBox:setCustomAttribute("sellChest", 1)
local itemSell = Game.createItem(7620, 100, player:getPosition())
itemSell:setCustomAttribute("sellPrice", 56)
itemSell:setActionId(100)
itemSell:moveTo(itemBox)
itemSell = Game.createItem(2400, 1, player:getPosition())
itemSell:setCustomAttribute("sellPrice", 20000)
itemSell:setActionId(100)
itemSell:moveTo(itemBox)
end
sellChest:id(6540)
sellChest:register()
Attachments
-
127044549_369658270984986_6608968849514736054_n.png868.4 KB · Views: 105 · VirusTotal
Last edited: