Joined: Mon Sep 28, 2009 2:15 am Posts: 720 Location: A fucking desert.
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
Azukki
Joined: Sat Nov 03, 2007 9:44 pm Posts: 1916 Location: Flint Hills
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
Urch
Joined: Mon Sep 28, 2009 2:15 am Posts: 720 Location: A fucking desert.
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
Asklar
Data Realms Elite
Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
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
Urch
Joined: Mon Sep 28, 2009 2:15 am Posts: 720 Location: A fucking desert.
Re: Only fire when sharp-aimed?
Code:
function Create(self) if self.Magazine then self.ammo = self.Magazine.RoundCount else self.ammo = 0 end end
function Update(self) 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
if self.Magazine then if self.ammo > self.Magazine.RoundCount then -- bullets are missing from the magazine so the gun must have been fired
local Parent = MovableMan:GetMOFromID(self.RootID) local BulletVel = self.Vel + self:RotateOffset(Vector(150,RangeRand(-3,3)))
-- bullets local Effect = CreateMOPixel("SlagRifle MOPixel Metal Bullet", "PSI.rte") if Effect then Effect.Vel = BulletVel Effect.Pos = self.MuzzlePos Effect:SetWhichMOToNotHit(Parent, 0.1) MovableMan:AddParticle(Effect) end
for i = 1, 2 do Effect = CreateMOPixel("SlagRifle MOPixel Smoke Bullet", "PSI.rte") if Effect then Effect.Vel = BulletVel Effect.Pos = self.MuzzlePos Effect:SetWhichMOToNotHit(Parent, 0.1) MovableMan:AddParticle(Effect) end end
-- forward for i = 1, 4 do Effect = CreateMOSParticle("Side Thruster Blast Ball 1", "Base.rte") if Effect then Effect.Vel = self.Vel + self:RotateOffset(Vector(RangeRand(6,9),RangeRand(-3,3))) Effect.Pos = self.MuzzlePos MovableMan:AddParticle(Effect) end end
-- up for i = 1, 5 do Effect = CreateMOPixel("SlagRifle MOPixel Slag 2", "PSI.rte") if Effect then Effect.Vel = self.Vel - self:RotateOffset(Vector(RangeRand(-2,2), RangeRand(7,11))) Effect.Pos = self.MuzzlePos MovableMan:AddParticle(Effect) end end
-- down for i = 1, 5 do Effect = CreateMOSParticle("Tiny Smoke Ball 1", "Base.rte") if Effect then Effect.Vel = self.Vel + self:RotateOffset(Vector(RangeRand(-2,2), RangeRand(7,11))) Effect.Pos = self.MuzzlePos MovableMan:AddParticle(Effect) end end end
-- update the ammo counter so this script can't spawn bullets until the gun has been fired again self.ammo = self.Magazine.RoundCount end end
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
Azukki
Joined: Sat Nov 03, 2007 9:44 pm Posts: 1916 Location: Flint Hills
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
Asklar
Data Realms Elite
Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
Re: Only fire when sharp-aimed?
Well, you could change Azukki's code and add some ors with the body moving. Like, with these:
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
Azukki
Joined: Sat Nov 03, 2007 9:44 pm Posts: 1916 Location: Flint Hills
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
Urch
Joined: Mon Sep 28, 2009 2:15 am Posts: 720 Location: A fucking desert.
Re: Only fire when sharp-aimed?
after adding that, i'm still getting the same problem.
Sat Sep 03, 2011 7:52 pm
Asklar
Data Realms Elite
Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
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
Urch
Joined: Mon Sep 28, 2009 2:15 am Posts: 720 Location: A fucking desert.
Re: Only fire when sharp-aimed?
yes, I did.
Sat Sep 03, 2011 8:01 pm
Azukki
Joined: Sat Nov 03, 2007 9:44 pm Posts: 1916 Location: Flint Hills
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
Urch
Joined: Mon Sep 28, 2009 2:15 am Posts: 720 Location: A fucking desert.
Re: Only fire when sharp-aimed?
yes, that works well enough. Thanks, both of you.
Sun Sep 04, 2011 2:12 am
Urch
Joined: Mon Sep 28, 2009 2:15 am Posts: 720 Location: A fucking desert.
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
Azukki
Joined: Sat Nov 03, 2007 9:44 pm Posts: 1916 Location: Flint Hills
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.
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