View unanswered posts | View active topics It is currently Wed Dec 25, 2024 4:54 pm



Reply to topic  [ 9 posts ] 
 Checking activity.state from an attachable 
Author Message
User avatar

Joined: Wed Jul 06, 2011 5:11 pm
Posts: 226
Reply with quote
Post 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.


Mon Jun 05, 2017 9:09 pm
Profile

Joined: Fri Sep 10, 2010 1:48 am
Posts: 666
Location: Halifax, Canada
Reply with quote
Post Re: Checking activity.state from an attachable
I believe you want ActivityMan:GetActivity().ActivityState == ActivityState.RUNNING

See here and here.


Tue Jun 06, 2017 6:29 pm
Profile
User avatar

Joined: Wed Jul 06, 2011 5:11 pm
Posts: 226
Reply with quote
Post 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


Tue Jun 06, 2017 10:55 pm
Profile

Joined: Fri Sep 10, 2010 1:48 am
Posts: 666
Location: Halifax, Canada
Reply with quote
Post Re: Checking activity.state from an attachable
Cool, good luck.


Wed Jun 07, 2017 3:32 am
Profile
User avatar

Joined: Wed Jul 06, 2011 5:11 pm
Posts: 226
Reply with quote
Post 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!


Wed Jun 07, 2017 4:57 am
Profile

Joined: Fri Sep 10, 2010 1:48 am
Posts: 666
Location: Halifax, Canada
Reply with quote
Post 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.


Wed Jun 07, 2017 5:05 pm
Profile
User avatar

Joined: Wed Jul 06, 2011 5:11 pm
Posts: 226
Reply with quote
Post 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...


Sun Jun 11, 2017 3:33 am
Profile

Joined: Fri Sep 10, 2010 1:48 am
Posts: 666
Location: Halifax, Canada
Reply with quote
Post 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.



Tue Jun 13, 2017 4:30 am
Profile
User avatar

Joined: Wed Jul 06, 2011 5:11 pm
Posts: 226
Reply with quote
Post 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.


Wed Jun 14, 2017 1:37 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 9 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.036s | 13 Queries | GZIP : Off ]