Data Realms Fan Forums
http://45.55.195.193/

2 small questions
http://45.55.195.193/viewtopic.php?f=73&t=24981
Page 1 of 2

Author:  Awesomeness [ Sat Aug 06, 2011 4:01 am ]
Post subject:  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.

Author:  Roast Veg [ Sat Aug 06, 2011 4:06 am ]
Post subject:  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.

Author:  Coops [ Sat Aug 06, 2011 4:13 am ]
Post subject:  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


Author:  Awesomeness [ Sat Aug 06, 2011 12:38 pm ]
Post subject:  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

Author:  Coops [ Sat Aug 06, 2011 12:54 pm ]
Post subject:  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.

Author:  Abdul Alhazred [ Sat Aug 06, 2011 9:15 pm ]
Post subject:  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

Author:  Awesomeness [ Sun Aug 07, 2011 2:10 am ]
Post subject:  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?

Author:  CaveCricket48 [ Sun Aug 07, 2011 4:51 am ]
Post subject:  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.

Author:  Abdul Alhazred [ Sun Aug 07, 2011 12:30 pm ]
Post subject:  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.

Author:  Awesomeness [ Sun Aug 07, 2011 2:47 pm ]
Post subject:  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

Author:  Abdul Alhazred [ Sun Aug 07, 2011 3:27 pm ]
Post subject:  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

Author:  Awesomeness [ Sun Aug 07, 2011 4:57 pm ]
Post subject:  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? :-(

Author:  Coops [ Sun Aug 07, 2011 5:04 pm ]
Post subject:  Re: 2 small questions

What is the script attached to?

Author:  TheLastBanana [ Sun Aug 07, 2011 7:06 pm ]
Post subject:  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.

Author:  Awesomeness [ Sun Aug 07, 2011 7:40 pm ]
Post subject:  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... :-(

Page 1 of 2 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/