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

Lua Convert mock portgun script to revscript

Lbtg

Intermediate OT User
Joined
Nov 22, 2008
Messages
2,312
Reaction score
135
Lua:
--[[
 
Portal gun V 1.0
By: Mock the bear
 
 
Still improving...
:]
 
contact: <a href="mailto:[email protected]">[email protected]</a>
]]
 
PORTAL_CONF = {
        blockpz = false--If you want to be able using it in protection zone
    yellow    = {2091,28,3}, --Item, portal effect, shooting effect
    blue    = {2090,30,1}, --Item, portal effect, shooting effect
    DELAY=300, --300ms
 
    --dont touch on this!
 
    portals = {},
    _T = {},
    _run = false;
}
 
function isWalkable(pos, creature, proj, pz)-- by Nord
        if getTileThingByPos({x = pos.x, y = pos.y, z = pos.z, stackpos = 0}).itemid == 0 then return false end
        if getTopCreature(pos).uid > 0 and creature then return false end
        if (PORTAL_CONF.blockpz)then
            if getTileInfo(pos).protection and pz then return false, true end
        end
        local n = not proj and 3 or 2
        for i = 0, 255 do
                pos.stackpos = i
                local tile = getTileThingByPos(pos)
                if tile.itemid ~= 0 and not isCreature(tile.uid) then
                        if hasProperty(tile.uid, n) or hasProperty(tile.uid, 7) then
                                return false
                        end
                end
        end
        return true
end
 
 
function compPos(p1,p2) --comparate positions
    if p1.x == p2.x and p2.y == p1.y then
        return true
    end
end
function getLastPathPos(p1,p2,ef) --calculate the path to the p2
    local dir,oldP;
    local n = 0;
    local p = {x=p1.x,y=p1.y,z=p1.z}
 
    while not compPos(p,p2) do
        oldp = {x=p.x,y=p.y,z=p.z}
        dir = getDirectionTo(p,p2);
        p = getPosByDir(p,dir);
        if ef then
            doSendMagicEffect(p,ef)
        end
        n = n+1
        if not isWalkable(p, true, true,true) or n >= 20 then
            return oldp
        end
 
    end
    return p
end
function gerReversePortal(i) --derp
    return i == 1 and 2 or 1
end
function controlPortals() --controll everything
    local no = 0
    for i=1,2 do
        if PORTAL_CONF.portals[i] then
            doSendMagicEffect(PORTAL_CONF.portals[i][1],PORTAL_CONF.portals[i][3])
            PORTAL_CONF.portals[i][1].stackpos = 255;
            if PORTAL_CONF.portals[gerReversePortal(i)] then
                local t = getThingFromPos(PORTAL_CONF.portals[i][1],false)
                if t.uid ~= 0 and not PORTAL_CONF._T[t.uid] then
                    local P =  PORTAL_CONF.portals[gerReversePortal(i)][1]
                    doTeleportThing(t.uid,P)
                    doSendMagicEffect(P,10)
                    PORTAL_CONF._T[t.uid] = {gerReversePortal(i),isCreature(t.uid)}
                    return addEvent(controlPortals,100)
                end
            end
            for e,b in pairs(PORTAL_CONF._T) do
                if (b and e and b[1]) then
                    if PORTAL_CONF._T[e] and PORTAL_CONF._T[e][1] == i then
                        if (not isCreature(e) and not isMovable(e) or not getThingPosition(e)) or not compPos(PORTAL_CONF.portals[i][1],getThingPosition(e)) then
                            PORTAL_CONF._T[e] = nil
                        end
                    end
                end
            end
 
        end
    end
    addEvent(controlPortals,PORTAL_CONF.DELAY)
 
end
 
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if not PORTAL_CONF._run then
        controlPortals()
        PORTAL_CONF._run = true
    end
    if item.actionid ~= 0 then
        return false --Also the key need to be used as a normal key with aid 0
    end
 
    local pos = getLastPathPos(getCreaturePosition(cid),toPosition  ,item.itemid == PORTAL_CONF.yellow[1] and PORTAL_CONF.yellow[3] or PORTAL_CONF.blue[3])
    if compPos(pos,getCreaturePosition(cid)) then
        PORTAL_CONF.portals = {}
    else
        if item.itemid == PORTAL_CONF.yellow[1] then
            doTransformItem(item.uid, PORTAL_CONF.blue[1])
            PORTAL_CONF.portals[1] = { pos,false,PORTAL_CONF.yellow[2] }
        else
            doTransformItem(item.uid, PORTAL_CONF.yellow[1])
            PORTAL_CONF.portals[2] = { pos,false,PORTAL_CONF.blue[2] }
        end
    end
    return true
end


Thats latest script from portal gun, can someone please remake it for revscripts and for 1.4+ ? It seems this script was made for 0.4(not sure)
 
Back
Top