• 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!

TFS 1.X+ HELP FEW SCRIPT NOT WORKING 100% AFTER MIGRATION

Diarreamental

Banned User
Joined
Jul 6, 2015
Messages
463
Solutions
1
Reaction score
85
Hello guys after migrating to tfs 1.3 few scrpits had changed its behavior and they are not working 100%

exampe brigde lever script works good, but a feature that used to work in older distributions now doesn't.
In this case if there is blood on the brigde and you pull the lever to remove the brigde it should remove the blood that was on the brigde too
(it working with corpses , items and player but not blood)

or could omebody what function i should add to make this work like i want?
Code:
local config = {
    bridgePositions = {
        {position = Position(32099, 32205, 8), groundId = 352, itemId = 352},
        {position = Position(32100, 32205, 8), groundId = 508, itemId = 508},
        {position = Position(32101, 32205, 8), groundId = 509, itemId = 509}
    },
    leverPositions = {
        Position(32098, 32204, 8),
        Position(32104, 32204, 8)
    },
    relocatePosition = Position(32102, 32205, 8),
    relocateMonsterPosition = Position(32103, 32205, 8),
    bridgeId = 1284
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local leverLeft, lever = item.itemid == 1945
    for i = 1, #config.leverPositions do
        lever = Tile(config.leverPositions[i]):getItemById(leverLeft and 1945 or 1946)
        if lever then
            lever:transform(leverLeft and 1946 or 1945)
        end
    end

    local tile, tmpItem, bridge
    if leverLeft then
        for i = 1, #config.bridgePositions do
            bridge = config.bridgePositions[i]
            tile = Tile(bridge.position)

            tmpItem = tile:getGround()
            if tmpItem then
                tmpItem:transform(config.bridgeId)
            end

            if bridge.itemId then
                tmpItem = tile:getItemById(bridge.itemId)
                if tmpItem then
                    tmpItem:remove()
                end
            end
        end
    else
        for i = 1, #config.bridgePositions do
            bridge = config.bridgePositions[i]
            tile = Tile(bridge.position)

            tile:relocateTo(config.relocatePosition, true, config.relocateMonsterPosition)
            tile:getGround():transform(bridge.groundId)
            Game.createItem(bridge.itemId, 1, bridge.position)
        end

    end
    return true
end

wall remove

if there is a player standing where the wall will appear the wall should push the player 1 sqm back
the same for dead corpses, items and if there is blood where the wall will appear it will be shown below the wall not above
Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local tile = Tile(Position({x = 32566, y = 32119, z = 7}))
    if item.itemid == 1945 then
        if tile:getItemById(1025) then
            tile:getItemById(1025):remove()
            item:transform(1946)
        else
            Game.createItem(1025, 1, {x = 32566, y = 32119, z = 7})
        end
    else
        Game.createItem(1025, 1, {x = 32566, y = 32119, z = 7})
        item:transform(1945)
    end
    return true
end


this is to remove // create 1 sqm of "roof" when lever is used
if there is an item or a player where and when the roof will be removed the player and items on it, should fall down to the floor
if there's blood, the blood should be removed
Code:
local postile = { x = 32398, y = 32239, z = 6, stackpos = 0 }
function onUse(cid, item, frompos, item2, topos)

    local tile = getThingfromPos(postile)
    local levpos = getThingPos(item.uid)
    levpos.stackpos = 253
    local topCreature = getThingfromPos(levpos)
    if topCreature.uid ~= 0 then
        doPlayerSendCancel(cid, 'Sorry, not possible.')
        return true
    end

    local topCreature2 = getThingfromPos({ x = 32398, y = 32239, z = 6, stackpos = 253 })
    if topCreature2.uid ~= 0 then
        local lastPos = getCreatureLastPosition(topCreature2.uid)
        doTeleportThing(topCreature2.uid, lastPos, true)
    end

    if item.actionid == 4024 and item.itemid == 1945 then
        doRemoveItem(tile.uid, 1)
        doCreateItem(429, 1, postile)
        doTransformItem(item.uid, item.itemid+1)
    elseif item.actionid == 4024 and item.itemid == 1946 then
        doRemoveItem(tile.uid, 1)
        doCreateItem(405, 1, postile)
        doTransformItem(item.uid, item.itemid-1)
    end

return true
end


thanks
 
Last edited:
Diff:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
+    local spot = Position(32566, 32119, 7)
+    local tile = spot:getGround()
-    local tile = Tile(Position({x = 32566, y = 32119, z = 7}))
     if item.itemid == 1945 then
         if tile:getItemById(1025) then
             tile:getItemById(1025):remove()
             item:transform(1946)
         else
+             Game.createItem(1025, 1, spot)
-             Game.createItem(1025, 1, {x = 32566, y = 32119, z = 7})
         end
     else
+         Game.createItem(1025, 1, spot)
-         Game.createItem(1025, 1, {x = 32566, y = 32119, z = 7})
         item:transform(1945)
     end
     return true
end
 
Last edited:
A minor patch you will need for 100% port as-is.

git apply patchfile
Diff:
diff --git a/src/luascript.cpp b/src/luascript.cpp
index c95a9ca1..5beff136 100644
--- a/src/luascript.cpp
+++ b/src/luascript.cpp
@@ -2217,6 +2217,7 @@ void LuaScriptInterface::registerFunctions()
        registerMethod("Creature", "setSkillLoss", LuaScriptInterface::luaCreatureSetSkillLoss);
 
        registerMethod("Creature", "getPosition", LuaScriptInterface::luaCreatureGetPosition);
+       registerMethod("Creature", "getLastPosition", LuaScriptInterface::luaCreatureGetLastPosition);
        registerMethod("Creature", "getTile", LuaScriptInterface::luaCreatureGetTile);
        registerMethod("Creature", "getDirection", LuaScriptInterface::luaCreatureGetDirection);
        registerMethod("Creature", "setDirection", LuaScriptInterface::luaCreatureSetDirection);
@@ -7196,6 +7197,18 @@ int LuaScriptInterface::luaCreatureGetPosition(lua_State* L)
        return 1;
 }
 
+int LuaScriptInterface::luaCreatureGetLastPosition(lua_State* L)
+{
+       // creature:getLastPosition()
+       const Creature* creature = getUserdata<const Creature>(L, 1);
+       if (creature) {
+               pushPosition(L, creature->getLastPosition());
+       } else {
+               lua_pushnil(L);
+       }
+       return 1;
+}
+
 int LuaScriptInterface::luaCreatureGetTile(lua_State* L)
 {
        // creature:getTile()
diff --git a/src/luascript.h b/src/luascript.h
index d3ab465b..d89a9ad7 100644
--- a/src/luascript.h
+++ b/src/luascript.h
@@ -781,6 +781,7 @@ class LuaScriptInterface
                static int luaCreatureSetSkillLoss(lua_State* L);
 
                static int luaCreatureGetPosition(lua_State* L);
+               static int luaCreatureGetLastPosition(lua_State* L);
                static int luaCreatureGetTile(lua_State* L);
                static int luaCreatureGetDirection(lua_State* L);
                static int luaCreatureSetDirection(lua_State* L);
Post automatically merged:

Diff:
-local postile = { x = 32398, y = 32239, z = 6, stackpos = 0 }
-function onUse(cid, item, frompos, item2, topos)
-
-    local tile = getThingfromPos(postile)
-    local levpos = getThingPos(item.uid)
-    levpos.stackpos = 253
-    local topCreature = getThingfromPos(levpos)
-    if topCreature.uid ~= 0 then
-        doPlayerSendCancel(cid, 'Sorry, not possible.')
-        return true
-    end
-
-    local topCreature2 = getThingfromPos({ x = 32398, y = 32239, z = 6, stackpos = 253 })
-    if topCreature2.uid ~= 0 then
-        local lastPos = getCreatureLastPosition(topCreature2.uid)
-        doTeleportThing(topCreature2.uid, lastPos, true)
-    end
-
-    if item.actionid == 4024 and item.itemid == 1945 then
-        doRemoveItem(tile.uid, 1)
-        doCreateItem(429, 1, postile)
-        doTransformItem(item.uid, item.itemid+1)
-    elseif item.actionid == 4024 and item.itemid == 1946 then
-        doRemoveItem(tile.uid, 1)
-        doCreateItem(405, 1, postile)
-        doTransformItem(item.uid, item.itemid-1)
-    end
-
-return true
-end


LUA:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local spot = Position(32398, 32239, 6)

    local leverSpot = item:getPosition()
    local activator = leverSpot:getTopCreature()

    if activator ~= nil then
        return true, player:sendCancelMessage('Sorry, not possible.')
    end

    local occupier = spot:getTopCreature()
    if occupier ~= nil then
        occupier:teleportTo(occupier:getCreatureLastPosition(), true)
    end

    local tile = spot:getGround()
    if item.actionid == 4024 and item.itemid == 1945 then
        tile:remove()
        Game.createItem(429, 1, spot)
        item:transform(item:getId() + 1)
    elseif item.actionid == 4024 and item.itemid == 1946 then
        tile:remove()
        Game.createItem(405, 1, spot)
        item:transform(item:getId() - 1)
    end
    return true
end
 
Last edited:

Similar threads

  • Question Question
Replies
1
Views
478
Back
Top