View unanswered posts | View active topics It is currently Fri Dec 27, 2024 8:08 am



Reply to topic  [ 10 posts ] 
 Land Mine script not working *Fixed 
Author Message
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Land Mine script not working *Fixed
Edit:

New Land mine script, not working. Help please.

Code:
function Create(self)
end
local curdist = 40;
for actor in MovableMan.Actors do
local avgx = actor.Pos.X - self.Pos.X;
local avgy = actor.Pos.Y - self.Pos.Y;
local dist = math.sqrt(avgx ^ 2 + avgy ^ 2);
if dist < curdist then
self:GibThis();
end
end


Last edited by CaveCricket48 on Fri Aug 14, 2009 3:50 pm, edited 1 time in total.



Thu Aug 13, 2009 10:26 pm
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: Land Mine script not working
Anything in the create function will only be executed the same update as the object is created.

Put the distance check inside function Update(self)


Fri Aug 14, 2009 12:23 am
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: Land Mine script not working
So it will look like:

Code:
function Update(self)
end
local curdist = 40;
for actor in MovableMan.Actors do
local avgx = actor.Pos.X - self.Pos.X;
local avgy = actor.Pos.Y - self.Pos.Y;
local dist = math.sqrt(avgx ^ 2 + avgy ^ 2);
if dist < curdist then
self:GibThis();
end
end


Right?


Fri Aug 14, 2009 12:43 am
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: Land Mine script not working
No. Because that code would immediately end the function loop. function create self, then for, if, then three ends at the end of the script.


Fri Aug 14, 2009 1:20 am
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: Land Mine script not working
I'm not getting any errors, but this isn't working either.

Code:
function Create(self)
local curdist = 50;
for actor in MovableMan.Actors do
local avgx = actor.Pos.X - self.Pos.X;
local avgy = actor.Pos.Y - self.Pos.Y;
local dist = math.sqrt(avgx ^ 2 + avgy ^ 2);
if dist < curdist then
self:GibThis();
end
end
end


Fri Aug 14, 2009 2:52 am
Profile
User avatar

Joined: Thu Mar 06, 2008 10:54 pm
Posts: 1360
Location: USA
Reply with quote
Post Re: Land Mine script not working
Code:
function Update(self)
local curdist = 50;
for actor in MovableMan.Actors do
local avgx = actor.Pos.X - self.Pos.X;
local avgy = actor.Pos.Y - self.Pos.Y;
local dist = math.sqrt(avgx ^ 2 + avgy ^ 2);
if dist < curdist then
self:GibThis();
end
end
end


:)


Fri Aug 14, 2009 2:54 am
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: Land Mine script not working
/facepalm

Thanks Mind.


Fri Aug 14, 2009 3:05 am
Profile
User avatar

Joined: Thu Mar 06, 2008 10:54 pm
Posts: 1360
Location: USA
Reply with quote
Post Re: Land Mine script not working
lol np


Fri Aug 14, 2009 3:07 am
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: Land Mine script not working
Another script not working. I think I need a "for" statement, but I'm not sure how I'm suppose to put it in.

Edit: got the "for" statement, but getting errors abou a nil box value.

Edit2: Found an easier way to do box and it works. Problem solved.

Small, easy box script:
Code:
function Update(self)

--Using Lua to do box detection

for actor in MovableMan.Actors do   --If an actor gets within the defined area
if (actor.Pos.X >= self.Pos.X - 20) and (actor.Pos.X <= self.Pos.X + 20) and (actor.Pos.Y >= self.Pos.Y - 20) and (actor.Pos.Y <= self.Pos.Y + 20) then
self:GibThis();   --Gib the Mine
end
end
end


Fri Aug 14, 2009 3:39 pm
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: Land Mine script not working *Fixed
Longform box detection is marginally slower than engine boxes.
This script will check every half-second for an actor (rather than every sim update) and uses engine functions for that tiny bit of not-lagginess.

function Create(self)
self.checktimer = Timer();
self.checkbox = Box(Vector(self.Pos.X - 20,self.Pos.Y - 20),Vector(self.Pos.X + 20,self.Pos.Y + 20));
end

function Update(self)
if self.checktimer:IsPastSimMS(500) == true then
self.checktimer:Reset();
for actor in MovableMan.Actors do
if self.checkbox:WithinBox(actor.Pos) == true then
self:GibThis();
end
end
end
end


Fri Aug 14, 2009 6:30 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 10 posts ] 

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.057s | 16 Queries | GZIP : Off ]