Jump to content

Problem


FuriouZ

Recommended Posts

Hey!

I'm trying to draw reloading text if bullets in weapon are < 1 and if player have gun..

So, everything works fine until i add more weapons to "weaponSlot" than one

If i use

  
local clip = getPedAmmoInClip (getLocalPlayer()) 
local weapSlot = getPedWeaponSlot(getLocalPlayer())      
if ( clip < 1 and weapSlot == 3 ) then 
    dxDrawText("Reloading...", xSP+100,ySP+20, 290*sW, 250*sH, tocolor (255, 255, 255, 255), 1.25*sW,1.25*sH,"default-bold","left","top",false,false,false,true)         
end 

then it draws "Reloading" always if player is reloading a gun, this is what i want

but if i want add more weaponSlot's

then it draws "Reloading" even if player isn't reloading

       
local clip = getPedAmmoInClip (getLocalPlayer()) 
local weapSlot = getPedWeaponSlot(getLocalPlayer())   
if ( clip < 1 and weapSlot == 2 or 3 or 4 or 5 or 6 or 7 or 8 ) then 
    dxDrawText("Reloading...", xSP+100,ySP+20, 290*sW, 250*sH, tocolor (255, 255, 255, 255), 1.25*sW,1.25*sH,"default-bold","left","top",false,false,false,true)         
end 

also there isn't any errors in debug

Link to comment
Make a table with the valid weapon slots, then check if the weapon slot the player is using is in that table.

Now it doesn't draw reloading text at all, no errors in debug

local validWeaponSlots = 
{ 
    { 2 }, 
    { 3 },   
    { 4 },   
    { 5 }, 
    { 6 }, 
    { 7 }, 
    { 8 }, 
} 
local clip = getPedAmmoInClip (getLocalPlayer()) 
local weapSlot = getPedWeaponSlot(getLocalPlayer())   
if ( clip < 1 and weapSlot == validWeaponSlots ) then 
    dxDrawText("Reloading...", xSP+100,ySP+20, 290*sW, 250*sH, tocolor (255, 255, 255, 255), 1.25*sW,1.25*sH,"default-bold","left","top",false,false,false,true)        
end 
  

Link to comment
local validWeaponSlots = 
{ 
    [ 2 ] = true, 
    [ 3 ] = true,  
    [ 4 ] = true,  
    [ 5 ] = true, 
    [ 6 ] = true, 
    [ 7 ] = true, 
    [ 8 ] = true, 
} 
  
local clip = getPedAmmoInClip ( localPlayer ) 
local weapSlot = getPedWeaponSlot ( localPlayer ) 
if ( clip < 1 and validWeaponSlots [ weapSlot ] ) then 
    dxDrawText("Reloading...", xSP+100,ySP+20, 290*sW, 250*sH, tocolor (255, 255, 255, 255), 1.25*sW,1.25*sH,"default-bold","left","top",false,false,false,true)       
end 

Link to comment
Do you actualy render it ???

Of course

  
local validWeaponSlots = 
{ 
    [ 2 ] = true, 
    [ 3 ] = true, 
    [ 4 ] = true, 
    [ 5 ] = true, 
    [ 6 ] = true, 
    [ 7 ] = true, 
    [ 8 ] = true, 
} 
addEventHandler("onClientRender", root, 
    function() 
        if getControlState ("aim_weapon") then 
        local ammo = getPedTotalAmmo (getLocalPlayer()) 
        local clip = getPedAmmoInClip (getLocalPlayer()) 
        local weaponID = getPedWeapon(localPlayer) 
        local weapName = getWeaponNameFromID(weaponID) 
        local weapSlot = getPedWeaponSlot(getLocalPlayer())     
        local xBone,yBone,zBone = getPedBonePosition(getLocalPlayer(),8) 
        local zBone = zBone - 0.5 
        local xSP,ySP = getScreenFromWorldPosition ( xBone,yBone,zBone )        
        if ( xSP and ySP ) then  
        dxDrawText(weapName.." "..clip.." | "..ammo, xSP+100,ySP, 290*sW, 250*sH, tocolor (255, 255, 255, 255), 1.25*sW,1.25*sH,"default-bold","left","top",false,false,false,true) 
        if ( clip < 1 and weapSlot == validWeaponSlots [ weapSlot ] ) then 
            dxDrawText("Reloading...", xSP+100,ySP+20, 290*sW, 250*sH, tocolor (255, 255, 255, 255), 1.25*sW,1.25*sH,"default-bold","left","top",false,false,false,true)        
        end 
        end 
        end 
        end 
)   

Link to comment

If that's your full script, then you forgot to define "sW" and "sH".

local validWeaponSlots = 
{ 
    [ 2 ] = true, 
    [ 3 ] = true, 
    [ 4 ] = true, 
    [ 5 ] = true, 
    [ 6 ] = true, 
    [ 7 ] = true, 
    [ 8 ] = true, 
} 
local sW, sH = guiGetScreenSize ( ) 
  
addEventHandler ( "onClientRender", root, 
    function ( ) 
        if getControlState ( "aim_weapon" ) then 
            local ammo = getPedTotalAmmo ( localPlayer ) 
            local clip = getPedAmmoInClip ( localPlayer ) 
            local weaponID = getPedWeapon ( localPlayer ) 
            local weapName = getWeaponNameFromID ( weaponID ) 
            local weapSlot = getPedWeaponSlot ( localPlayer ) 
            local xBone,yBone,zBone = getPedBonePosition ( localPlayer, 8 ) 
            local zBone = ( zBone - 0.5 ) 
            local xSP, ySP = getScreenFromWorldPosition ( xBone, yBone, zBone ) 
            if ( xSP and ySP ) then 
                dxDrawText ( weapName .." ".. clip .." | ".. ammo, xSP+100,ySP, 290*sW, 250*sH, tocolor (255, 255, 255, 255), 1.25*sW,1.25*sH, "default-bold", "left", "top", false, false, false, true ) 
                if ( clip < 1 and validWeaponSlots [ weapSlot ] ) then 
                    dxDrawText ( "Reloading...", xSP+100,ySP+20, 290*sW, 250*sH, tocolor (255, 255, 255, 255), 1.25*sW,1.25*sH,"default-bold", "left", "top", false, false, false, true ) 
                end 
            end 
        end 
    end 
) 

Link to comment
If that's your full script, then you forgot to define "sW" and "sH".

No, i didn't

local screenW,screenH = guiGetScreenSize() 
local resW,resH = 1280,720 
local sW,sH =  (screenW/resW), (screenH/resH) 

It should draw "Reloading.. "

under the weapon ammo and name like this:

(works only this way " if ( clip < 1 and weapSlot == 3 ) then " )

mta-screen_2014-04-16_19-14-46.png

but if i add move weaponSlot's

then it doesn't draw it if i' am reloading or not

reloading:

mta-screen_2014-04-16_19-43-27.png

not reloading:

mta-screen_2014-04-16_19-43-26.png

Link to comment

That's because you changed what I gave you.

The 'if' must be like this:

if ( clip < 1 and validWeaponSlots [ weapSlot ] ) then 

Not:

if ( clip < 1 and weapSlot == validWeaponSlots [ weapSlot ] ) then 

Full code:

local validWeaponSlots = 
{ 
    [ 2 ] = true, 
    [ 3 ] = true, 
    [ 4 ] = true, 
    [ 5 ] = true, 
    [ 6 ] = true, 
    [ 7 ] = true, 
    [ 8 ] = true, 
} 
local screenW,screenH = guiGetScreenSize() 
local resW,resH = 1280,720 
local sW,sH =  (screenW/resW), (screenH/resH) 
  
addEventHandler ( "onClientRender", root, 
    function ( ) 
        if getControlState ( "aim_weapon" ) then 
            local ammo = getPedTotalAmmo ( localPlayer ) 
            local clip = getPedAmmoInClip ( localPlayer ) 
            local weaponID = getPedWeapon ( localPlayer ) 
            local weapName = getWeaponNameFromID ( weaponID ) 
            local weapSlot = getPedWeaponSlot ( localPlayer ) 
            local xBone,yBone,zBone = getPedBonePosition ( localPlayer, 8 ) 
            local zBone = ( zBone - 0.5 ) 
            local xSP, ySP = getScreenFromWorldPosition ( xBone, yBone, zBone ) 
            if ( xSP and ySP ) then 
                dxDrawText ( weapName .." ".. clip .." | ".. ammo, xSP+100,ySP, 290*sW, 250*sH, tocolor (255, 255, 255, 255), 1.25*sW,1.25*sH, "default-bold", "left", "top", false, false, false, true ) 
                if ( clip < 1 and validWeaponSlots [ weapSlot ] ) then 
                    dxDrawText ( "Reloading...", xSP+100,ySP+20, 290*sW, 250*sH, tocolor (255, 255, 255, 255), 1.25*sW,1.25*sH,"default-bold", "left", "top", false, false, false, true ) 
                end 
            end 
        end 
    end 
) 

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