--DESCRIPTION: [TEXT$="Hello"] --DESCRIPTION: [XPOS=50] --DESCRIPTION: [YPOS=50] --DESCRIPTION: [RANGE=1000] --DESCRIPTION: [SIZE=3(1,5)] --DESCRIPTION: [RED=255(0,255)] --DESCRIPTION: [GREEN=255(0,255)] --DESCRIPTION: [BLUE=255(0,255)] function local_prompt_properties(e, text, xpos,ypos, range, size, red,green,blue) local lp = g_local_prompt[e] lp.text = text lp.xpos = xpos lp.ypos = ypos lp.range = range lp.size = size lp.red = red lp.green = green lp.blue = blue end g_local_prompt = {} function local_prompt_init(e) g_local_prompt[e] = {} local_prompt_properties(e, "hello", 50,50, 1000, 3, 255,255,255) end function local_prompt_main(e) local lp = g_local_prompt[e] PromptLocalPosition(e, lp.text, lp.xpos, lp.ypos, lp.range, lp.size, lp.red,lp.green,lp.blue) end function PromptLocalPosition(e, txt, ox,oy, rng, size, r,g,b) local function PointAtPlayer(i) local x = g_PlayerPosX - g_Entity[i]['x'] local z = g_PlayerPosZ - g_Entity[i]['z'] local angle = math.atan2( z , x ) angle = angle + (-90.0*0.0174533) return angle end local dist = GetPlayerDistance(e) if dist < rng then -- work out the angle of the player facing vs the angle to the object local angle = PointAtPlayer(e) + math.rad(g_PlayerAngY) local anglex = g_PlayerAngY - GetAngleFromPointToPoint(g_PlayerPosX,g_PlayerPosZ, g_Entity[e]['x'],g_Entity[e]['z']) -- if the object is to the left we need to go negative in x if anglex > 180 then anglex = anglex - 360 elseif anglex < -180 then anglex = anglex + 360 end -- take the distance into account so closer objects get less effected local distx = dist / rng * 0.01 local ex,ey = g_Entity[e].x, g_Entity[e].y local textx = (distx + anglex) * -1 textx = textx + ox local texty = oy + (g_PlayerPosY - ey) * 0.125 -- need to take player x angle into account local pax = g_PlayerAngX -- looking up if pax >= 280 then texty = texty + ((360 - g_PlayerAngX) * 2) -- looking down else texty = texty + (g_PlayerAngX * -1.2) end --Prompt("textx = "..textx.." , texty = "..texty.." pax = "..g_PlayerAngX) -- check if the text will be on screen if textx >= 0 and textx <= 100 then if texty >= 0 and texty <= 100 then --TextCenterOnXColor(x,y,size,txt,r,g,b) TextCenterOnXColor(textx,texty, size, txt, r,g,b) end end end end function GetAngleFromPointToPoint(x1,z1, x2,z2) local destx = x2 - x1 local destz = z2 - z1 local angle = math.atan2(destx,destz) angle = angle * (180.0 / math.pi) if angle < 0 then angle = 360 + angle elseif angle > 360 then angle = angle - 360 end return angle end