Piorun Posted August 18, 2010 Posted August 18, 2010 I've got problem with my script, so i need help. I was trying to create a nice code, but this code doesn't work. 1. How to create a script - when the player join into the server his nametag shows at the top of the head for all player, but his health bar was hide (i'm thinking i must use dxDrawText function). Please, help. I'm really noob of lua .
The_Ex Posted August 18, 2010 Posted August 18, 2010 Basically you will have to do something like this on every frame 1)getCameraMatrix 2) for loop through players 2.1)getElementPosition 2.2)isLineOfSightClear 3.1)getPedBonePosition 3.2)getScreenFromWorldPosition 3.3)dxDrawText MTASA.LV - Latvian MTA Community
Piorun Posted August 18, 2010 Author Posted August 18, 2010 Yhm, okey. I'll try. local rootElement = getRootElement() function test ( ) local px, py, pz = getElementPosition ( rootElement ) local x, y, z = getScreenFromWorldPosition( px, py, pz+1 ) if x then example = dxDrawText( "Imie Nazwisko", x, y ) end end function nick ( ) addEventHandler("onClientRender", rootElement, test) end addEventHandler ( "onClientResourceStart", rootElement, nick ) This is my code but it doesn't work. What i'm doing wrong?
dzek (varez) Posted August 18, 2010 Posted August 18, 2010 local px, py, pz = getElementPosition ( rootElement ) this is totally wrong. in your test function do local players = getElementsByType("player") for key,val in ipairs(players) do local px, py, pz = getElementPosition (val) local x, y, z = getScreenFromWorldPosition( px, py, pz+1 ) if x then example = dxDrawText( "Imie Nazwisko", x, y ) end end not tested Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online! programista php rzeszów Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting. Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!
The_Ex Posted August 18, 2010 Posted August 18, 2010 addEventHandler("onClientRender",getRootElement(), function() local px,py,pz,tx,ty,tz,dist px,py,pz = getCameraMatrix() for k,v in ipairs(getElementsByType("player")) do tx,ty,tz = getElementPosition(v) dist = math.sqrt((px-tx)^2 + (py-ty)^2 + (pz-tz)^2) if dist < 30.0 then if isLineOfSightClear(px,py,pz,tx,ty,tz,true,false,false,true,false,false,getLocalPlayer()) then local sx,sy,sz = getPedBonePosition(v,5) local x,y = getScreenFromWorldPosition(sx,sy,sz+0.3) if x then dxDrawText(getPlayerName(v),x,y,x,y,tocolor(150,50,0),0.85+(15-dist)*0.02,"bankgothic") end end end end end ) This is random example, should work. MTASA.LV - Latvian MTA Community
Piorun Posted August 18, 2010 Author Posted August 18, 2010 The_Ex thanks. It works really nice . I've got one more question. How to hide this text for local player, but shows for all players?
dzek (varez) Posted August 18, 2010 Posted August 18, 2010 addEventHandler("onClientRender",getRootElement(), function() local px,py,pz,tx,ty,tz,dist px,py,pz = getCameraMatrix() for k,v in ipairs(getElementsByType("player")) do if (v~=getLocalPlayer()) then tx,ty,tz = getElementPosition(v) dist = math.sqrt((px-tx)^2 + (py-ty)^2 + (pz-tz)^2) if dist < 30.0 then if isLineOfSightClear(px,py,pz,tx,ty,tz,true,false,false,true,false,false,getLocalPlayer()) then local sx,sy,sz = getPedBonePosition(v,5) local x,y = getScreenFromWorldPosition(sx,sy,sz+0.3) if x then dxDrawText(getPlayerName(v),x,y,x,y,tocolor(150,50,0),0.85+(15-dist)*0.02,"bankgothic") end end end end end end ) Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online! programista php rzeszów Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting. Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!
Piorun Posted August 18, 2010 Author Posted August 18, 2010 Ok and the last question. How to center this text? When i join into the server i saw my nickname at the right side. I include an image: Image
50p Posted August 19, 2010 Posted August 19, 2010 Use https://wiki.multitheftauto.com/wiki/DxGetTextWidth to get the text's width and draw the text half the width the text to the left of the head. Replace your dxDrawText with these 4: local scale = 0.85+(15-dist)*0.02; local playerName = getPlayerName( v ); local w = dxGetTextWidth( playerName, scale, "bankgothic" ); dxDrawText(playerName,x-w/2,y,x,y,tocolor(150,50,0),scale,"bankgothic") - MTA Script Editor - Ask your scripting questions properly, please. - 50p's public resources - Meta.xml - what is it for? How is it possible LOL
DiSaMe Posted August 19, 2010 Posted August 19, 2010 Or just set two more parameters, alignX and alignY, to "center" in dxDrawText. -
50p Posted August 19, 2010 Posted August 19, 2010 Or just set two more parameters, alignX and alignY, to "center" in dxDrawText. This will not give him the results that he wants.. He'll still have to use dxGetTextWidth. - MTA Script Editor - Ask your scripting questions properly, please. - 50p's public resources - Meta.xml - what is it for? How is it possible LOL
darkdreamingdan Posted September 1, 2010 Posted September 1, 2010 Or just set two more parameters, alignX and alignY, to "center" in dxDrawText. This will not give him the results that he wants.. He'll still have to use dxGetTextWidth. If you turn clipping off, then set identical left & right, and top & bottom parameters, you can use alignment easily. VCP FOREVER!
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