FuriouZ Posted April 16, 2014 Share Posted April 16, 2014 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
Castillo Posted April 16, 2014 Share Posted April 16, 2014 Make a table with the valid weapon slots, then check if the weapon slot the player is using is in that table. Link to comment
FuriouZ Posted April 16, 2014 Author Share Posted April 16, 2014 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
Castillo Posted April 16, 2014 Share Posted April 16, 2014 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
Castillo Posted April 16, 2014 Share Posted April 16, 2014 Any errors in debugscript? try debugging the script to see what weapSlot is returning, what clip is returning, etc. Link to comment
FuriouZ Posted April 16, 2014 Author Share Posted April 16, 2014 There's no errors in debug, even if i put only one valid weapon to table, it doesn't draw it I think the problem is in table ? Link to comment
FuriouZ Posted April 16, 2014 Author Share Posted April 16, 2014 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
Vinctus Posted April 16, 2014 Share Posted April 16, 2014 don't you have on extra 'end' at the end of the script? Link to comment
FuriouZ Posted April 16, 2014 Author Share Posted April 16, 2014 don't you have on extra 'end' at the end of the script? No Link to comment
Castillo Posted April 16, 2014 Share Posted April 16, 2014 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
FuriouZ Posted April 16, 2014 Author Share Posted April 16, 2014 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 " ) but if i add move weaponSlot's then it doesn't draw it if i' am reloading or not reloading: not reloading: Link to comment
Castillo Posted April 16, 2014 Share Posted April 16, 2014 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
Castillo Posted April 16, 2014 Share Posted April 16, 2014 What do you mean? I tested that code and worked perfectly. Link to comment
FuriouZ Posted April 16, 2014 Author Share Posted April 16, 2014 What do you mean? I tested that code and worked perfectly. Oh, sorry, i didn't saw that you posted the new code Thanks, it works perfectly now ! Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now