'k, I got a little too ambitious, and decided to try and make a Lua mod for telekinesis.
Sadly, nothing happens. Not even an error ;(
Here is the first Lua code I tried to use.
Code:
function Create(self)
function lengthdir_x(dist,ang)
return dist * math.cos(-ang);
end
function lengthdir_y(dist,ang)
return dist * math.sin(-ang);
end
Holding = 0
curdist = 80;
IsHoldingSomething = 0
avgx = 0
avgy = 0
dist = 0
end
function Update(self)
if(UInputMan:KeyHeld(8)) then
Holding = 1
else
Holding = 0
end
if Holding == 1 then
for actor in MovableMan.Actors do
avgx = actor.Pos.X - self.Pos.X + lengthdir_x(96,self:GetAimAngle(true));
avgy = actor.Pos.Y - self.Pos.Y + lengthdir_y(96,self:GetAimAngle(true));
dist = math.sqrt(avgx ^ 2 + avgy ^ 2);
if self.dist ~= nil then
if dist < curdist then
curdist = dist;
actor = Held;
IsHoldingSomething = 1
else
IsHoldingSomething = 0
end
end
end
end
if IsHoldingSomething == 1 then
Held.Pos.X = self.Pos.X + lengthdir_x(96,self:GetAimAngle(true));
Held.Pos.Y = self.Pos.Y + lengthdir_y(96,self:GetAimAngle(true));
end
end
Here is the second, using piipu's finding stuff code (though, they are essentially the same).
Code:
function Create(self)
function lengthdir_x(dist,ang)
return dist * math.cos(-ang);
end
function lengthdir_y(dist,ang)
return dist * math.sin(-ang);
end
Holding = 0
curdist = 80;
IsHoldingSomething = 0
avgx = 0
avgy = 0
dist = 0
end
function Update(self)
if(UInputMan:KeyHeld(8)) then
Holding = 1
else
Holding = 0
end
if Holding == 1 then
for actor in MovableMan.Actors do
local diff = math.sqrt(math.pow((actor.Pos.X-self.Pos.X + lengthdir_x(96,self:GetAimAngle(true))),2) + math.pow((actor.Pos.Y - self.Pos.Y + lengthdir_y(96,self:GetAimAngle(true))),2))
if (diff < 80) and actor.PinStrength == 0 and IsHoldingSomething == 1 then
actor.Pos.X = self.Pos.X + lengthdir_x(96,self:GetAimAngle(true));
actor.Pos.Y = self.Pos.Y + lengthdir_y(96,self:GetAimAngle(true));
end
end
end
end
These are both meant to be applied directly to an actor.
They come with the same result, nothing happens. Not even an error.
Help Please.
(By the way, the "8" in the UIInputMan is code for "H").