• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Action Extremely simple house building script [TFS 1.2]

Lakkir

Active Member
Joined
Jan 6, 2009
Messages
29
Reaction score
25
Location
Chile
Actually I dont know much about TFS 1.1 so I dont know if it's compatible, if anyone knows, please put it in comment.
Feel free to improve it if you have an idea.
I test a similar scripts, and it works but i made some changes and I dont test that. If it works or it does not work, please tell me in comments. Thanks!

OBnFKvw.gif


It basically allows you tu build walls in grass or in wooden floor with item id 405 depending the direction you use it.
To build you have to use the wooden hammer, id= 2556
To destroy walls you have to use the snake destroyer, id=4846

Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if itemid == 405 or isGrass(target) then
        local click = target:getPosition()
        local playerpos = player:getPosition()
        horizontal0 = {5261, 5266, 5268, 5274, 5275}
        vertical0 = {5262, 5264, 5270, 5272, 5273}
        local items ={
        {5263, vertical0[math.random(1,5)], vertical0[math.random(1,5)]},
        {horizontal0[math.random(1,5)],0,horizontal0[math.random(1,5)]},
        {horizontal0[math.random(1,5)], vertical0[math.random(1,5)], 5265},
        }
        local i = click.x-playerpos.x+2
        local j = click.y-playerpos.y+2
        doCreateItem(items[j][i], 1, click)
        click:sendMagicEffect(73)
    end
end

function isGrass(item)
    if item:getName() == "grass" then
        return true
    end
    return false
end

The next script you should use it with care, cause you can destroy another type of wall with the name "wooden wall", you can change the name of the walls that the script creates and change the condition (I do that in my server) or you can change the name of the other wooden wall. Or just change the script to search all the item id of the walls, I dont like this cause it's less efficient.

Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local targetpos = target:getPosition()
    if isWoodenWall(target) then
        target:remove()
        targetpos:sendMagicEffect(3)
        return true
    end
end

function isWoodenWall(item)
    local id = item.itemid
    if item:getName() == "wooden wall" then
        return true
    end
    for j=5278,5283 do
        if id == j then
            return true
        end
    end
    return false
end

Code:
<action itemid="2556" script="simplebuild.lua" />
<action itemid="4846" script="removewall.lua" />
 
Last edited:
Tried it out in 1.1 and it works but i get some consoles error from time to time.. would be awesome if you could add some things to the script tho
* Resources - to build 1 wall the player must have 5 wood ( id: 5601 ) in his bag.
* build floor - like another tool for floor building

im not a great scripter myself but i will maybe try to add something to the script myself when i have time and motivation for it :)
its just examples if anyone want to improve the script :)
 
Hey guys, I've made some changes. like a player can only build inside this house, and also other players can't destroy random woodwalls in the map that arent supposed to.

Also made it require wood and also give back the wood when deconstructed.
Adapted for TFS 1.2 because of some missing functions.

I'm not a coder but anyways...

Code:
local grassIds = {106, 405, 11114, 10737, 10738, 10739, 10740, 9043, 9044, 9045, 9046, 9047, 9048, 9049, 9050, 9051, 9052, 9053, 9054, 9055, 9056, 9057, 9058, 8591, 8578, 8591, 8166, 8167, 8140, 8141, 8142, 8143, 8144, 8145, 8146, 8147, 8148, 8149, 8150, 8151, 8152, 8153, 8154, 8155, 8156, 8157, 8158, 8159, 7709, 7710, 7656, 7657, 7658, 7659, 7660, 7661, 7662, 7663, 7664, 7653, 6216, 6217, 6216, 6217, 6218, 6219, 4784, 4785, 4786, 4787, 4788, 4789, 4790, 4791, 4792, 4793, 4794, 4795, 4526, 4527, 4528, 4529, 4530, 4531, 4532, 4533, 4534, 4536, 4537, 4538, 4539, 4540, 4541, 4542, 4543, 4544, 4545, 4546, 4547, 4548, 4549, 4550, 4551, 4552, 4553, 3985, 3984, 3298, 3299, 3300, 3301, 3302, 3303, 3304, 3305, 3306, 3307, 3308, 3309, 3263, 791, 293}
local useWood = true

-- 12969 dry piece of wood id --
-- Credits to Lakkir for creating and Sezo for adaptations --

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local targetId = target.itemid
    local house = Tile(player:getPosition()):getHouse()
   
    if not isInArray(grassIds, target.itemid) then
        return false
        end
   
        if not house then
        return false
        end
       
        -- implement only house owner can build --
       
        if useWood and not player:removeItem("dry piece of wood", 1) then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "You don't have the necessary materials to build.")
        return true
        end
       
        local click = target:getPosition()
        local playerpos = player:getPosition()
        horizontal0 = {5261, 5266, 5268, 5274, 5275}
        vertical0 = {5262, 5264, 5270, 5272, 5273}
        local items ={
        {5263, vertical0[math.random(1,5)], vertical0[math.random(1,5)]},
        {horizontal0[math.random(1,5)],0,horizontal0[math.random(1,5)]},
        {horizontal0[math.random(1,5)], vertical0[math.random(1,5)], 5265},
        }
        local i = click.x-playerpos.x+2
        local j = click.y-playerpos.y+2
        doCreateItem(items[j][i], 1, click)
        click:sendMagicEffect(73)
       
    end

and now for the wall remover:

Code:
local wwallIds = {5261, 5266, 5268, 5274, 5275, 5262, 5264, 5270, 5272, 5273, 5265, 5278, 5280, 5283, 5282} -- the last four are doors


function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local targetId = target.itemid
    local house = Tile(player:getPosition()):getHouse()
   
    if not isInArray(wwallIds, target.itemid) then
        return false
        end
       
    if not house then
        return false
        end

   
        target:remove()
        toPosition:sendMagicEffect(3)
        player:addItem(12969, 1)
        return true
    end

-- Credits to Lakkir for creating and Sezo for adaptations --
 
Maybe we could expand this further?
1: Only buildable on land that you own.
2: Floor, roof, window and door?
 
Hey guys, I've made some changes. like a player can only build inside this house, and also other players can't destroy random woodwalls in the map that arent supposed to.

Also made it require wood and also give back the wood when deconstructed.
Adapted for TFS 1.2 because of some missing functions.

I'm not a coder but anyways...

Code:
local grassIds = {106, 405, 11114, 10737, 10738, 10739, 10740, 9043, 9044, 9045, 9046, 9047, 9048, 9049, 9050, 9051, 9052, 9053, 9054, 9055, 9056, 9057, 9058, 8591, 8578, 8591, 8166, 8167, 8140, 8141, 8142, 8143, 8144, 8145, 8146, 8147, 8148, 8149, 8150, 8151, 8152, 8153, 8154, 8155, 8156, 8157, 8158, 8159, 7709, 7710, 7656, 7657, 7658, 7659, 7660, 7661, 7662, 7663, 7664, 7653, 6216, 6217, 6216, 6217, 6218, 6219, 4784, 4785, 4786, 4787, 4788, 4789, 4790, 4791, 4792, 4793, 4794, 4795, 4526, 4527, 4528, 4529, 4530, 4531, 4532, 4533, 4534, 4536, 4537, 4538, 4539, 4540, 4541, 4542, 4543, 4544, 4545, 4546, 4547, 4548, 4549, 4550, 4551, 4552, 4553, 3985, 3984, 3298, 3299, 3300, 3301, 3302, 3303, 3304, 3305, 3306, 3307, 3308, 3309, 3263, 791, 293}
local useWood = true

-- 12969 dry piece of wood id --
-- Credits to Lakkir for creating and Sezo for adaptations --

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local targetId = target.itemid
    local house = Tile(player:getPosition()):getHouse()
  
    if not isInArray(grassIds, target.itemid) then
        return false
        end
  
        if not house then
        return false
        end
      
        -- implement only house owner can build --
      
        if useWood and not player:removeItem("dry piece of wood", 1) then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "You don't have the necessary materials to build.")
        return true
        end
      
        local click = target:getPosition()
        local playerpos = player:getPosition()
        horizontal0 = {5261, 5266, 5268, 5274, 5275}
        vertical0 = {5262, 5264, 5270, 5272, 5273}
        local items ={
        {5263, vertical0[math.random(1,5)], vertical0[math.random(1,5)]},
        {horizontal0[math.random(1,5)],0,horizontal0[math.random(1,5)]},
        {horizontal0[math.random(1,5)], vertical0[math.random(1,5)], 5265},
        }
        local i = click.x-playerpos.x+2
        local j = click.y-playerpos.y+2
        doCreateItem(items[j][i], 1, click)
        click:sendMagicEffect(73)
      
    end

and now for the wall remover:

Code:
local wwallIds = {5261, 5266, 5268, 5274, 5275, 5262, 5264, 5270, 5272, 5273, 5265, 5278, 5280, 5283, 5282} -- the last four are doors


function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local targetId = target.itemid
    local house = Tile(player:getPosition()):getHouse()
  
    if not isInArray(wwallIds, target.itemid) then
        return false
        end
      
    if not house then
        return false
        end

  
        target:remove()
        toPosition:sendMagicEffect(3)
        player:addItem(12969, 1)
        return true
    end

-- Credits to Lakkir for creating and Sezo for adaptations --

It works, but after restart the server, walls dissapear. Any other items in house stay on their place. anyone know why walls dissapear?
 
There are 3 ways to solve it
1) add buyable plots of land on the website, (you can create entry door somewhere else on the map so server side entryPos works fine, and loads as valid house)
you can put command !putdoor (to put door itemid if in house)
edit tile.cpp and add exception to house.cpp to save walls/doors as well etc by item ranges.

2) better - add custom zone that is being saved as house, maybe house2 (you can use same code as house.cpp offers, but poses issue with multiple floors, unless you can use place wall/ground itemid with zone type defined.

3) save whole map.
 
Maybe we could expand this further?
1: Only buildable on land that you own.
2: Floor, roof, window and door?

just create an invisible item without sprite on the second floor with a step function to create the floor visible on the spot with a check if you have enough material to create the floor, already the ends invisible items with action on use to create the walls, already the top floor would have to be an open one it would be a good setup to create a garden
 
Back
Top