Data Realms Fan Forums
http://45.55.195.193/

Only fire when sharp-aimed?
http://45.55.195.193/viewtopic.php?f=75&t=25405
Page 1 of 2

Author:  Urch [ Sat Sep 03, 2011 6:02 am ]
Post subject:  Only fire when sharp-aimed?

Is it possible to make a gun that can only fire while sharpaimed? If so, can someone pm for a little more information? thanks.

Author:  Azukki [ Sat Sep 03, 2011 5:45 pm ]
Post subject:  Re: Only fire when sharp-aimed?

That's a very basic thing to do, now that we have attachable scripting.
Code:
function Update(self)
--check to see if the root object of the gun is an actor. If so, it can be concluded that the root object actor is the operator of the device, holding it.
   self.rootofdevice = MovableMan:GetMOFromID(self.RootID)
   if self.rootofdevice:IsActor() then
      self.operator = ToActor(self.rootofdevice)
--if the operator's controller is not in a state of sharp aiming, force his controller's weapon firing state to false
      if self.operator:GetController():IsState(Controller.AIM_SHARP) == false then
         self.operator:GetController():SetState(Controller.WEAPON_FIRE,false)
      end
   end
end

Here you go. But also, when you utilize a basic script that you didn't make, try to read through it and understand it for yourself, so you can make your own basic scripts at some point, and then perhaps less basic ones. Give a man a fish, teach a man to fish, etc etc.

Author:  Urch [ Sat Sep 03, 2011 5:57 pm ]
Post subject:  Re: Only fire when sharp-aimed?

The script doesn't seem to work consistently; sometimes it does, other times it doesn't. usually the gun can be fired while moving, but not while standing still and not sharp-aiming.

Edit: To clarify,

if the actor is sharp-aiming while standing still then they can fire.
if the actor is not sharp-aiming while standing still then they cannot fire.
if the actor is moving and not sharp-aiming, then they can fire. sometimes.

Author:  Asklar [ Sat Sep 03, 2011 6:09 pm ]
Post subject:  Re: Only fire when sharp-aimed?

I'd change a bit the code, to force everything stop working.

Code:
function Update(self)
if self.parent == nil then   
   self.parent = MovableMan:GetMOFromID(self.RootID)
end

if self.parent:GetController():IsState(Controller.AIM_SHARP) == false then
    self:Deactivate()
    self.parent:GetController():SetState(Controller.WEAPON_FIRE,false)
end
end


Long ago I made a mod which had a burst firing weapon and I wanted to make the actor stop firing, and to do it I had to deactivate the gun and the actor.

Author:  Urch [ Sat Sep 03, 2011 6:27 pm ]
Post subject:  Re: Only fire when sharp-aimed?



This is the code i have so far. btw, asklar, when i put your code in instead of azzuki's it would not produce any particles under any circumstances.

Author:  Azukki [ Sat Sep 03, 2011 6:46 pm ]
Post subject:  Re: Only fire when sharp-aimed?

I think the inconsistency is simply due to the inconsistency of the sharpaim state.
When I add in Asklar's self deactivate bit to my script along with teaching the actor some trigger discipline, it's still the same, it occasionally considers sharp aim to be the case when walking, and almost always does when jet-packing.

And if I'm not mistaken, Asklar's script would be reading the sharpaim state of the first root it ever had, so it wouldn't work properly if it ever weren't in the current user's inventory, and would crash when that actor gibbed or settled to terrain? And that's if it were working for any actor, which it seems not to be, the console's full of errors related to the GetController on line 6, probably because for the first frame or so, the root of the gun isn't the actor with it equipped, but rather, itself, so it keeps trying to access the controller of the gun itself, which does not exist.

Author:  Asklar [ Sat Sep 03, 2011 6:48 pm ]
Post subject:  Re: Only fire when sharp-aimed?

Well, you could change Azukki's code and add some ors with the body moving.
Like, with these:

3 = MOVE_RIGHT
4 = MOVE_LEFT
5 = MOVE_UP
6 = MOVE_DOWN
7 = MOVE_FAST
8 = BODY_JUMPSTART
9 = BODY_JUMP

But I think there must be another way though.

EDIT:
Crap, Ninja'd

And my bit of code for the parent does work, but I think I ripped it uncompletely from one of my mods.

Author:  Azukki [ Sat Sep 03, 2011 6:57 pm ]
Post subject:  Re: Only fire when sharp-aimed?

You could just check the actor's speed.

if self.operator:GetController():IsState(Controller.AIM_SHARP) == false or self.operator.Vel.Magnitude > 1 then

Hah! Due to some actors' jittery idle animations, with this script, semi autos become inconsistent full autos, because the script releases the trigger for you!
Change 1 to 3 if you don't want that.

Author:  Urch [ Sat Sep 03, 2011 7:52 pm ]
Post subject:  Re: Only fire when sharp-aimed?

after adding that, i'm still getting the same problem.

Author:  Asklar [ Sat Sep 03, 2011 7:58 pm ]
Post subject:  Re: Only fire when sharp-aimed?

Did you use magnitude 3?

Because actors often have 1 velocity even standing still.

Author:  Urch [ Sat Sep 03, 2011 8:01 pm ]
Post subject:  Re: Only fire when sharp-aimed?

yes, I did.

Author:  Azukki [ Sat Sep 03, 2011 11:26 pm ]
Post subject:  Re: Only fire when sharp-aimed?

Three may have been too high, and allowed walking.

How about this?
Code:
function Update(self)
--check to see if the root object of the gun is an actor. If so, it can be concluded that the root object actor is the operator of the device, holding it.
   self.rootofdevice = MovableMan:GetMOFromID(self.RootID)
   if self.rootofdevice:IsActor() then
      self.operator = ToActor(self.rootofdevice)
--if the operator's controller is not in a state of sharp aiming, force his controller's weapon firing state to false
      if self.operator:GetController():IsState(Controller.AIM_SHARP) == false or self.operator.Vel.Magnitude > 2 or self.operator:GetController():IsState(Controller.JUMP) == true or self.operator:GetController():IsState(Controller.MOVE_RIGHT) == true or self.operator:GetController():IsState(Controller.MOVE_LEFT) == true then
         self.operator:GetController():SetState(Controller.WEAPON_FIRE,false)
         self:Deactivate()
      end
   end
end

Author:  Urch [ Sun Sep 04, 2011 2:12 am ]
Post subject:  Re: Only fire when sharp-aimed?

yes, that works well enough. Thanks, both of you.

Author:  Urch [ Sun Sep 11, 2011 9:17 pm ]
Post subject:  Re: Only fire when sharp-aimed?

I have now discovered that the AI seems to be incapable of firing this gun, despite the fact that the AI sharpaims and doesn't move.

Author:  Azukki [ Mon Sep 12, 2011 4:00 am ]
Post subject:  Re: Only fire when sharp-aimed?

Dang.
Okay, so AI's sharp state presumably can't be read, but if an ai is firing and not moving, it's a pretty sure bet that he's sharp aiming, so how about we try taking off the sharp check when the operator is ai, just leaving the movement checks?

Code:
function Update(self)
--check to see if the root object of the gun is an actor. If so, it can be concluded that the root object actor is the operator of the device, holding it.
   self.rootofdevice = MovableMan:GetMOFromID(self.RootID)
   if self.rootofdevice:IsActor() then
      self.operator = ToActor(self.rootofdevice)
      if self.operator:IsPlayerControlled() == true then
         if self.operator:GetController():IsState(Controller.AIM_SHARP) == false or self.operator.Vel.Magnitude > 2 or self.operator:GetController():IsState(Controller.JUMP) == true or self.operator:GetController():IsState(Controller.MOVE_RIGHT) == true or self.operator:GetController():IsState(Controller.MOVE_LEFT) == true then
            self.operator:GetController():SetState(Controller.WEAPON_FIRE,false)
            self:Deactivate()
         end
      else
        if self.operator.Vel.Magnitude > 2 or self.operator:GetController():IsState(Controller.JUMP) == true or self.operator:GetController():IsState(Controller.MOVE_RIGHT) == true or self.operator:GetController():IsState(Controller.MOVE_LEFT) == true then
          self.operator:GetController():SetState(Controller.WEAPON_FIRE,false)
          self:Deactivate()
      end
      end
   end
end


I haven't tried this, but I imagine it should be vaguely close to functional.

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