Jack Parsons
Member
I've developed a talkaction that allows a player to open a shovel hole for a price (I've decided that 1k is a fair price, considering the player's stupidity of not having a shovel). The script detects whether there's a hole in front of the player or not, and then checks whether the player has the necessary amount of money or not, and then it transforms the tile accordingly (Just like shovel.lua).
Entry in talkactions.xml:
openhole.lua:
Entry in talkactions.xml:
Code:
<talkactions>
...
<talkaction words="!openhole" script="openhole.lua"/>
...
</talkactions>
openhole.lua:
Code:
-- Script by Rederick Deathwill (Ericson Willians).
function onSay(cid, words, param)
local price = 1000
local p = Player(cid)
local pPos = p:getPosition()
local pDir = p:getDirection()
local holes = {468, 481, 483}
local holePos = nil
local isEverythingFalse = true
local booleanHoles = {false, false, false}
if pDir == NORTH then
holePos = {x = pPos['x'], y = pPos['y']-1, z = pPos['z'], stackpos = 0}
elseif pDir == SOUTH then
holePos = {x = pPos['x'], y = pPos['y']+1, z = pPos['z'], stackpos = 0}
elseif pDir == WEST then
holePos = {x = pPos['x']-1, y = pPos['y'], z = pPos['z'], stackpos = 0}
elseif pDir == EAST then
holePos = {x = pPos['x']+1, y = pPos['y'], z = pPos['z'], stackpos = 0}
end
for i, v in ipairs(holes) do
local thing = getTileThingByPos(holePos)
if thing["itemid"] == v then
booleanHoles[i] = true
if p:getMoney() >= price then
p:say("Open hole!", TALKTYPE_MONSTER_SAY)
local h = Item(thing["uid"])
h:transform(thing["itemid"] + 1)
h:decay()
p:removeMoney(price)
else
p:sendTextMessage(MESSAGE_INFO_DESCR, "You need " .. price .. " gp in order to open this hole. Go get a shovel!")
p:getPosition():sendMagicEffect(CONST_ME_POFF)
end
end
end
for _, v in ipairs(booleanHoles) do
if v then
isEverythingFalse = false
end
end
if isEverythingFalse then
p:sendTextMessage(MESSAGE_INFO_DESCR, "Don't be silly, what you're trying to open is not a hole.")
p:getPosition():sendMagicEffect(CONST_ME_POFF)
end
return false
end