Teleporters very wierd sometimes.
This is the teleporter from Ballistic Weapons:Mercenaries. It still remains the same as it was in the release and you can actually play and test it.
The thing is, the teleporter can act a bit wierd sometimes. I suspect theres something broken with the code or something wrong about it. The whole code uses very wierd stuff that I have no idea of so I really need help.
About wierd stuff this can happen:
-Teleporting inside a random object
-Crashing the game, with no errors what so ever.
-Teleporting out of thin air
This is the code. Although if you have BW.rte, you can find it as a file and test it.
Its located in BW.rte/Maps/teleporter.ini
Code:
function Create(self)
if (_teleporters == nil) then
_teleporters = {self}
else
table.insert(_teleporters,self)
end
self.teledelaytimer = Timer();
self.teleactivate = nil;
self.thistele = #_teleporters;
end
function Destroy(self)
table.remove(_teleporters,self.thistele)
end
function Update(self)
if(#_teleporters > 1) then
for actor in MovableMan.Actors do
if (actor.Pos.X >= self.Pos.X - 24) and (actor.Pos.X <= self.Pos.X + 24) and (actor.Pos.Y >= self.Pos.Y - 25) and (actor.Pos.Y <= self.Pos.Y + 25) and (actor.PinStrength <= 0)then
if not self.teleactivated or self.teleactivated == 0 then
self.teleactivate = CreateAEmitter("Teleport Activation");
self.teleactivate.Lifetime = 2000;
self.teleactivate.Pos = self.Pos;
self.teleactivate:EnableEmission(true);
MovableMan:AddParticle(self.teleactivate);
self.teledelaytimer:Reset();
self.teleactivated = 1
print(self.thistele);
else
if self.teledelaytimer:IsPastSimMS(2000)then
--TELEPORTATION HAPPENS HERE
local i = #_teleporters --Failsafe.
-- The below commented code has random teleport.
--[[
i = math.random(1,#_teleporters)
while i == self.thistele
do
i = math.random(1,#_teleporters)
end
--]]
--Below code is pair teleport
--[[
if self.thistele%2 == 1 then
i = self.thistele + 1;
end
if self.thistele%2 == 0 then
i = self.thistele - 1;
end
if i > #_teleporters) --Abort teleport if unpaired
then
self.teledelaytimer:Reset();
self.teleactivate.Lifetime = 1;
self.teleactivated = 0
break
end
--]]
--Below code is sequential teleport
i = self.thistele + 1;
if (i > #_teleporters) -- Kiosk keyboards suck.
then
i = 1;
end
for oactor in MovableMan.Actors do
if (oactor.Pos.X >= _teleporters[i].Pos.X - 24) and (oactor.Pos.X <= _teleporters[i].Pos.X + 24) and (oactor.Pos.Y >= _teleporters[i].Pos.Y - 25) and (oactor.Pos.Y <= _teleporters[i].Pos.Y + 25)
then
oactor:GibThis();
_teleporters[i].teledelaytimer:Reset(); -- Needed
_teleporters[i].teleactivate.Lifetime = 1;
_teleporters[i].teleactivated = 0
end
end
actor:FlashWhite(400);
local sound = CreateAEmitter("Teleport Sound Emitter");
sound.Pos = self.Pos;
MovableMan:AddParticle(sound);
actor.Pos = _teleporters[i].Pos
self.teledelaytimer:Reset();
self.teleactivate.Lifetime = 1;
self.teleactivated = 0
end
end
end
end
if self.teledelaytimer:IsPastSimMS(2000) and self.teleactivate -- Sanity Check.
then
self.teledelaytimer:Reset();
self.teleactivate.Lifetime = 1;
self.teleactivated = 0;
end
end
end