View unanswered posts | View active topics It is currently Thu Dec 26, 2024 6:01 pm



Reply to topic  [ 13 posts ] 
 Help with LUA 
Author Message
User avatar

Joined: Thu May 12, 2011 5:35 am
Posts: 11
Reply with quote
Post Help with LUA
This is probably just a noob problem as I am very inexperienced with lua, what I'm trying to do is make an actor that gibs when it gets a certain distance to an enemy actor.
Code:
function Update(self)
   for actor in MovableMan.Actors do
      local distcheck = SceneMan:shortestDistance(self.Pos,actor.Pos,true).Magnitude
      if distcheck < 20 then
         self.ignoreteam = actor.Team
         self:GibThis()
         break
      end
   end
end

I'm just getting silent crashes when CC loads my .rte, can anyone help with this?


Thu May 12, 2011 5:43 am
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Tue May 25, 2010 8:27 pm
Posts: 4521
Location: Constant motion
Reply with quote
Post Re: Help with LUA
Lua does not cause silent crashes on startup as a general rule, but I can correct some errors for you.
Code:
function Update(self)
   for actor in MovableMan.Actors do
      local distcheck = SceneMan:shortestDistance(self.Pos,actor.Pos,true);
      if distcheck <= 20 then
         self.ignoreteam = actor.Team;
         self:GibThis()
         break
      end
   end
end


Thu May 12, 2011 4:26 pm
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: Help with LUA
Roast Veg wrote:
Lua does not cause silent crashes on startup as a general rule, but I can correct some errors for you.
Code:
function Update(self)
   if self.timer then
   if self.timer:IsPastSimMS(500) then
   self.timer:Reset();
      for actor in MovableMan.Actors do
         local distcheck = SceneMan:ShortestDistance(self.Pos,actor.Pos,true);
         if distcheck.Magnitude <= 20 and self.Team ~= actor.Team then
            self:GibThis();
            break;
         end
      end
   else
      self.timer = Timer();
   end
end


FTFY
the timer code will make the game not lag so horrendously; looping through all actors every frame is terribly inefficient.


Thu May 12, 2011 4:52 pm
Profile

Joined: Sat Feb 03, 2007 7:11 pm
Posts: 1496
Reply with quote
Post Re: Help with LUA
To fix the silent startup crashes, you'll probably want to try
grafting the Lua script onto a default actor and seeing if that works.

If it does, then your problem is in your actor's .ini code.

If it doesn't, check to make sure your "ScriptFile" leads to the proper location.


Thu May 12, 2011 6:24 pm
Profile WWW
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post Re: Help with LUA
Wasn't it ScriptPath?


Fri May 13, 2011 2:59 am
Profile
User avatar

Joined: Thu May 12, 2011 5:35 am
Posts: 11
Reply with quote
Post Re: Help with LUA
It was the code causing the crashes, the script path was fine, problem now is: it loads fine, doesnt work and the console says error 'end' expected at line 16 'eof' even though there is an end at the eof...


Fri May 13, 2011 4:23 am
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post Re: Help with LUA
That means that you have to add another end.
If that doesn't work, remove the end.


Fri May 13, 2011 4:29 am
Profile
User avatar

Joined: Thu May 12, 2011 5:35 am
Posts: 11
Reply with quote
Post Re: Help with LUA
Well the script loads without any errors now, sadly it doesn't work, any ideas? Thanks for all the help btw.


Fri May 13, 2011 4:38 am
Profile
User avatar

Joined: Sat Feb 26, 2011 10:29 am
Posts: 163
Reply with quote
Post Re: Help with LUA
Neutrality wrote:
Well the script loads without any errors now, sadly it doesn't work, any ideas? Thanks for all the help btw.


Code:
self:GibThis();

The script no more runs after its loader disappeared...right?


Fri May 13, 2011 4:55 am
Profile
User avatar

Joined: Thu May 12, 2011 5:35 am
Posts: 11
Reply with quote
Post Re: Help with LUA
I'm not sure what you mean? the script is exactly the same as the code grif posted...


Fri May 13, 2011 5:05 am
Profile
User avatar

Joined: Sat Feb 26, 2011 10:29 am
Posts: 163
Reply with quote
Post Re: Help with LUA
Is there any example of this in other mods?


Fri May 13, 2011 5:58 am
Profile
User avatar

Joined: Thu May 12, 2011 5:35 am
Posts: 11
Reply with quote
Post Re: Help with LUA
not sure, it should work just like a landmine of sorts except that its an ahuman actor


Fri May 13, 2011 6:00 am
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post Re: Help with LUA
That's wierd.

It's not showing any errors at all?
Could you post the code to check it, please.


Fri May 13, 2011 8:55 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 13 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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.419s | 13 Queries | GZIP : Off ]