--root of server--
HOUSES = {
[334] = {center={x=258,y=194,z=7},sizex=5,sizey=5}, --- just a example
}
GROUND = {457,407,458,405,106,424,415,448}
WALLS = {
[1] = {
[0] =0,
[1] =1111,
[2] =1112,
[3] =1115,
[4] =1113,
[5] =1220,
[6] =1222,
},
[2] = {
[0] =0,
[1] =1025,
[2] =1026,
[3] =1029,
[4] =1027,
[5] =1220,
[6] =1222,
},
[3] = {
[0] = 0,
[1] =5519,
[2] =3362,
[3] =5520,
[4] =3363,
[5] =1220,
[6] =1222,
}
}
TYPES = {
s = {[0] = ' *',[1]=' |',[2]=' -',[3] = '|',[4] = '|',[5]='P'},
[1] = {
{4 ,2, 2,2},
{1, 0 ,0,{[0]=0,1}},
{1 ,0, 0,{[0]=0,5}},
{1 ,2, 2,3},
},
[2] = {
{4,2,2,2,2},
{1,0,{[0]=0,1},0,{[0]=0,1}},
{1,0,{[0]=0,5},0,{[0]=0,5}},
{1,2,3,2,3},
},
[3] = {
{4,2,2,2,2,2,2,2,2},
{1,0,0,0,0,0,0,0,{[0]=0,1}},
{1,0,0,0,0,0,0,0,{[0]=0,5}},
{1,0,0,{[0]=0,1481},0,0,0,0,{[0]=0,5}},
{1,0,0,0,0,0,0,0,1},
{1,0,0,0,0,4,2,2,3},
{1,0,0,0,0,{[0]=0,1},0,0,1},
{1,0,0,0,0,{[0]=0,5},0,0,1},
{1,0,0,0,0,1,0,0,1},
{1,2,2,2,2,3,2,2,3},
},
[4] = {
{4,2,2,2,6,2},
{1,{[0]=0,1620},0,{[0]=0,1},0,1},
{1,{[0]=0,1620},0,{[0]=0,5},0,1},
{1,{[0]=0,1620},0,1,0,1},
{1,{[0]=0,1620},0,1,{[0]=0,1481},1},
{1,2,2,3,2,3},
},
[5] = {
{4,2,2,2,2,2,2,2,2,2,2},
{1,0,0,0,{[0]=0,1620},1,0,0,0,0,1},
{1,0,0,0,{[0]=0,1620},1,0,0,0,0,1},
{5,0,0,0,{[0]=0,1620},1,0,0,0,0,1},
{5,0,0,0,{[0]=0,1620},1,0,0,0,0,{[0]=0,5}},
{1,2,6,2,2,3,0,0,0,0,1},
{1,0,0,1,0,0,0,0,0,0,1},
{1,0,0,5,0,0,0,0,0,0,1},
{1,0,0,1,0,0,0,0,0,0,1},
{1,{[0]=0,1481},{[0]=0,1481},1,0,0,0,0,0,0,1},
{1,2,2,2,2,2,2,2,2,2,3},
},
[6] = {
{4,{2,3950},2,2,{2,3950},2},
{1,0,0,0,{[0]=0,1620},1},
{{1,3948},0,0,0,{[0]=0,1620},1},
{5,0,0,4,{2,3950},3},
{{1,3948},0,0,{[0]=0,1},0,1},
{1,0,0,{[0]=0,5},0,1},
{1,2,2,3,2,3},
}
}
--[[
ground = 0
| = 1
_ = 2
_| = 3
. = 4
P = 5 - em pé
* = 6 deitada
]]
--Globalevent [Startup]--
local function executeInArea(pos, area,cmd,...)--by Nord and Mock
local center = {}
center.y = math.floor(#area/2)+1
for y = 1, #area do
for x = 1, #area[y] do
local number = area[y][x]
--if number then
center.x = math.floor(table.getn(area[y])/2)+1
local pos = {x = pos.x + x - center.x, y = pos.y + y - center.y, z = pos.z}
cmd(pos,number,...)
--end
end
end
end
function create(idA,h_type,g_type,wall)
executeInArea(HOUSES[tonumber(idA)].center,TYPES[tonumber(h_type)],function(pos,id)
pos.stackpos = 255
if type(id) == 'number' then
doCreateItem(WALLS[tonumber(wall)][id] == 0 and GROUND[tonumber(g_type)] or WALLS[tonumber(wall)][id] or id,pos)
elseif type(id) == 'table' then
for stack,id_ in pairs(id) do
pos.stackpos = stack
doCreateItem(WALLS[tonumber(wall)][id_] == 0 and GROUND[tonumber(g_type)] or WALLS[tonumber(wall)][id_] or id_,pos)
end
end
end)
end
function begin()
if not ok then
dofile('hconf.lua')
local con,env = connect_db()
local b = con:execute([[SELECT * FROM `made_homes`]])
local k = 1
local back = {}
local c = b:fetch({}, "a")
if c then
repeat
if HOUSES[tonumber(c.houseid) or 0] then
create(c.houseid,c.housetype,c.ground,c.wall)
print(c.houseid..' ...Loaded.')
end
c = b:fetch({}, "a")
until not c
b:close()
con:close()
env:close()
end
ok = 1
end
end
--on startup function just add: begin()--
--NPC--
local focus = {}
local talk_start = 0
local target = 0
dofile('hconf.lua')
local function executeInArea(pos, area,cmd,...)--by Nord and Mock
local center = {}
center.y = math.floor(#area/2)+1
for y = 1, #area do
for x = 1, #area[y] do
local number = area[y][x]
--if number then
center.x = math.floor(table.getn(area[y])/2)+1
local pos = {x = pos.x + x - center.x, y = pos.y + y - center.y, z = pos.z}
cmd(pos,number,...)
--end
end
end
end
function House(id)
if not TYPES[id] then print('sad') return false end
local cx,cy = math.floor(#TYPES[id][1]), math.floor(#TYPES[id])
local s = ''
for y=1,#TYPES[id] do
for x=1,#TYPES[id][1] do
if type(TYPES[id][y][x]) == 'number' then
s = s..(TYPES.s[TYPES[id][y][x]] or ' ?')
else
s = s..(TYPES.s[TYPES[id][y][x][1]] or ' ?')
end
end
s = s..'\n'
end
return s,cx,cy
end
function create(cid)
executeInArea(HOUSES[focus[cid].house].center,TYPES[focus[cid].selected],function(pos,id)
pos.stackpos = 255
if type(id) == 'number' then
doCreateItem(WALLS[focus[cid].wall][id] == 0 and GROUND[focus[cid].c] or WALLS[focus[cid].wall][id] or id ,pos)
elseif type(id) == 'table' then
for stack,id_ in pairs(id) do
pos.stackpos = stack
doCreateItem(WALLS[focus[cid].wall][id_] == 0 and GROUND[focus[cid].c] or WALLS[focus[cid].wall][id_] or id_ ,pos)
end
end
end)
end
function onCreatureSay(cid, type_, msg)
dofile('hconf.lua')
local msg = string.lower(msg)
if getDistanceToCreature(cid) > 4 then
return
end
if msgcontains(msg, 'hi') and not focus[cid] then
selfSay('Do you wish to create a house? Say {change}.',cid)
focus[cid] = {1}
return
end
if focus[cid] then
if focus[cid][1] == 3 then
local n = tonumber(msg:match('(%d+)') or '')
if n then
local s,cx,cy = House(n)
if s then
print(HOUSES[focus[cid].house].sizex,focus[cid].house)
if cx > (HOUSES[focus[cid].house].sizex*2)+1 or cy > (HOUSES[focus[cid].house].sizey*2)+1 then
selfSay('That house is too big for your land, your land is of {'..((HOUSES[focus[cid].house].sizex*2)+1)..'x'..((HOUSES[focus[cid].house].sizey*2)+1)..'} and your house is of a{'..cx..'x'..cy..'}.',cid)
else
doPlayerPopupFYI(cid,'House '..n..', House Type:\n'..s..'\nD = Door\n* = floor\nIs this type to your liking?')
selfSay('Do you want that house type?',cid)
focus[cid][1] = 4
focus[cid].selected = n
end
else
selfSay('That house does not exist or it\'s too big.',cid)
end
else
selfSay('Say a number from 1 to '..#TYPES,cid)
end
elseif focus[cid][1] == 5 then
local n = tonumber(msg:match('(%d+)') or '')
if n then
if WALLS[n] then
doSetItemOutfit(cid,WALLS[n][1],1000)
selfSay('Do you like this one?',cid)
focus[cid][1] = 6
focus[cid].wall = n
else
selfSay('Say a number from 1 to '..#WALLS,cid)
end
else
selfSay('Say a number from 1 to '..#WALLS,cid)
end
elseif focus[cid][1] == 7 then
local n = tonumber(msg:match('(%d+)') or '')
if n then
if GROUND[n] then
doSetItemOutfit(cid,GROUND[n],1000)
selfSay('Do you like this one?',cid)
focus[cid][1] = 8
focus[cid].c = n
else
selfSay('Say a number from 1 to '..#WALLS,cid)
end
else
selfSay('Say a number from 1 to '..#WALLS,cid)
end
elseif msgcontains(msg, 'change') and focus[cid][1] == 1 then
local g = getHouseByPlayerGUID(getPlayerGUID(cid))
if g and HOUSES[g] then
focus[cid].house=g
focus[cid][1] = 2
selfSay('Are you sure you want to change your house ('..getHouseName(focus[cid].house)..')?(Please remove all items from the house, before giving your answer.)',cid)
else
selfSay('You do not have a land.',cid)
end
elseif msgcontains(msg, 'yes') then
if focus[cid][1] == 2 then
doCleanHouse(focus[cid].house)
local hz = HOUSES[focus[cid].house]
local pos = {x=hz.center.x,y=hz.center.y,z=hz.center.z}
for y=-hz.sizey,hz.sizey do
for x=-hz.sizex,hz.sizex do
pos = {x=hz.center.x+x,y=hz.center.y+y,z=hz.center.z,sta ckpos = 0}
for i=0,10 do
pos.stackpos = 0
local c = getThingFromPos(pos)
if c.uid ~= 0 and not isCreature(c.uid) then
doRemoveItem(c.uid,-1)
elseif isCreature(c.uid) then
doRemoveCreature(c.uid)
end
end
pos.stackpos = 0
doCreateItem(choose(4526,4533,4527,4530),pos)
end
end
focus[cid][1] = 3
db.executeQuery('DELETE FROM `made_homes` WHERE `houseid` = '..focus[cid].house)
selfSay('Your house has been cleaned, Let\'s begin.\nSay the house ID that you want, 1-'..#TYPES..'.',cid)
elseif focus[cid][1] == 4 then
focus[cid][1] = 5
selfSay('Next, What kind of wall do you want? 1-'..#WALLS..'',cid)
elseif focus[cid][1] == 6 then
focus[cid][1] = 7
selfSay('Next, What type of floor do you want? 1-'..#GROUND..'',cid)
elseif focus[cid][1] == 8 then
focus[cid][1] = 9
selfSay('Do you want to create the house?',cid)
elseif focus[cid][1] == 9 then
selfSay('Your house was successfully created!',cid)
create(cid)
local s = [[INSERT INTO `made_homes` (
`houseid` ,
`housetype` ,
`ground` ,
`wall`
)
VALUES (
'%d', '%d', '%d', '%d'
);
]]
db.executeQuery(s:format(focus[cid].house,focus[cid].selected,focus[cid].c,focus[cid].wall))
focus[cid] = nil
end
elseif msgcontains(msg, 'no') then
if focus[cid][1] == 2 then
focus[cid][1] = 1
selfSay('Ok.',cid)
elseif focus[cid][1] == 4 then
focus[cid][1] = 3
focus[cid].selected = nil
selfSay('Say a house ID, 1-'..#TYPES,cid)
elseif focus[cid][1] == 6 then
focus[cid][1] = 5
focus[cid].wall = nil
selfSay('Say a wall ID, 1-'..#WALLS,cid)
elseif focus[cid][1] == 8 then
focus[cid][1] = 7
focus[cid].c = nil
selfSay('Say a ground ID, 1-'..#GROUND,cid)
elseif focus[cid][1] == 9 then
focus[cid] = nil
selfSay('OK then...',cid)
selfSay('Bye, ' .. creatureGetName(cid) .. '!')
end
elseif msgcontains(msg, 'bye') then
selfSay('Bye, ' .. creatureGetName(cid) .. '!')
focus[cid] = nil
end
end
end
function onThink()
for i,b in pairs(focus) do
if not isPlayer(i) then
focus[i] = nil
else
if getDistanceToCreature(i) > 4 then
selfSay('Houses.',i)
focus[i] = nil
end
end
end
end