Xierra Posted June 7, 2010 Share Posted June 7, 2010 (edited) Hi guys! Now I ask another question: I have made a table, I want to get weapon ID, but I'm a bit confused. local noreloadweapons = {} --Weapons that don't reload. {[16], [17], [18], [19], [25], [33], [34], [35], [36]} local meleespecialweapons = {} --Weapons that don't shoot, and special weapons. {[0], [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [13], [14], [15], [40], [44], [45], [46]} Here's what I want: Get weapon ID, then if the weapons is from noreloadweapons, I want it to show in the other DX text which I said will be later. dxDrawText("",646.0,731.0,694.0,766.0,tocolor(0,255,255,175),1.0,"bankgothic","right","top",false,false,false) --Ammo (for shotgun, grenades, etc), will be later. And if the weapons is from meleespecialweapons, I don't want to show anything, just simple, by guiSetVisible to false. How can I do this? I'm confused after reading the wiki. Edited June 8, 2010 by Guest Link to comment
DiSaMe Posted June 7, 2010 Share Posted June 7, 2010 First, you have to write numbers without [ and ] in these tables. To check if a table has the value, you can cycle through them. This code will check if current local player's weapon is included in table noreloadweapons: local is_weapon_in_table = false local player_weapon = getPedWeapon(getLocalPlayer()) for _,weapon_id in ipairs(noreloadweapons) do if player_weapon == weapon_id then is_weapon_in_table = true break end end if is_weapon_in_table then --the code executed if weapon is in the table end BUT there's much simpler way to do that if you store data in the table in other way noreloadweapons = {} noreloadweapons[16] = true noreloadweapons[17] = true noreloadweapons[18] = true noreloadweapons[19] = true noreloadweapons[25] = true --and continue this to 36 if noreloadweapons[getPedWeapon(getLocalPlayer())] then --the code executed if weapon is in the table end And if you don't want to show DX drawings with certain weapons, just don't draw them. They disappear 1 frame after they have been drawn, this is why you have to draw them in onClientRender. Link to comment
Xierra Posted June 7, 2010 Author Share Posted June 7, 2010 Right, I've have done this: -- Weapon tables function weapontables () local noreloadweapons = {} --Weapons that doesn't reload. noreloadweapons[16] = true noreloadweapons[17] = true noreloadweapons[18] = true noreloadweapons[19] = true noreloadweapons[25] = true noreloadweapons[33] = true noreloadweapons[34] = true noreloadweapons[35] = true noreloadweapons[36] = true local meleespecialweapons = {} --Weapons that don't shoot, and special weapons. meleespecialweapons[0] = true meleespecialweapons[1] = true meleespecialweapons[2] = true meleespecialweapons[3] = true meleespecialweapons[4] = true meleespecialweapons[5] = true meleespecialweapons[6] = true meleespecialweapons[7] = true meleespecialweapons[8] = true meleespecialweapons[9] = true meleespecialweapons[10] = true meleespecialweapons[11] = true meleespecialweapons[12] = true meleespecialweapons[13] = true meleespecialweapons[14] = true meleespecialweapons[15] = true meleespecialweapons[40] = true meleespecialweapons[44] = true meleespecialweapons[45] = true meleespecialweapons[46] = true if noreloadweapons [getPedWeapon(getLocalPlayer())] then guiSetVisible (totalammo, false) guiSetVisible (separator, false) guiSetVisible (ammoinclip, false) guiSetVisible (noreloadtotalammo, true) elseif meleespecialweapons [getPedWeapon(getLocalPlayer())] then guiSetVisible (totalammo, false) guiSetVisible (separator, false) guiSetVisible (ammoinclip, false) guiSetVisible (noreloadtotalammo, false) else guiSetVisible (totalammo, true) guiSetVisible (separator, true) guiSetVisible (ammoinclip, true) guiSetVisible (noreloadtotalammo, true) end end end -- All the Direct X Drawings function DXdraw() --Variables sWidth, sHeight = guiGetScreenSize() health = getElementHealth( getLocalPlayer() ) lineLength1 = 114 * ( health / 100 ) -- Health bar armor = getPedArmor( getLocalPlayer() ) lineLength2 = 114 * ( armor / 100 ) -- Armor bar ammoinclip1 = getPedAmmoInClip (getLocalPlayer()) totalammo1 = getPedTotalAmmo (getLocalPlayer()) showammo1=ammoinclip1 showammo2=totalammo1 moneycount=getPlayerMoney(getLocalPlayer()) money= '$' ..moneycount local hour, mins = getTime () time = hour.. ':' ..mins --DX Drawings noreloadtotalammo = dxDrawText(showammo2,646.0,731.0,694.0,766.0,tocolor(0,255,255,175),1.0,"bankgothic","right","top",false,false,false) --Ammo (for shotgun, grenades, etc), will be later. dxDrawRectangle(sWidth-206,sHeight-43,lineLength2,14.0,tocolor(200,200,200,200),false) -- Armor active bar dxDrawRectangle(sWidth-206,sHeight-23,114.0,14.0,tocolor(50,0,0,150),false) -- Health inactive bar totalammo = dxDrawText(tostring (showammo2),sWidth-340,sHeight-37,sWidth-292,sHeight-2,tocolor(0,255,255,175),1.0,"bankgothic","left","top",false,false,false) --Total Ammo separator = dxDrawText("|",sWidth-359,sHeight-37,sWidth-347,sHeight-6,tocolor(255,200,0,200),1.0,"bankgothic","left","top",false,false,false) --Separator ammoinclip = dxDrawText(tostring (showammo1),sWidth-413,sHeight-37,sWidth-365,sHeight-2,tocolor(0,255,255,175),1.0,"bankgothic","right","top",false,false,false) --Ammo in clip dxDrawRectangle(sWidth-206,sHeight-43,114.0,14.0,tocolor(50,50,50,150),false) -- Armor inactive bar dxDrawRectangle(sWidth-206,sHeight-23,lineLength1,14.0,tocolor(175,0,0,200),false) --Health active bar dxDrawRectangle(sWidth-84,sHeight-48,78.0,33.0,tocolor(0,0,0,150),false) -- GTA Time DX Rectangle dxDrawText(tostring (money),sWidth-200,sHeight-78,sWidth-5,sHeight-54,tocolor(0,0,0,200),1.0,"pricedown","right","top",false,false,false) -- Money DX text (shadow) dxDrawText(tostring (money),sWidth-202,sHeight-81,sWidth-7,sHeight-57,tocolor(0,100,0,220),1.0,"pricedown","right","top",false,false,false) -- Money DX text dxDrawText(tostring (time),sWidth-81,sHeight-46,sWidth-10,sHeight-16,tocolor(250,250,250,200),1.0,"diploma","center","top",false,false,false) -- GTA Time DX text end addEventHandler("onClientRender",getRootElement(),DXdraw) I got errors " expected near end" on line 57. I don't know where to place it, sorry. Can somebody help me where to put those tables? Link to comment
Dark Dragon Posted June 7, 2010 Share Posted June 7, 2010 remove the 'end' in line 57 but you can't use gui functions on dx draws. they are not elements. either you draw it or you don't, there is no "setVisible" function. to make it work store the tables outside of any function and check the player weapon every frame. Link to comment
Xierra Posted June 7, 2010 Author Share Posted June 7, 2010 I was thinking of a solution, your solution makes sense, but how should check weapon every frame and do what it says? Link to comment
Dark Dragon Posted June 7, 2010 Share Posted June 7, 2010 -- first draw the stuff which is visible at all times dxDrawRectangle(sWidth-206,sHeight-43,lineLength2,14.0,tocolor(200,200,200,200),false) -- Armor active bar dxDrawRectangle(sWidth-206,sHeight-23,114.0,14.0,tocolor(50,0,0,150),false) -- Health inactive bar dxDrawRectangle(sWidth-206,sHeight-43,114.0,14.0,tocolor(50,50,50,150),false) -- Armor inactive bar dxDrawRectangle(sWidth-206,sHeight-23,lineLength1,14.0,tocolor(175,0,0,200),false) --Health active bar dxDrawRectangle(sWidth-84,sHeight-48,78.0,33.0,tocolor(0,0,0,150),false) -- GTA Time DX Rectangle dxDrawText(tostring (money),sWidth-200,sHeight-78,sWidth-5,sHeight-54,tocolor(0,0,0,200),1.0,"pricedown","right","top",false,false,false) -- Money DX text (shadow) dxDrawText(tostring (money),sWidth-202,sHeight-81,sWidth-7,sHeight-57,tocolor(0,100,0,220),1.0,"pricedown","right","top",false,false,false) -- Money DX text dxDrawText(tostring (time),sWidth-81,sHeight-46,sWidth-10,sHeight-16,tocolor(250,250,250,200),1.0,"diploma","center","top",false,false,false) -- GTA Time DX text -- now decide if the optional stuff should be drawn if noreloadweapons [getPedWeapon(getLocalPlayer())] then -- draw nothing elseif meleespecialweapons [getPedWeapon(getLocalPlayer())] then dxDrawText(showammo2,646.0,731.0,694.0,766.0,tocolor(0,255,255,175),1.0,"bankgothic","right","top",false,false,false) --Ammo (for shotgun, grenades, etc), will be later. else dxDrawText(showammo2,646.0,731.0,694.0,766.0,tocolor(0,255,255,175),1.0,"bankgothic","right","top",false,false,false) --Ammo (for shotgun, grenades, etc), will be later. dxDrawText(tostring (showammo2),sWidth-340,sHeight-37,sWidth-292,sHeight-2,tocolor(0,255,255,175),1.0,"bankgothic","left","top",false,false,false) --Total Ammo dxDrawText("|",sWidth-359,sHeight-37,sWidth-347,sHeight-6,tocolor(255,200,0,200),1.0,"bankgothic","left","top",false,false,false) --Separator dxDrawText(tostring (showammo1),sWidth-413,sHeight-37,sWidth-365,sHeight-2,tocolor(0,255,255,175),1.0,"bankgothic","right","top",false,false,false) --Ammo in clip end Link to comment
Xierra Posted June 8, 2010 Author Share Posted June 8, 2010 Whew, did some tries and now it works as it should! Thanks Dragon, I'll credit you. Right, now I learned how to set DX text to be visible or invisible. Problem Solved. 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