Jump to content

Help Weapons


ksTakor

Recommended Posts

I have a problem with my inventory when a player drop a primary weapon ex: M4 but left the ammo in the inventory.

Then he equip a secondary weapon like a pistol, it equips again the m4.

I think the script is checking the ammo in the inventory then giving the weapon, but I like that it check if the weapon is there.

function rearmPlayerWeapon(weaponName, slot) 
  takeAllWeapons(source) 
  local ammoData, weapID = getWeaponAmmoType(weaponName) 
  if getElementData(source, ammoData) <= 0 then 
    triggerClientEvent(source, "displayClientInfo", source, "Rearm", shownInfos.nomag, 255, 22, 0) 
    return 
  end 
  setElementData(source, "currentweapon_" .. slot, weaponName) 
  local weapon = getElementData(source, "currentweapon_1") 
  if weapon then 
    local ammoData, weapID = getWeaponAmmoType(weapon) 
    giveWeapon(source, weapID, getElementData(source, ammoData), true) 
  end 
  local weapon = getElementData(source, "currentweapon_2") 
  if weapon then 
    local ammoData, weapID = getWeaponAmmoType(weapon) 
    giveWeapon(source, weapID, getElementData(source, ammoData), false) 
  end 
  local weapon = getElementData(source, "currentweapon_3") 
  if weapon then 
    local ammoData, weapID = getWeaponAmmoType(weapon) 
    giveWeapon(source, weapID, getElementData(source, ammoData), false) 
  end 
  if elementWeaponBack[source] then 
    detachElementFromBone(elementWeaponBack[source]) 
    destroyElement(elementWeaponBack[source]) 
    elementWeaponBack[source] = false 
  end 
  setElementModel(source, getElementData(source, "skin")) 
end 
addEvent("onPlayerRearmWeapon", true) 
addEventHandler("onPlayerRearmWeapon", getRootElement(), rearmPlayerWeapon) 

Thanks in Advance

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