Jump to content

ammo


Xwad

Recommended Posts

ALw7sH it's working thanks:D But i want to make that it will only give the guns if i already have them. I mean if i have ak47 then i will get only ak47 but if i have only grenade then i will only get grenade. Is is possible to make that? or is it very difficult? thanks.

Idont know if this is exactly what you want

function giveAmmo ( theVehicle, seat ) 
    if (getElementModel(theVehicle) == 433) then  
    local weapon = getPedWeapon (source) 
        if weapon then 
        giveWeapon ( source, weapon, 200 ) 
        end 
    end 
end 
addEventHandler ( "onPlayerVehicleEnter", getRootElement(), giveAmmo ) 

Link to comment
  
addEventHandler( "onPlayerVehiclenter", getRootElement(), 
function( vehicle, seat, jacked ) 
if ( ( getElementModel( vehicle ) == 433 ) and ( getPedWeapon( source, 5 ) == 31 ) ) then 
   outputChatBox( "Yeah, Ammo", source, 255, 255, 0 ); 
   giveWeapon( source, 31, 200 ); 
   end 
end ) 
  

Link to comment

how can i set for each weapon the ammo when i get in the vehicle? becaouse i want to make that if i have ak47 and rpg and enter the vehicle then i will get 200 ammo for ak47 but for rpg only 2. how can i make that? thanks.

Link to comment
addEventHandler( "onPlayerVehicleEnter", getRootElement(), 
function( vehicle, seat, jacked ) 
if ( getElementModel( vehicle ) == 433  ) then 
if ( getPedWeapon( source ) == 31 ) then --if  m4 
   giveWeapon( source, 31, 200 ); -- give m4 and 200 ammo 
elseif ( getPedWeapon( source ) == 30 ) then --if  ak47 
   giveWeapon( source, 30, 300 ); -- then give weapon ak47 and 300 ammo 
elseif ( getPedWeapon( source ) == 35 ) then -- if rpg 
   giveWeapon( source, 35, 2 ); -- then give weapon 35 and 2 ammo 
-- and so on how you like it. 
   end 
   outputChatBox( "Yeah, Ammo", source, 255, 255, 0 ); 
   end 
end ) 

this script is for easy understand ...

you can find all weapon ids here -> https://wiki.multitheftauto.com/wiki/Weapons

Link to comment

Try this:

addEventHandler("onPlayerVehicleEnter", getRootElement(), 
    function(vehicle, seat, jacked) 
    if (getElementModel(vehicle) == 433) then 
        local wep = getPedWeapon(source) or 0 
        if (wep == 0 or wep == 1 or wep == 10 or wep == 11 or wep == 12) then -- If its a melee. 
            outputChatBox("You can not have weapon ammo for "..getWeaponNameFromID(wep), source, 200, 0, 0) 
            return 
        end 
        if tonumber(wep) then giveWeapon(source, wep, 200) end 
        outputChatBox("You have been given 200 ammo for "..getWeaponNameFromID(wep), source, 255, 255, 0) 
    end 
end) 

Link to comment

is it server sided ?becaouse its not working i got 200 ammo:/ But it dosent metter im not patient anymore.. thanks for helping:)

  
maxAmmo = { 
["m4"] = 200, 
["mp5"] = 128, 
["grenade"] = 5, 
["colt45"] = 30, 
["silenced"] = 24, 
["deagle"] = 24, 
["shotgun"] = 30, 
["uzi"] = 120, 
["ak47"] = 200, 
["rifle"] = 30, 
["sniper"] = 30, 
["rocketlaucher"] = 4, 
["heatseeker"] = 4, 
["moltov"] = 5 
} 
-- And use like this: 
if ammo >= maxAmmo[wep] then setWeaponAmmo(player, wep, maxAmmo[wep]) end -- server sided. 
  

Link to comment

Make table like that and add checks when giving ammo like this:

maxAmmo = { 
["m4"] = 200, 
["mp5"] = 128, 
["grenade"] = 5, 
["colt45"] = 30, 
["silenced"] = 24, 
["deagle"] = 24, 
["shotgun"] = 30, 
["uzi"] = 120, 
["ak47"] = 200, 
["rifle"] = 30, 
["sniper"] = 30, 
["rocketlaucher"] = 4, 
["heatseeker"] = 4, 
["moltov"] = 5 
} 
  
function giveAmmo(player, wep, ammo) 
    if (not tonumber(ammo)) or (not tonumber(wep)) or (not player) then return end 
    local current = getPedTotalAmmo(player, wep) 
    if current >= (maxAmmo[wep] or 4) then setWeaponAmmo(player, wep, maxAmmo[wep]) return end -- If player have more than max ammo then it will set ammo to max. 
   local new = setWeaponAmmo(player, wep, (maxAmmo[wep] or 4)) 
end 
  
-- And then call this function in other events by giveAmmo(playerToGive, wep, ammo) and it will give maxx ammo to player. 

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...