View unanswered posts | View active topics It is currently Mon Jul 08, 2024 4:38 pm



Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
 Only fire when sharp-aimed? 
Author Message
User avatar

Joined: Mon Sep 28, 2009 2:15 am
Posts: 720
Location: A fucking desert.
Reply with quote
Post 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.


Sat Sep 03, 2011 6:02 am
Profile
User avatar

Joined: Sat Nov 03, 2007 9:44 pm
Posts: 1916
Location: Flint Hills
Reply with quote
Post 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.


Sat Sep 03, 2011 5:45 pm
Profile
User avatar

Joined: Mon Sep 28, 2009 2:15 am
Posts: 720
Location: A fucking desert.
Reply with quote
Post 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.


Sat Sep 03, 2011 5:57 pm
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post 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.


Sat Sep 03, 2011 6:09 pm
Profile
User avatar

Joined: Mon Sep 28, 2009 2:15 am
Posts: 720
Location: A fucking desert.
Reply with quote
Post 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.


Sat Sep 03, 2011 6:27 pm
Profile
User avatar

Joined: Sat Nov 03, 2007 9:44 pm
Posts: 1916
Location: Flint Hills
Reply with quote
Post 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.


Last edited by Azukki on Sat Sep 03, 2011 6:51 pm, edited 2 times in total.



Sat Sep 03, 2011 6:46 pm
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post 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.


Sat Sep 03, 2011 6:48 pm
Profile
User avatar

Joined: Sat Nov 03, 2007 9:44 pm
Posts: 1916
Location: Flint Hills
Reply with quote
Post 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.


Sat Sep 03, 2011 6:57 pm
Profile
User avatar

Joined: Mon Sep 28, 2009 2:15 am
Posts: 720
Location: A fucking desert.
Reply with quote
Post Re: Only fire when sharp-aimed?
after adding that, i'm still getting the same problem.


Sat Sep 03, 2011 7:52 pm
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post Re: Only fire when sharp-aimed?
Did you use magnitude 3?

Because actors often have 1 velocity even standing still.


Sat Sep 03, 2011 7:58 pm
Profile
User avatar

Joined: Mon Sep 28, 2009 2:15 am
Posts: 720
Location: A fucking desert.
Reply with quote
Post Re: Only fire when sharp-aimed?
yes, I did.


Sat Sep 03, 2011 8:01 pm
Profile
User avatar

Joined: Sat Nov 03, 2007 9:44 pm
Posts: 1916
Location: Flint Hills
Reply with quote
Post 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


Sat Sep 03, 2011 11:26 pm
Profile
User avatar

Joined: Mon Sep 28, 2009 2:15 am
Posts: 720
Location: A fucking desert.
Reply with quote
Post Re: Only fire when sharp-aimed?
yes, that works well enough. Thanks, both of you.


Sun Sep 04, 2011 2:12 am
Profile
User avatar

Joined: Mon Sep 28, 2009 2:15 am
Posts: 720
Location: A fucking desert.
Reply with quote
Post 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.


Sun Sep 11, 2011 9:17 pm
Profile
User avatar

Joined: Sat Nov 03, 2007 9:44 pm
Posts: 1916
Location: Flint Hills
Reply with quote
Post 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.


Mon Sep 12, 2011 4:00 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 16 posts ]  Go to page 1, 2  Next

Who is online

Users browsing this forum: Google [Bot]


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.035s | 16 Queries | GZIP : Off ]