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



Reply to topic  [ 18 posts ]  Go to page 1, 2  Next
 2 small questions 
Author Message
User avatar

Joined: Sat Jun 19, 2010 5:02 pm
Posts: 331
Location: Mekkan
Reply with quote
Post 2 small questions
Thanks for reading! :grin:

Question 1: How can I create a timer that measures real-world time, not in-game time? I need to time music.

Question 2: If I have a reference to an actor, how can I gib specifically that actors head, if said actor owns a head? I tried:
Code:
if actor.Head ~= nil then
   actor.Head:GibThis();
end
But this failed.


Sat Aug 06, 2011 4:01 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: 2 small questions
Why would you need to measure the length of music anyway? If you need to play a tune after it you can add it to the queue.


Sat Aug 06, 2011 4:06 am
Profile
User avatar

Joined: Wed Feb 17, 2010 12:07 am
Posts: 1545
Location: That small peaceful place called Hell.
Reply with quote
Post Re: 2 small questions
1:

this for Miliseconds.
Code:
yourTimer.ElapsedRealTimeMS


and this for Seconds
Code:
yourTimer.ElapsedRealTimeS


2:

Try this instead.
Code:
--get your actor

if actor.Head:IsAttached() then
   actor.Head:GibThis()
end



Sat Aug 06, 2011 4:13 am
Profile
User avatar

Joined: Sat Jun 19, 2010 5:02 pm
Posts: 331
Location: Mekkan
Reply with quote
Post Re: 2 small questions
I need to know when to blow up something after a song ends lol...

How can I make sure it doesn't throw an error when the reference happens to be to something that never had a head? (Dropships, doors)

You'll see how this all comes together when I release a small mod soon.... :P


Sat Aug 06, 2011 12:38 pm
Profile
User avatar

Joined: Wed Feb 17, 2010 12:07 am
Posts: 1545
Location: That small peaceful place called Hell.
Reply with quote
Post Re: 2 small questions
Code:
-- Make sure you have make this check AFTER the music started
-- Get "whatever"

if not AudioMan:IsMusicPlaying() then
   whatever:GibThis()
end


Code:
for act in MovableMan.Actors do
   if -- your actor checks then
      if act.ClassName == "AHuman" then
          local actor = ToAHuman(act)
          break
      end
   end
end

if actor then
   if actor.Head:IsAttached() then
      actor.Head:GibThis()
   end
else
   actor = nil
end


Second one might be tricky though, thats the only way I know how to do it.


Sat Aug 06, 2011 12:54 pm
Profile
DRL Developer
DRL Developer

Joined: Tue Aug 11, 2009 5:09 am
Posts: 395
Reply with quote
Post Re: 2 small questions
You can check for nil first, since only AHumans have a Head pointer. Remember that in Lua nil is equivalent to a logical false so you can do it like this:
Code:
if Target.Head and Target.Head:IsAttached() then
    Target.Head:GibThis()
end


Sat Aug 06, 2011 9:15 pm
Profile
User avatar

Joined: Sat Jun 19, 2010 5:02 pm
Posts: 331
Location: Mekkan
Reply with quote
Post Re: 2 small questions
I put that snippet in... No errors. It just refused to blow up heads.
This LuaDoc tells me Head is read-only. Does that mean I can't gib it? Because that would explain.

Also... Is it possible to attach a glow to an MOSRotating?


Sun Aug 07, 2011 2:10 am
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: 2 small questions
Not with any (functional) INI method. What you want to do is create a MOPixel that has a glow, and use Lua to position the MOPixel correctly over the MOSRotating.


Sun Aug 07, 2011 4:51 am
Profile
DRL Developer
DRL Developer

Joined: Tue Aug 11, 2009 5:09 am
Posts: 395
Reply with quote
Post Re: 2 small questions
Awesomeness wrote:
I put that snippet in... No errors. It just refused to blow up heads.

Coops9753 script looks correct, but you cannot just copy it because of the comment in the if-statement. Try this:
Code:
function Update(self)
   for Act in MovableMan.Actors do
      if Act.ClassName == "AHuman" then
         Act = ToAHuman(Act)
         if Act.Head and Act.Head:IsAttached() then
            Act.Head:GibThis()
         end
      end
   end
end


Awesomeness wrote:
This LuaDoc tells me Head is read-only. Does that mean I can't gib it? Because that would explain.

It means you cannot change what the pointer is pointing to, meaning it is not possible to e.g. replace a head with a new one.


Sun Aug 07, 2011 12:30 pm
Profile
User avatar

Joined: Sat Jun 19, 2010 5:02 pm
Posts: 331
Location: Mekkan
Reply with quote
Post Re: 2 small questions
Oh... I know what you mean. I am very familiar with references and pointers in Java... Usually they're super helpful, but in some moments when you have to use clone(), they are infuriating :)

EDIT: Okay, um... It still failed to blow up heads. I did some print debugging. It only prints "Found AHuman!" over and over again.

Code:
   for actor in MovableMan.Actors do
      self.Distance = math.sqrt(math.pow(self.Pos.X - actor.Pos.X,2) + math.pow(self.Pos.Y - actor.Pos.Y,2));
      if self.Distance < 200 then
      
         if actor.ClassName == "ACrab" then
            actor:GibThis();
            print("Gibbed a crab!");
         end
      
         if actor.ClassName == "AHuman" then
            actor = ToAHuman(actor);
            if actor.Head and actor.Head:IsAttached() then
               actor.Head:GibThis();
               print("Blew up a head!");
            else
               print("Found AHuman!");
            end
         end
         
      end
   end


Sun Aug 07, 2011 2:47 pm
Profile
DRL Developer
DRL Developer

Joined: Tue Aug 11, 2009 5:09 am
Posts: 395
Reply with quote
Post Re: 2 small questions
I cannot see why it is not working, so I modified a bit and then tested it to make sure it works.
Code:
function Update(self)
   for actor in MovableMan.Actors do
      if SceneMan:ShortestDistance(self.Pos, actor.Pos, false).Magnitude < 200 then    -- just calculating the hypotenuse will cause problems around the map seam
         if actor.ClassName == "ACrab" then
            actor:GibThis()
         elseif actor.ClassName == "AHuman" then
            actor = ToAHuman(actor)
            if actor.Head and actor.Head:IsAttached() then
               actor.Head:GibThis()
            end
         end
      end
   end
end


Sun Aug 07, 2011 3:27 pm
Profile
User avatar

Joined: Sat Jun 19, 2010 5:02 pm
Posts: 331
Location: Mekkan
Reply with quote
Post Re: 2 small questions
Okay... it's still not working. This is my full code...
Code:
function Create(self)
   AudioMan:ClearMusicQueue();
   AudioMan:PlayMusic("Friday.rte/Friday.ogg", 0, -1);
   self.GibTimer = Timer();
   self.GibTimer:Reset();
   self.SupposedToBeAlive = true;
end
function Update(self)
   if self.GibTimer.ElapsedRealTimeMS > 227*1000 then
      self.SupposedToBeAlive = false;
      self:GibThis();
   end
   for actor in MovableMan.Actors do
      if SceneMan:ShortestDistance(self.Pos, actor.Pos, false).Magnitude < 200 then    -- just calculating the hypotenuse will cause problems around the map seam
         if actor.ClassName == "ACrab" then
            actor:GibThis()
         elseif actor.ClassName == "AHuman" then
            actor = ToAHuman(actor)
            if actor.Head and actor.Head:IsAttached() then
               actor.Head:GibThis()
            end
         end
      end
   end
   if self.SupposedToBeAlive == true then
      self.ToDelete = false;
      self.ToSettle = false;
   end
end
function Destroy(self)
   AudioMan:ClearMusicQueue();
   AudioMan:PlayMusic("Base.rte/Music/dBSoundworks/cc2g.ogg", -1, -1);
   print("Gone!");
   print(self.GibTimer.ElapsedRealTimeMS/1000);
end

What stupid error am I making in my code that makes it silently fail to work? :-(


Sun Aug 07, 2011 4:57 pm
Profile
User avatar

Joined: Wed Feb 17, 2010 12:07 am
Posts: 1545
Location: That small peaceful place called Hell.
Reply with quote
Post Re: 2 small questions
What is the script attached to?


Sun Aug 07, 2011 5:04 pm
Profile
DRL Developer
DRL Developer
User avatar

Joined: Wed Dec 13, 2006 5:27 am
Posts: 3138
Location: A little south and a lot west of Moscow
Reply with quote
Post Re: 2 small questions
You may want to set the third argument of SceneMan:ShortestDistance to true. Otherwise, it won't account for wrapping over the map's seam.
Actually, don't do that. See Abdul's post.


Sun Aug 07, 2011 7:06 pm
Profile WWW
User avatar

Joined: Sat Jun 19, 2010 5:02 pm
Posts: 331
Location: Mekkan
Reply with quote
Post Re: 2 small questions
The script is attached to an MOSRotating that doesn't move. And I'll change that to true. It's still not working... :-(


Sun Aug 07, 2011 7:40 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 18 posts ]  Go to page 1, 2  Next

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.107s | 13 Queries | GZIP : Off ]