-Blaze- Posted November 11, 2014 Share Posted November 11, 2014 hey , i'm trying to make a code in which a weapon is not taken from a player when the weapons ammo reaches 0. if it is possible , how? Link to comment
ViRuZGamiing Posted November 11, 2014 Share Posted November 11, 2014 You can do a check for ammo, if it's 0 then set it too 1 perhaps, except you'll have the problem that will be infinite ammo. but to cancel that you can say on weapon fire cancel if ammo is 1. so he can only shoot when ammo is more then 1. Link to comment
-Blaze- Posted November 11, 2014 Author Share Posted November 11, 2014 i could do that , but then the ammo would show as "1" in the HUD , which i don't want. Thanks anyways. Link to comment
ViRuZGamiing Posted November 11, 2014 Share Posted November 11, 2014 That's something you can change hud wise. if ammo is 1 set the dxDrawText (or what is used) set it as 0. Link to comment
-Blaze- Posted November 11, 2014 Author Share Posted November 11, 2014 well , theres gotta be another way too right? Link to comment
ViRuZGamiing Posted November 11, 2014 Share Posted November 11, 2014 Did some research for you, and too bad there isn't a possible way (which is simple), I suggest 2 things. • What i've said before. • What is explained in the link below. Link: https://forum.multitheftauto.com/viewtopic.php?f=91&t=40797 Link to comment
-Blaze- Posted November 11, 2014 Author Share Posted November 11, 2014 you mean something like this? function donttakemygun() local currentweapon = getPedWeapon (getLocalPlayer()) local currentammo = getWeaponAmmo (currentweapon) if (currentammo < 2) then toggleControl ("fire", false ) -- disable the fire key end end addEventHandler("onClientRender", getLocalPlayer(), donttakemygun) or function donttakemygun() local currentammo = getPedTotalAmmo (getLocalPlayer()) if (currentammo < 2) then toggleControl ("fire", false ) -- disable the fire key end end addEventHandler("onClientRender", getLocalPlayer(), donttakemygun) none of them seem to work. Link to comment
steadyfi Posted November 11, 2014 Share Posted November 11, 2014 you mean something like this? function donttakemygun() local currentweapon = getPedWeapon (getLocalPlayer()) local currentammo = getWeaponAmmo (currentweapon) if (currentammo < 2) then toggleControl ("fire", false ) -- disable the fire key end end addEventHandler("onClientRender", getLocalPlayer(), donttakemygun) or function donttakemygun() local currentammo = getPedTotalAmmo (getLocalPlayer()) if (currentammo < 2) then toggleControl ("fire", false ) -- disable the fire key end end addEventHandler("onClientRender", getLocalPlayer(), donttakemygun) none of them seem to work. You could try to use onClientPlayerWeaponFire handler and see how it works , i'm gonna give you 2 scripts and you-ll see what's better. onClientPlayerWeaponFire triggers the function every time the player shoots so its better in this situation. #1 Uses toggleControl function dontTakeMyGun() --the function local currentammo = getPedTotalAmmo(getLocalPlayer()) --set the variable "currentammo" if (currentammo < 2) then --if ammo <2 then do toggleControl ("fire", false ) --toggle bind end end addEventHandler("onClientPlayerWeaponFire", getLocalPlayer(), dontTakeMyGun) --Triggers the function every time the peds fire #2 Uses cancelEvent (see the comment on it to see what it means) function dontTakeMyGun() --the function local currentammo = getPedTotalAmmo(getLocalPlayer()) --set the variable "currentammo" if (currentammo < 2) then --if ammo <2 then do cancelEvent(true) --cancels the event which in this case is onClientPlayerWeaponFire so you can't shoot end end addEventHandler("onClientPlayerWeaponFire", getLocalPlayer(), dontTakeMyGun) --Triggers the function every time the peds fire Link to comment
TAPL Posted November 11, 2014 Share Posted November 11, 2014 The event onClientPlayerWeaponFire is not cancelable. Link to comment
-Blaze- Posted November 11, 2014 Author Share Posted November 11, 2014 thanks ImSteady , the second one worked. Yes TAPL , realized that when i tried it . Umm, I lose my last shot when I aim and press tab. Is there a way to stop that? Link to comment
steadyfi Posted November 19, 2014 Share Posted November 19, 2014 thanks ImSteady , the second one worked.Yes TAPL , realized that when i tried it . Umm, I lose my last shot when I aim and press tab. Is there a way to stop that? Tab is set to fire. Go to Settings>Binds and see Action: Tab, unbind it. And what do you mean by I lose my last shot ? You mean you can't shoot at 2 bullets left ? Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now