<?xml version="1.0"?>
<npc name="Bed Specialist" script="data/npc/scripts/housekits.lua" access="3" lookdir="3" autowalk="25">
<health now="1000" max="1000"/>
<look type="128" head="20" body="100" legs="50" feet="99"/>
<parameters>
<parameter key="module_shop" value="1" />
<parameter key="message_greet" value="Hello |PLAYERNAME|. I sell green, red, yellow bed kits, and the standard bed kit. You can use theese kits on a bed inside a house to change its design. (each kit cost 300gp)" />
<parameter key="shop_buyable" value="green bed kit,7904,300;red bed kit,7905,300;yellow bed kit,7906,300;standard bed kit,7907,300" />
</parameters>
</npc>
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
-- OTServ event handling functions start
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end
-- OTServ event handling functions end
npcHandler:addModule(FocusModule:new())
local KIT_GREEN = 7904
local KIT_RED = 7905
local KIT_YELLOW = 7906
local KIT_REMOVAL = 7907
local BEDS = {
[KIT_GREEN] = {{7811, 7812}, {7813, 7814}},
[KIT_RED] = {{7815, 7816}, {7817, 7818}},
[KIT_YELLOW] = {{7819, 7820}, {7821, 7822}},
[KIT_REMOVAL] = {{1754, 1755}, {1760, 1761}}
}
local function internalBedTransform(item, itemEx, toPosition, id1, id2)
doTransformItem(itemEx.uid, id1)
doTransformItem(getThingfromPos(toPosition).uid, id2)
doRemoveItem(item.uid)
doSendMagicEffect(getThingPos(itemEx.uid), CONST_ME_POFF)
doSendMagicEffect(toPosition, CONST_ME_POFF)
end
function onUse(cid, item, fromPosition, itemEx, toPosition)
local newBed = BEDS[item.itemid]
if not newBed or getTileHouseInfo(getCreaturePosition(cid)) == FALSE then
return FALSE
end
if isInArray({newBed[1][1], newBed[2][1]}, itemEx.itemid) == TRUE then
doPlayerSendCancel(cid, "You already have this bed modification.")
return TRUE
end
for kit, bed in pairs(BEDS) do
if bed[1][1] == itemEx.itemid then
toPosition.y = toPosition.y + 1
internalBedTransform(item, itemEx, toPosition, newBed[1][1], newBed[1][2])
break
elseif bed[2][1] == itemEx.itemid then
toPosition.x = toPosition.x + 1
internalBedTransform(item, itemEx, toPosition, newBed[2][1], newBed[2][2])
break
end
end
return TRUE
end