Jump to content

getPedWeapon bug in my script?


TrickyTommy

Recommended Posts

Hi. The script should draw an image of my current weapon if i don't hold weapon id 44 or 45, but it is not doing so.
 

			-- weap icon
			local weaponName = getPedWeapon(localPlayer)
			outputDebugString (weaponName)
			if tostring(weaponName) == not "44" and tostring(weaponName) == not "45" then
				local WeaponIcon = dxDrawImage (1360/dX*jX, 70/dY*jY, 200/dX*jX, 100/dY*jY, "assets/images/weapons/"..tonumber(fegyverid)..".png")
			else 
				outputDebugString ("else")
			end

"else" is being displayed, whether i hold weapon id 44, 45 or not.

Link to comment
  • Administrators
-- weap icon
local weaponName = getPedWeapon(localPlayer)
outputDebugString (weaponName)
if tostring(weaponName) == "44" or tostring(weaponName) == "45" then
  local WeaponIcon = dxDrawImage (1360/dX*jX, 70/dY*jY, 200/dX*jX, 100/dY*jY, "assets/images/weapons/"..tonumber(fegyverid)..".png")
else 
  outputDebugString ("else")
end

This would be a better way to do it.

However, if you want to check if something isn't true, you do it like so:

if not a == 1 then
  --a is not 1
else
  --a is 1
end

You were doing it like this:

if a == not 1 then
  --a is equal to false 1 (?)
else
  --will always return else due to incorrect if statement
end

 

Link to comment

yeah, i just noticed it. still not working....

 

			local weaponID = getPedWeapon(localPlayer)
			outputDebugString (weaponID)
			if not weaponID == 44 and not weaponID == 45 then
				local WeaponIcon = dxDrawImage (1360/dX*jX, 70/dY*jY, 200/dX*jX, 100/dY*jY, "assets/images/weapons/"..tonumber(weaponID)..".png")
			else 
				outputDebugString ("else")
			end

 

at least this way weapons get drawn:
 

local weaponID = getPedWeapon(localPlayer)
			outputDebugString (weaponID)
			local NotExist = {["44"] = true, ["45"] = true}
			if not NotExist[weaponID] then
				WeaponIcon = dxDrawImage (1360/dX*jX, 70/dY*jY, 200/dX*jX, 100/dY*jY, "assets/images/weapons/"..tonumber(weaponID)..".png")
			else 
				outputDebugString ("else")
			end

but yet it is attempting to draw on 44 and 45

Edited by TrickyTommy
Link to comment
  • Administrators

You're still doing it wrong, try like this and it should work

local weaponID = getPedWeapon(localPlayer)
outputDebugString (weaponID)
if weaponID == 44 or weaponID == 45 then
  local WeaponIcon = dxDrawImage (1360/dX*jX, 70/dY*jY, 200/dX*jX, 100/dY*jY, "assets/images/weapons/"..tonumber(weaponID)..".png")
else 
  outputDebugString ("else")
end

You want to check if the current weapon ID is X or Y

You are currently trying to check if the currently weapon ID is not X and Y, which will never be true because a variable can't be two different values at the same time

Edited by LopSided_
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...