How to check collisions for "teleport" command?
How to check collisions for "teleport" command?
Do you know some easy method to check collisions of entities by using teleport? teleport(position, surface)
Re: How to check collisions for "teleport" command?
This is what I did for my /slap command
or see:
viewtopic.php?f=36&t=39577#p235465
in sl_utils.lua
Code: Select all
-- till parameter is to make sure there is no infinite loop. eg When the player has no other place to reach.
function slapTill(player, till)
if player and player.valid and player.connected then
local randomXdirection = randomPosOrNeg()
local randomX = randomXdirection * math.random(10)
local randomYdirection = randomPosOrNeg()
local randomY = randomYdirection * math.random(10)
local newPosition = {x = player.position.x + randomX, y = player.position.y + randomY}
-- if a wall can be placed at the position, a player won't be stack there. Unless it's an island :)
if player.surface.can_place_entity({name="stone-wall", position=newPosition, direction=nil, force=player.force}) then
local success = player.teleport(newPosition)
if success then
slapReceived(player)
return true
else
return false
end
else
if till > 1 then
return slap(player, till-1)
else
return false
end
end
end
return false
end
viewtopic.php?f=36&t=39577#p235465
in sl_utils.lua
Re: How to check collisions for "teleport" command?
Silly question:
Why are you checking for stone-wall and teleporting player there?
You should cehck if actual player entity will fit - it has different bounding parameters then wall
(Spoilers: player is an actual entity named player)
Why are you checking for stone-wall and teleporting player there?
You should cehck if actual player entity will fit - it has different bounding parameters then wall

(Spoilers: player is an actual entity named player)
Re: How to check collisions for "teleport" command?
I'll look into itorzelek wrote:Silly question:
Why are you checking for stone-wall and teleporting player there?
You should cehck if actual player entity will fit - it has different bounding parameters then wall
(Spoilers: player is an actual entity named player)
Re: How to check collisions for "teleport" command?
There is also a way to find the closest position to something with find_non_colliding_position.darkfrei wrote:Do you know some easy method to check collisions of entities by using teleport? teleport(position, surface)
local non_colliding = player.surface.find_non_colliding_position(name="player", center=target_position, radius=10, precision=1) -- check in a 10x10 tile box around target_position, checking every 1 tile until there is a spot
if non_colliding then player.teleport(non_colliding) end