Crashes Game But Shouldnt, Please Help
Hey, I am trying to make a gun that shoots a bomb, and when the bomb explodes everything within the blast radius gets converted to a certain team. In the code below, I put the lua I am using for the green team converter.
Code:
function Destroy(self)
for actor in MovableMan.Actors do
local diff = math.sqrt(math.pow((actor.Pos.X-self.Pos.X),2) + math.pow((actor.Pos.Y - self.Pos.Y),2))
if diff < 50 then
actor.Team = 1
end
end
end
The code works fine. It converts anything that isn't on team 1 (green team) to team 1. However, there are a few issues with this.
Problem 1: If I am on team 0, and shot one of my team 0 soldiers to convert him to team 1, he will successfully convert to team 1 and my soldiers will start shooting him. However, I can still switch back to him, and when I do he goes back to team 0. Not only this, but people on team 1 cannot control him even after he has been converted.
Problem 2: If a converted object dies while it is still converted, the game will crash. No matter what. If I shoot said object with a different gun that converts it back to team 0, though, the game will not crash.
What did I do wrong? Please help.