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.
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!
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
Pantera1993
Joined: Wed Jul 06, 2011 5:11 pm Posts: 226
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...
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.
Code:
--All the setup for easy parent checks function SetupParent(self) self.Parent = nil; if self.RootID ~= 255 and self.RootID ~= self.ID and MovableMan:IsActor(MovableMan:GetMOFromID(self.RootID)) then self.Parent = ToActor(MovableMan:GetMOFromID(self.RootID)); end end --All the update for easy parent checks function HasParent(self) --Various parent checks --If we have no parent or no non-self root if self.Parent == nil or self.RootID == self.ID or self.RootID == 255 then --Check if there's a parent to be had and set it if there is if self.RootID ~= 255 and self.RootID ~= self.ID and MovableMan:IsActor(MovableMan:GetMOFromID(self.RootID)) then self.Parent = ToActor(MovableMan:GetMOFromID(self.RootID)); return true; else self.Parent = nil; end --Otherwise, if we have a parent and a non-self root elseif self.Parent ~= nil and self.RootID ~= self.ID then --If the root isn't the parent but exists and is an actor, change the parent if self.RootID ~= 255 and self.RootID ~= self.ID and MovableMan:IsActor(MovableMan:GetMOFromID(self.RootID)) then self.Parent = ToActor(MovableMan:GetMOFromID(self.RootID)); --Just in case, if the parent doesn't exist, set parent as nil elseif not MovableMan:IsActor(self.Parent) or self.RootID == self.ID then self.Parent = nil; return false; end --Return true since we do have a parent return true; end return false; end
Tue Jun 13, 2017 4:30 am
Pantera1993
Joined: Wed Jul 06, 2011 5:11 pm Posts: 226
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.
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