|
Page 1 of 1
|
[ 10 posts ] |
|
Author |
Message |
MaximDude
Joined: Wed Nov 22, 2006 3:19 pm Posts: 2073
|
Setting controller modes
So, I have this little script attached to the MDC gunship and it doesn't seem to function... The script is supposed to control the turret that is attached to it. Code: if self.turret:IsPlayerControlled() == true then ActivityMan:GetActivity():SwitchToActor(self,self.myteam,self.Team); -- this part works just great, it auto switches to the ship if the turret is selected end if (self:IsPlayerControlled()) and self:GetController():IsState(26) then -- when pressing z, it should rotate to the left self.turret:GetController():SetControllerMode(Controller.MOVE_UP); -- it does not elseif (self:IsPlayerControlled()) and self:GetController():IsState(3) then -- when pressing c, it should rotate to the right self.turret:GetController():SetControllerMode(Controller.MOVE_DOWN); -- it does not else if (self:IsPlayerControlled()) and self:GetController():IsState(24) then -- when pressing x, it should fire self.turret:GetController():SetControllerMode(Controller.WEAPON_FIRE); -- again, it does not end end
No errors in the console, but since I never actually worked with controllers (Other than checking if a key is pressed), I don't know what i'm doing wrong... Maybe it is because of the AI being at work? If so how do I disable it, or maybe i'm just stupid. Whatever the reason, I need some help here. I'd probably get this done by myself if the goddamn wiki wasn't down for whatever reason it is. >:C
|
Tue Jun 29, 2010 9:41 pm |
|
|
MaximDude
Joined: Wed Nov 22, 2006 3:19 pm Posts: 2073
|
Re: Setting controller modes
Oh wow. x'D Thanks Daman.
|
Tue Jun 29, 2010 10:19 pm |
|
|
MaximDude
Joined: Wed Nov 22, 2006 3:19 pm Posts: 2073
|
Re: Setting controller modes
Yeah I guess I was wrong. I have no idea what i'm doing here... I need a working example... >_______>' Here's what I have, and in theory, it should work. Code: function Update(self) local curdist = 120; for parent in MovableMan.Actors do local avgx = parent.Pos.X - self.Pos.X; local avgy = parent.Pos.Y - self.Pos.Y; local dist = math.sqrt(avgx ^ 2 + avgy ^ 2); if dist < curdist then if parent:IsPlayerControlled() == true then self:GetController():SetState(Controller.CIM_PLAYER); if parent:GetController():IsState(26) then self:GetController():SetState(Controller.MOVE_UP); elseif parent:GetController():IsState(3) then self:GetController():SetState(Controller.MOVE_DOWN); else if parent:GetController():IsState(24) then self:GetController():SetState(Controller.WEAPON_FIRE); end end end end end end This is attached to the turret (Which is lua attached to the DS) The turret is unselectable (Auto switches to the DS if turret selected).
|
Wed Jun 30, 2010 7:38 pm |
|
|
CrazyMLC
Joined: Fri Dec 22, 2006 4:20 am Posts: 4772 Location: Good news everyone!
|
Re: Setting controller modes
You need a true in there as a second arguement. (Or false, which the effect of is self-explanitory.) You could have found your answer by yourself if you had searched for "SetState" in Lua Scripting. MaximDude wrote: Code: function Update(self) local curdist = 120; for parent in MovableMan.Actors do local avgx = parent.Pos.X - self.Pos.X; local avgy = parent.Pos.Y - self.Pos.Y; local dist = math.sqrt(avgx ^ 2 + avgy ^ 2); if dist < curdist then if parent:IsPlayerControlled() == true then self:GetController():SetState(Controller.CIM_PLAYER,true); if parent:GetController():IsState(26) then self:GetController():SetState(Controller.MOVE_UP,true); elseif parent:GetController():IsState(3) then self:GetController():SetState(Controller.MOVE_DOWN,true); else if parent:GetController():IsState(24) then self:GetController():SetState(Controller.WEAPON_FIRE,true); end end end end end end
|
Wed Jun 30, 2010 10:52 pm |
|
|
MaximDude
Joined: Wed Nov 22, 2006 3:19 pm Posts: 2073
|
Re: Setting controller modes
I guess I missed that, but regardless, it still does not work.
No errors, no effect.
|
Thu Jul 01, 2010 11:24 am |
|
|
CrazyMLC
Joined: Fri Dec 22, 2006 4:20 am Posts: 4772 Location: Good news everyone!
|
Re: Setting controller modes
Well, I could help you out. The distance check thing isn't actually the best way to find 'parent', it's actually easier and a bajillion times more accurate to check if the actor's "ID" is the same as the other object's "RootID". I'm not sure how you have this set up, but if the object the script is attached to is an attachable or something else of that nature, then scripts wont run on it. This could also break what I said above if you have it attached with Sparkle Magic. I'm not sure how IsState works, exactly, but that could be a problem. You're defining, or setting the value of local curdist in function Update(self), meaning it sets it back to that about thirty times a second or some number like that, when it's value hasn't changed. It would be faster and more efficient to put that sort of thing in function Create(self), which runs one time when the object is created. Code: function Create(self) for actor in MovableMan.Actors do if actor.ID = self.RootID then self.parent = actor end end end function Update(self) if self.parent:IsPlayerControlled() == true then self:GetController():SetState(Controller.CIM_PLAYER,true); if self.parent:GetController():IsState(26) then self:GetController():SetState(Controller.MOVE_UP,true); elseif self.parent:GetController():IsState(3) then self:GetController():SetState(Controller.MOVE_DOWN,true); elseif self.parent:GetController():IsState(24) then self:GetController():SetState(Controller.WEAPON_FIRE,true); end end end
|
Thu Jul 01, 2010 11:45 am |
|
|
MaximDude
Joined: Wed Nov 22, 2006 3:19 pm Posts: 2073
|
Re: Setting controller modes
The way it is set up is that there is an ACrab turret lua-attached to aa dropship. This script is attached to the turret, while there is another script attached to the DS. The script on the DS makes it so when the turret is selected, the control is automatically switched to the DS.
Problem is, that the AI kicks in for the turret, so I have 'self:GetController():SetState(Controller.CIM_PLAYER,true)', but that doesn't seem to disable it, it still keeps moving around and shooting things... And 'IsState' might be an issue here, because I know for sure it is used to check if a controller mode is being at use, but I don't know if you can use it to check is a certain key is pressed.
Bleh.
|
Thu Jul 01, 2010 12:49 pm |
|
|
CrazyMLC
Joined: Fri Dec 22, 2006 4:20 am Posts: 4772 Location: Good news everyone!
|
Re: Setting controller modes
There is a specific function to check if a key is pressed. It's UIInputMan or something like that, I'll have to consult the wiki. (Someone had a downloadable version posted.) Well then, this should do it (Unless the Is/SetStates don't work.): Code: function Create(self) local curdist = 120; for actor in MovableMan.Actors do local avgx = actor.Pos.X - self.Pos.X; local avgy = actor.Pos.Y - self.Pos.Y; local dist = math.sqrt(avgx ^ 2 + avgy ^ 2); if dist < curdist self.parent = actor end end end function Update(self) if self.parent:IsPlayerControlled() == true then self:GetController():SetState(Controller.CIM_PLAYER,true) self:GetController():SetState(Controller.MOVE_UP,false) self:GetController():SetState(Controller.MOVE_DOWN,false) self:GetController():SetState(Controller.WEAPON_FIRE,false) if self.parent:GetController():IsState(26) then self:GetController():SetState(Controller.MOVE_UP,true) elseif self.parent:GetController():IsState(3) then self:GetController():SetState(Controller.MOVE_DOWN,true) elseif self.parent:GetController():IsState(24) then self:GetController():SetState(Controller.WEAPON_FIRE,true) end end end MOVE_UP, etc is probably making the turret attempt to crouch and use it's jetpack.
|
Thu Jul 01, 2010 1:07 pm |
|
|
MaximDude
Joined: Wed Nov 22, 2006 3:19 pm Posts: 2073
|
Re: Setting controller modes
Got everything working. Thanks for the help MLC.
|
Fri Jul 02, 2010 12:45 pm |
|
|
CrazyMLC
Joined: Fri Dec 22, 2006 4:20 am Posts: 4772 Location: Good news everyone!
|
Re: Setting controller modes
No problem, I'm glad I was able to help.
|
Fri Jul 02, 2010 10:03 pm |
|
|
|
|
Page 1 of 1
|
[ 10 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
|
|