Jump to content

ammo limit


Tox

Recommended Posts

hey uh, i am trying to make an ammo limit but when after a few attempts, it somehow reduces ammo. i couldn't find a solution so i thought about posting it here;

outputDebugString ("Ammo limit (re)started.") 
local number = 0 
local slotLimits = { 
--index = slot,[get ID] = {weapon 1, weapon 2, weapon 3}, limit      
[1] = {2,{22,23,24},tonumber (get ("Handgun Limit"))}, 
[2] = {3,{25,26,27},tonumber (get ("Shotgun Limit"))}, 
[3] = {4, {28,29,32},tonumber (get ("Submachine Gun Limit"))}, 
[4] = {5, {30,31},tonumber (get ("Machine Gun Limit"))}, 
[5] = {6,{33,34},tonumber (get ("Rifle Limit"))}, 
[6] = {8, {16,17,18,39}, tonumber (get ("Projectile Limit"))}, 
[7] = {7, {35,36}, tonumber (get ("Heavy Weapon Limit"))} 
} 
  
function weaponLimit() 
    for i,v in ipairs (getElementsByType ("player")) do 
        for index, value in ipairs (slotLimits) do 
            if getPedTotalAmmo(v,value[1]) ~= value[3] then 
                if getPedTotalAmmo (v,value[1]) >= value[3] then 
                    if #value[2] == 2 then 
                        number = 2  
                    elseif #value[2] == 3 then 
                        number = 3 
                    else 
                        number = 4 
                    end  
                    for i= 1, number do  
                        setWeaponAmmo (v, value[2][i], value[3] ) 
                    end          
                end  
            end  
        end 
    end  
end 
     
setTimer (weaponLimit, 50, 0)  
addEventHandler ("onPlayerWeaponSwitch",root,weaponLimit) 

Link to comment
  • Moderators

This function will make it a lot easier:

local weapon = getPedWeapon(player,index)-- index = slot 

https://wiki.multitheftauto.com/wiki/GetPedWeapon

New structure:

[1] = {2,[color=#FF0000]{[22]=true,[23]=true,[24]=true}[/color],tonumber (get ("Handgun Limit"))}, 

local isWeaponLimited = value[2][weapon] -- true/nil 
if isWeaponLimited then 

Line 17 isn't required.

if getPedTotalAmmo(v,value[1]) ~= value[3] then 

Put the timer on 500 ms, the result of getPedTotalAmmo only changes after the clients are sync their ammo back.

This event isn't required to be bounded on a function that is for all players.

addEventHandler ("onPlayerWeaponSwitch",root,weaponLimit) 
Link to comment

thank you both,

@#RooTs i don't really see what's going on in that video

@IIYAMA i thought about local weapon = getPedWeapon(player,index)-- index = slot but i needed to state certain slots so i insert them in table, thank you for suggestion though. isWeaponLimited is good idea thank you for that. i've set timer 500 ms and so far we have no problem, sir. thank you

Link to comment
thank you both,

@#RooTs i don't really see what's going on in that video

@IIYAMA i thought about local weapon = getPedWeapon(player,index)-- index = slot but i needed to state certain slots so i insert them in table, thank you for suggestion though. isWeaponLimited is good idea thank you for that. i've set timer 500 ms and so far we have no problem, sir. thank you

you can make a demo video for me to see?, it may be useful to me.

Link to comment
thank you both,

@#RooTs i don't really see what's going on in that video

@IIYAMA i thought about local weapon = getPedWeapon(player,index)-- index = slot but i needed to state certain slots so i insert them in table, thank you for suggestion though. isWeaponLimited is good idea thank you for that. i've set timer 500 ms and so far we have no problem, sir. thank you

you can make a demo video for me to see?, it may be useful to me.

oh, limited internet sorry. but i can send you the script through PM if you want

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...