playersExist = {} playersBlinking = {} --The following variables can be changed to fit your level. --these are the distance a ship moves on blink, and the level boundaries. blinkDistance = 255/5 top = -1530 bottom = 1530 left = -1275 right = 1275 --This function takes a ship, and moves it back into the stage bounds if it is outside. function checkBounds(ship) local shipLoc = ship:getLoc() if(shipLoc.x > right) then ship:setLoc(point.new(right, shipLoc.y)) elseif(shipLoc.x < left) then ship:setLoc(point.new(left, shipLoc.y)) end if(shipLoc.y > bottom) then ship:setLoc(point.new(shipLoc.x, bottom)) elseif(shipLoc.y < top) then ship:setLoc(point.new(shipLoc.x, top)) end end --This function is what moves a ship for blinking function blink(ship) shipLoc = ship:getLoc() local angle = ship:getAngle() logprint(angle) local newX = blinkDistance*math.cos(angle) local newY = blinkDistance*math.sin(angle) ship:setLoc(point.new(shipLoc.x + newX, shipLoc.y + newY)) end --this function looks at all registered players, then checks if they are blinking function checkBlinking() for index, object in pairs(players) do --Get the ship and player name local ship = object:getShip() local playerName = object:getName() --Did they start cloaking? make them blink --If they were already cloaked, do nothing. --otherwise if they aren't cloaked, get them ready to blink if(ship:isModActive(Module.Cloak) == true and playersBlinking[playerName] ~= true) then logprint("blink = true") playersBlinking[playerName] = true blink(ship) checkBounds(ship) elseif(ship:isModActive(Module.Cloak) ~= true) then playersBlinking[playerName] = false; end --Now we make sure that the player hasn't blinked out of the stage boundaries --Comment out this next line if you don't want to force boundaries to the level checkBounds(ship) end end --A bit of code I borrowed from Raptor. This removes an entry from a table. --function searchAndRemoveFromTable(someTable, valueObject) --local localIndexToRemove = -1 --for i, v in ipairs(someTable) --do --if(v == valueObject) then --localIndexToRemove = i --break --end --end -- --if localIndexToRemove ~= -1 then --table.remove(someTable, localIndexToRemove) --end --end --Another function from Raptor. This adds to a table. --function insertIntoTableIfUnique(someTable, valueObject) --local foundObject = false --for i, v in ipairs(someTable) --do --if(v == valueObject) then --foundObject = true --break --end --end -- --if foundObject == false then --table.insert(someTable, valueObject) --end --end --when a player spawns, register them so they can blink --function onShipSpawned(ship) -- local player = ship:getPlayerInfo() -- local name = player:getName() -- insertIntoTableIfUnique(playersExist, ship:getPlayerInfo()) -- playersBlinking[name] = false --end --when a player dies, un-register the ship so that we don't fill our tables with unrelavent data --function onShipKilled(ship) -- local player = ship:getPlayerInfo() -- local name = player:getName() -- searchAndRemoveFromTable(playersExist, ship:getPlayerInfo()) --remove from playersExist -- playersBlinking[name] = nil --remove from playersBlinking --end function onTick() game = GameInfo() players = game:getPlayers() --logprint(tablelength(players)) checkBlinking() end function main() subscribe(Event.Tick) subscribe(Event.ShipSpawned) subscribe(Event.ShipKilled) --in main() do: game = GameInfo() --then anywhere you want is: game:getPlayers() end