Jump to content

[HELP] Infinite ammo bug in DayZ gamemode


JsK

Recommended Posts

Hey guys. i have a small problem that makes my development stuck of my entire gamemode, Basically when i'm shooting with a gun , it shows on the guns hud that the ammo goes out , but it doesn't go out from the inventory , so Example if i take "AK-47" with 300 ammo and shoot 100 ammo , i re equip gun and i will have 300 ammo again. 

2nd problem is that i tried to see in /debugscript 3 where the error was , and couldn' find it.

 

function weaponSwitch(weapon)
    if source == getLocalPlayer() then	
        local ammoName,_ = getWeaponAmmoType2(weapon,getElementData(localPlayer,"currentweapon_1"),getElementData(localPlayer,"currentweapon_2"),getElementData(localPlayer,"currentweapon_3"),getElementData(localPlayer,"selectedWeapon"))
		if getElementData(getLocalPlayer(),ammoName) > 0 then
            setElementData(getLocalPlayer(),ammoName,getElementData(getLocalPlayer(),ammoName)-1)
        end
    end
end
addEventHandler("onClientPlayerWeaponFire",getLocalPlayer(),weaponSwitch)

HELP

Edited by Jisko27ns
Link to comment

Add 

outputChatBox(tostring(getElementData(getLocalPlayer(),ammoName)-1))

After line 5 to check if the ammo actually goes down. If it does, then the problem comes from the event when you switch to the gun, show us the code.

If it doesn't go down, that means that there's a problem from your function "getWeaponAmmoType2" or somewhere else not shown in the code.

Link to comment

i have added your line in the command and it :Oed up my whole inventory didnt wanted to open.

But the bug of ammo was gone but no inventory. And what is the code from the event when you switch the gun ?

 

function weaponSwitch(weapon)
    if source == getLocalPlayer() then	
        local ammoName,_ = getWeaponAmmoType2(weapon,getElementData(localPlayer,"currentweapon_1"),getElementData(localPlayer,"currentweapon_2"),getElementData(localPlayer,"currentweapon_3"),getElementData(localPlayer,"selectedWeapon"))
		if getElementData(getLocalPlayer(),ammoName) > 0 then
            setElementData(getElementData(getLocalPlayer(),ammoName)-1)
			outputChatBox(tostring(getElementData(getLocalPlayer(),ammoName)-1))
        end
    end
end
addEventHandler("onClientPlayerWeaponFire",getLocalPlayer(),weaponSwitch)

Keep in mind that this makes dissapear the inventory but the ammo goes down.

Link to comment

How could a simple 'outputChatBox' stop your inventory from running? Post your /debugscript 3 info.

You've said that your ammo gets reset when you switch guns so you need to look for something like

onClientPlayerWeaponSwitch

in your code.

Link to comment

Try

 

function weaponSwitch(weapon)
    if source == localPlayer then	
        local ammoName,_ = getWeaponAmmoType2(weapon,getElementData(localPlayer,"currentweapon_1"),getElementData(localPlayer,"currentweapon_2"),getElementData(localPlayer,"currentweapon_3"),getElementData(localPlayer,"selectedWeapon"))
		if getElementData(localPlayer, ammoName) > 0 then
            setElementData(localPlayer, getElementData(localPlayer,ammoName)-1)
			outputChatBox(tostring(getElementData(localPlayer, ammoName)-1))
        end
    end
end
addEventHandler("onClientPlayerWeaponFire", getLocalPlayer(), weaponSwitch)

 

You forgot the first argument in 'setElementData'.

Link to comment
5 minutes ago, Jisko27ns said:

            outputChatBox(tostring(getElemen tData(localPlayer, ammoName ) -1))

Probably because of the forum, sometimes it adds an invisible character at the end. Try to delete the last character after the ')' to fix it.

 

PS: I tried to take the code into my notepad++ and I could delete something invisible lol.

Edited by HassoN
Link to comment

Nope , same error , and there is nothing at the end 

i have made some changes and saw that the ammo was going down from the inventory , but when you have left like 1 bullet and re equip gun you get everything back , it's kinda like duplication stuff 

 

Here's the change of what i made :

	for i,weaponData in ipairs(weaponAmmoTable["51мм NATO"]) do
		if weaponName == weaponData[2] and (weap1 == weaponData[1] or weap2 == weaponData[1] or weap3 == weaponData[1]) then
			return "51мм NATO",weaponData[2]
		end
	end	
end
	
function weaponSwitch(weapon)
    if source == getLocalPlayer() then	
        local ammoName,_ = getWeaponAmmoType2(weapon,getElementData(localPlayer,"currentweapon_1"),getElementData(localPlayer,"currentweapon_2"),getElementData(localPlayer,"currentweapon_3"),getElementData(localPlayer,"selectedWeapon"))
		if getElementData(getLocalPlayer(),ammoName) > 0 then
            setElementData(getLocalPlayer(),ammoName,getElementData(getLocalPlayer(),ammoName)-1)
        end
    end
end
addEventHandler("onClientPlayerWeaponFire",getLocalPlayer(),weaponSwitch)

before there was only weaponName == weaponData[2] and WeaponAmmoType2 was added 2 times.

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