Bom eu fiz isso rapidamente então ainda não tem tanto recurso, em breve pretendo deixar parecido com a Portal gun do portals 1
Ela é uma action, e por enquanto só é interessante ter uma por server. Aliais, é mais uma ferrament de GM, não é muito legal deixar players usarem a vontade.
Seguinte, ela funciona no item Golden Key e Blue Key, mas só vai funcionar como portal gun se os items não tiverem actionid.
Em fim cortando preliminares aqui está um video o script e as tags.
Tags:
<action itemid="2090" event="script" value="mock_portal.lua" allowfaruse="1"/>
<action itemid="2091" event="script" value="mock_portal.lua" allowfaruse="1"/>
Script:
--[[
Portal gun V 1.0
By: Mock the bear
Still improving...
:]
contact: <a href="mailto:matheus.mtb7@gmail.com">matheus.mtb7@gmail.com</a>
]]
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