If you dont know this system watch the video.
[video=youtube;b2Jo7PdYS-I]http://www.youtube.com/watch?v=b2Jo7PdYS-I[/video]
Well this system still in develop can be better and i made when i was a noob scripter so you will find too many bizzare things in this script xD!
i am pretending remake but no time for it.
The code was tested on TFS 0.3.6.
First create in server root folder an file called hconf.lua inside:
in globalevents in yout file to execute when server start add:
on startup function just add: begin()
Create a npc in open tibia style (not using handlers) and insite the file add:
now create an empty area in you map, creata a square like 5x5, create a house in this square, get the center position and house id ad change add in this table like:
[334] = {center={x=258,y=194,z=7},sizex=5,sizey=5},
The structure for sql table is:
Name: made_homes
int 11 houseid
int 11 housetype
int 11 ground
int 11 wall
Okay i know is a terrible explanation and the NPC is in portuguese, but i dont have time to fix and too many peoples are asking me for release this code. Read the code and make some changes to adapt in to your server. Really sorry to not explain to the begginers but in this days my time to dedicate to post codes are getting smaller.
[video=youtube;b2Jo7PdYS-I]http://www.youtube.com/watch?v=b2Jo7PdYS-I[/video]
Well this system still in develop can be better and i made when i was a noob scripter so you will find too many bizzare things in this script xD!
i am pretending remake but no time for it.
The code was tested on TFS 0.3.6.
First create in server root folder an file called hconf.lua inside:
Code:
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,
}
}
TIPOS = {
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
]]
in globalevents in yout file to execute when server start add:
Code:
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 criar(ida,t,c,w)
executeInArea(HOUSES[tonumber(ida)].center,TIPOS[tonumber(t)],function(pos,id)
pos.stackpos = 255
if type(id) == 'number' then
doCreateItem(WALLS[tonumber(w)][id] == 0 and GROUND[tonumber(c)] or WALLS[tonumber(w)][id] or id,pos)
elseif type(id) == 'table' then
for stack,id_ in pairs(id) do
pos.stackpos = stack
doCreateItem(WALLS[tonumber(w)][id_] == 0 and GROUND[tonumber(c)] or WALLS[tonumber(w)][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
criar(c.houseid,c.housetype,c.ground,c.wall)
print('Carregado =>'..c.houseid)
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()
Create a npc in open tibia style (not using handlers) and insite the file add:
Code:
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 Casa(id)
if not TIPOS[id] then print('sad') return false end
local cx,cy = math.floor(#TIPOS[id][1]), math.floor(#TIPOS[id])
local s = ''
for y=1,#TIPOS[id] do
for x=1,#TIPOS[id][1] do
if type(TIPOS[id][y][x]) == 'number' then
s = s..(TIPOS.s[TIPOS[id][y][x]] or ' ?')
else
s = s..(TIPOS.s[TIPOS[id][y][x][1]] or ' ?')
end
end
s = s..'\n'
end
return s,cx,cy
end
function criar(cid)
executeInArea(HOUSES[focus[cid].house].center,TIPOS[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('Quer construir sua casa? fale {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 = Casa(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('Essa casa é muito grande para seu terreno, Seu terreno é de {'..((HOUSES[focus[cid].house].sizex*2)+1)..'x'..((HOUSES[focus[cid].house].sizey*2)+1)..'} e a casa é de {'..cx..'x'..cy..'}.',cid)
else
doPlayerPopupFYI(cid,'A casa '..n..' é essa:\n'..s..'\nP = porta\n* = chao\nVocê quer mesmo essa house?')
selfSay('Quer essa mesmo?',cid)
focus[cid][1] = 4
focus[cid].selected = n
end
else
selfSay('Essa casa nao existe ou é muito grande.',cid)
end
else
selfSay('Fale um numero de 1 a '..#TIPOS,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('Quer essa mesmo?',cid)
focus[cid][1] = 6
focus[cid].wall = n
else
selfSay('Fale um numero de 1 a '..#WALLS,cid)
end
else
selfSay('Fale um numero de 1 a '..#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('Quer essa mesmo?',cid)
focus[cid][1] = 8
focus[cid].c = n
else
selfSay('Fale um numero de 1 a '..#WALLS,cid)
end
else
selfSay('Fale um numero de 1 a '..#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('Você tem certeza que quer mudar sua casa ('..getHouseName(focus[cid].house)..')? {tire TODOS os items da sua casa antes de responder}',cid)
else
selfSay('Você nao tem um terreno',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('Sua casa foi limpa! Vamos começar.\nFale o ID da casa que você quer 1-'..#TIPOS,cid)
elseif focus[cid][1] == 4 then
focus[cid][1] = 5
selfSay('Pronto, qual tipo de parede. 1-'..#WALLS..'',cid)
elseif focus[cid][1] == 6 then
focus[cid][1] = 7
selfSay('Pronto, qual tipo de chao. 1-'..#GROUND..'',cid)
elseif focus[cid][1] == 8 then
focus[cid][1] = 9
selfSay('Quer mesmo criar a casa?',cid)
elseif focus[cid][1] == 9 then
selfSay('Sua casa foi criada com sucesso!',cid)
criar(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('Fale o ID da casa que você quer 1-'..#TIPOS,cid)
elseif focus[cid][1] == 6 then
focus[cid][1] = 5
focus[cid].wall = nil
selfSay('Fale o ID da parede que você quer 1-'..#WALLS,cid)
elseif focus[cid][1] == 8 then
focus[cid][1] = 7
focus[cid].c = nil
selfSay('Fale o ID do chao que você quer 1-'..#GROUND,cid)
elseif focus[cid][1] == 9 then
focus[cid] = nil
selfSay('Ok entao.',cid)
selfSay('Tchau, ' .. creatureGetName(cid) .. '!')
end
elseif msgcontains(msg, 'bye') then
selfSay('Tchau, ' .. 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('Some daki',i)
focus[i] = nil
end
end
end
end
now create an empty area in you map, creata a square like 5x5, create a house in this square, get the center position and house id ad change add in this table like:
[334] = {center={x=258,y=194,z=7},sizex=5,sizey=5},
The structure for sql table is:
Name: made_homes
int 11 houseid
int 11 housetype
int 11 ground
int 11 wall
Okay i know is a terrible explanation and the NPC is in portuguese, but i dont have time to fix and too many peoples are asking me for release this code. Read the code and make some changes to adapt in to your server. Really sorry to not explain to the begginers but in this days my time to dedicate to post codes are getting smaller.