I really dont see the mistake. I have a variable
local WeaponName = Player:GetActiveWeapon():GetPrintName()
(Yes, Player is defined as LocalPlayer())
When the Player has the Physics Gun equipped, WeaponName is "PHYSICS GUN".
That is alo when i print WeaponName. It is "PHYSICS GUN", in Caps.
But when i do
if WeaponName ~= "PHYSICS GUN" then
surface.PlaySound(AmmoEmptySound)
end
The Sound gets playd even if the player has the physics gun equipped. Even tho it shouldnt be possible because the if statement checks if the player is holding anything else than the PHYSICS GUN.
So how can this possibly not work?? Its what WeaponName returns, and it still doesnt work.
The if statement here was a example, it also contains a check for if clip1 and clip2 ammo is empty. Heres the whole code, i really have no idea anymore?
TwicerCheck = false
local AmmoEmptySounds = {
"Ammo_empty/Ammoempty_angry1.mp3",
"Ammo_empty/Ammoempty_angry2.mp3",
"Ammo_empty/Ammoempty1.mp3",
"Ammo_empty/Ammoempty2.mp3",
"Ammo_empty/Ammoempty3.mp3",
}
function AmmoEmptySound()
if TwicerCheck == false then
local Randomizer = math.random(1, 5)
surface.PlaySound(AmmoEmptySounds[Randomizer])
TwicerCheck = true
end
end
hook.Add("HUDAmmoPickedUp", "ResetTwicer", function()
TwicerCheck = false
end)
hook.Add("PostGamemodeLoaded", "KatoAmmoEmptyGM", function()
hook.Add("Think", "KatoAmmoEmpty", function()
local Player = LocalPlayer()
if (Player:GetActiveWeapon():IsValid()) then
local Clip1Ammo = Player:GetActiveWeapon():Clip1()
local Clip2Ammo = Player:GetAmmoCount(Player:GetActiveWeapon():GetPrimaryAmmoType())
local SecAmmo = Player:GetAmmoCount(Player:GetActiveWeapon():GetSecondaryAmmoType())
local WeaponName = Player:GetActiveWeapon():GetPrintName()
print(Clip1Ammo.." "..Clip2Ammo)
if Clip1Ammo <= 0 and Clip2Ammo <= 0 and WeaponName ~= "PHYSICS GUN" then
if Clip1Ammo == -1 and Clip2Ammo == 0 then
AmmoEmptySound()
end
end
end
end)
end)
--[[Two Mayor Problems:
Ammo Empty Sound Plays on Spawn, when PHYSICS GUN is in Hands.
Doesn`t play again until you pick up Ammo (which is good),
but then plays also when the ammo that has been equiped
is NOT the ammo of the empty Ammo. So Addon will say
your out of Ammo again, even tho your Ammo is empty the whole time.]]
use Entity/GetClass
Yeah like Fancy says, it uses #GMOD_Physgun, and that’s so it can be compatible with different languages.
When the game encounters that, it’ll search for the appropriate translation.
so should i put in the if statement #GMOD_Physgun, or make a variable with Entity/GetClass and compare THAT in the uf statement?
local ply = LocalPlayer()
if not IsValid(ply) then return end
weapon = ply:GetActiveWeapon()
if not IsValid(weapon) then return end
if weapon:GetClass() ~= "what the weapon's class is" then
end
You replace the string with whatever the weapon's class is, which can be checked using the GetClass
method
if i make
local weapon = Player:GetActiveWeapon()
print(weapon)
it returns
Weapon [115][weapon_physgun]
and when i put that in the if statement it still plays. ...sooo..any idea? why does it return for me that huge thing?
Sorry, you need to Log In to post a reply to this thread.