Data Realms Fan Forums
http://forums.datarealms.com/

Checking activity.state from an attachable
http://forums.datarealms.com/viewtopic.php?f=73&t=46177
Page 1 of 1

Author:  Pantera1993 [ Mon Jun 05, 2017 9:09 pm ]
Post subject:  Checking activity.state from an attachable

So I'm trying to find a way to check the activitystate of the game to prevent scripts on attachables from running during the editing state. The specific issue I'm having is that during the building phase of the Metagame, scripts attached to attachables will continuously try to find the Parent, causing tons of lag when there are many actors on screen. Also, this seems to cause attachables to pick the wrong actor as a parent, often giving abilities to actors that shouldn't have them.

I was thinking something like this, which works to stop the code from running in editing state, eliminating lag, but also stops it from running in any other state.

Code:
   if ActivityMan:ActivityRunning() == 1 then 


I've tried a few other variations that didn't work, but my experience writing code for attachables is limited.

Author:  Bad Boy [ Tue Jun 06, 2017 6:29 pm ]
Post subject:  Re: Checking activity.state from an attachable

I believe you want ActivityMan:GetActivity().ActivityState == ActivityState.RUNNING

See here and here.

Author:  Pantera1993 [ Tue Jun 06, 2017 10:55 pm ]
Post subject:  Re: Checking activity.state from an attachable

Thanks I'll give this a try once I figure out the current error I'm having (can't load the mod) :P

Author:  Bad Boy [ Wed Jun 07, 2017 3:32 am ]
Post subject:  Re: Checking activity.state from an attachable

Cool, good luck.

Author:  Pantera1993 [ Wed Jun 07, 2017 4:57 am ]
Post subject:  Re: Checking activity.state from an attachable

Seems to work so far, but I had to check for the integer (4) instead of ActivityState.RUNNING. Will test further to see how well this will work with large amounts of actors in the scene, thanks again Bad Boy!

Author:  Bad Boy [ Wed Jun 07, 2017 5:05 pm ]
Post subject:  Re: Checking activity.state from an attachable

Hmm, ActivityState.RUNNING should just give you the int 4 since it's an enum, but maybe I typoed somewhere. Take a look at the wiki I guess, if you want to put in the enum instead.
Either way, glad it works and hope it holds up well, that's a pain in the ass issue to have to deal with - I wouldn't even have thought of it.

Author:  Pantera1993 [ Sun Jun 11, 2017 3:33 am ]
Post subject:  Re: Checking activity.state from an attachable

So the script seems to be working fine in most modes but I'm still getting errors in the Metagame with multiple actors being assigned as the parent of one actor's attachable or multiple instances of a single script running on one actor. The scripts still seems to be running during the base building phase. I think it might have something to do with how the game is spawning actors. I'm using this to assign a parent:

Code:
   local actor = MovableMan:GetMOFromID(self.RootID);

   if MovableMan:IsActor(actor) then
      self.Parent = ToActor(actor);
      self.Parentpickingdone = true;
   end


I also have the same script running in the update as a safety check:

Code:
      if self.ParentPickTimer:IsPastSimMS(500) then         
         local actor = MovableMan:GetMOFromID(self.RootID);
         if MovableMan:IsActor(actor) then
            self.Parent = ToActor(actor);         
            self.Parentpickingdone = true;            
         end
      end      
      --Set the parent to nil if he's dead
      if not MovableMan:IsActor(self.Parent) then
         self.Parent = nil;
      end   

Not sure if this method is still the standard way it's done these days, most of the scripts I use are pieced together with old info from these forums.

Would I have better luck attaching the scripts directly to the AHuman? I imagine I could just reference self instead of letting the game fumble around with parent picking...

Author:  Bad Boy [ Tue Jun 13, 2017 4:30 am ]
Post subject:  Re: Checking activity.state from an attachable

Hmm, weird. There are a few classes related to the metagame but I don't think any of them will help you with this. It could be an issue with your parent checking code, though a quick glance doesn't suggest anything wrong with it.

For what it's worth, here are my parent checks - the first one should be run in Create and the 2nd in Update. The 2nd will return true if there's still a valid parent and false otherwise, so you can use its return to tell you if you should do stuff. I had it running every Update with no lag, but that was with something which wasn't in the scene in too large numbers so you may still want some delay on it if you use it.


Author:  Pantera1993 [ Wed Jun 14, 2017 1:37 am ]
Post subject:  Re: Checking activity.state from an attachable

Thanks, I think having it check if the Root ID is 255 will help here. I'll give this a try as soon as I get a chance to implement.

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