View unanswered posts | View active topics It is currently Sat Aug 15, 2020 9:54 am

 Page 1 of 1 [ 4 posts ]
 Print view Previous topic | Next topic
In need of a simple script
Author Message

Joined: Mon Oct 11, 2010 1:15 pm
Posts: 594
Location: Finlandia
In need of a simple script
I'm learning the ropes on lua, but I'm putting this here since I have zero experience with rays.

I'm looking for a simple script that scans for actors within a certain distance from an object (self), without any obstructing terrain. I'm guessing this has something to do with MORays and ObstacleRays?

Mon Jul 09, 2012 9:16 pm
Data Realms Elite

Joined: Tue May 25, 2010 8:27 pm
Posts: 4521
Location: Constant motion
Re: In need of a simple script
Really a ray isn't going to do you any good here, since it can cause lag in large quantities and only looks on one direction. What you want is this short snippet here:

Code:
function Create(self)
self.minDistance = 10 --distance in pixels from the centre of the actor
end

function Update(self)
for actor MovableMan.Actors do
local actorDist = sqrt(actor.Pos.X^2+actor.Pos.Y^2)
if actorDist <= self.minDistance then
actor:GibThis() --Alter this to do whatever it is that you want.
end
end

There are simplifications of the seventh line there, but since I don't remember the functions this will suffice.

Mon Jul 09, 2012 9:32 pm

Joined: Mon Oct 11, 2010 1:15 pm
Posts: 594
Location: Finlandia
Re: In need of a simple script
I'm able of doing that myself, I just wanted for the object to not affect actors if they're obstructed by terrain.

Mon Jul 09, 2012 9:35 pm
Data Realms Elite

Joined: Tue May 25, 2010 8:27 pm
Posts: 4521
Location: Constant motion
Re: In need of a simple script
Ah ok, try:
Code:
function Create(self)
self.minDistance = 10 --distance in pixels from the centre of the actor
end

function Update(self)
for actor MovableMan.Actors do
local actorDist = sqrt(actor.Pos.X^2+actor.Pos.Y^2)
if actorDist <= self.minDistance then
if SceneMan:CastFindMORay(self.Pos, actor.Pos, actor.RootID, Vector(), 0, false, 1) == true then
actor:GibThis()
end
end
end

That new line is all sorts of untested, so it might well not work without tweaking.

EDIT: Just corrected this, try again if it wasn't working before.

Mon Jul 09, 2012 9:47 pm
Display posts from previous:  Sort by
 Page 1 of 1 [ 4 posts ]

#### Who is online

Users browsing this forum: No registered users

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

Search for:
 Jump to:  Select a forum ------------------ Cortex Command    Dev Log    Wiki    Game Discussion    Game and Licensing Support    Mod Making       Lua Scripting       Requests    Mod Releases       Older Mods    Scene Releases       Scene Making Planetoid Pioneers    Game Discussion    Pioneer Program Lounge Data Realms Off-Topic    Off Topic Chat       Gaming       Forum Games    Site Support & Feedback