• 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 Portal Gun 1.0

Mock

Mock the bear (MTB)
Joined
Jul 29, 2008
Messages
619
Reaction score
106
Location
Brazil
Well, i made this in 30 mins XD
Just a silly script, a bit useful to server admins or something

For while it support 1 portal per server =s

Features:
  • Create yellow and blue portals
  • Transport creatures and items
  • Move in straight line until find an obstacle
  • Use on yourself to deactivate both portals
  • WIP choose the portal
  • WIP grab items

Video:
[video=youtube;xPM8QigQ9rg]http://www.youtube.com/watch?v=xPM8QigQ9rg[/video]
I am using crystal key and golden key with AID 0, you can choose another item.

The tags (actions.xml):
Code:
	<action itemid="2090" event="script" value="mock_portal.lua" allowfaruse="1"/>
	<action itemid="2091" event="script" value="mock_portal.lua" allowfaruse="1"/>

Code:
Lua:
--[[

Portal gun V 1.0
By: Mock the bear


Still improving...
:]

contact: [email][email protected][/email]
]]

PORTAL_CONF = {
	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 getTileInfo(pos).protection and pz then return false, true 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

Enjoy and report bugs, also do not post anywhere else without my authorization kay? :3
 
Last edited:
how to make i , that i can use it also on pz zone ?
 
i cand add it on next version.
but i see under your name
"Experienced Member "
And lua log, i think you are experienced so you can do it yoursef, i'm right? :D
 
i cand add it on next version.
but i see under your name
"Experienced Member "
And lua log, i think you are experienced so you can do it yoursef, i'm right? :D

i just pretend :p :D
so you are not right Mr. Mock :p
 
Oh, okay... at the end of the week i am going to upgrade.
But... if you cant simply add one condition in this scripts, you're are just a lua script poser with the lua logo on avatar, i'm right? =]
 
This should do it :)

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
 
can somebody please help my
i can make the teleport but if i make the second teleport the both teleports disapear and i cant make a new one

i got this error on my console

[28/07/2013 17:14:44] Lua Script Error: [Action Interface]
[28/07/2013 17:14:44] in a timer event called from:
[28/07/2013 17:14:44] data/actions/scripts/fibula/portalgun.lua:eek:nUse
[28/07/2013 17:14:45] data/actions/scripts/fibula/portalgun.lua:78: attempt to call global 'getThingFromPos' (a nil value)
[28/07/2013 17:14:45] stack traceback:
[28/07/2013 17:14:45] [C]: in function 'getThingFromPos'
[28/07/2013 17:14:45] data/actions/scripts/fibula/portalgun.lua:78: in function <data/actions/scripts/fibula/portalgun.lua:71>

i use the [9.80-9.86] The Forgotten Server v0.2.15 (Mystic Spirit) as server

i realy wanne use this script but i not a scripter and dont have an idea to fix this

thanks for your help
 
This should do it :)

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
maybe someone can remake it for 1.4tfs + ? in revscript maybe ? :O
 
Back
Top