local textx = 50 --center of the text on the x axis (% of screen) local texty = 90 --position of the text on the y axis (% of screen) local textsize = 3 --text size (1 = small, 5 = large) local use_range = 120 --how close player needs to be to object to "interact" with it local prompt_line = "Press *E* to check" --first line that appears (2nd line onwards is taken from object 'name' local line_number = {} local line = {} local str = {} local state = {} local a = nil obj_pressed = 0 --remember name should be filled with text and separated with fullstop/period between lines function interact_object_init_name(e,name) state[e] = "active" str[e] = name line[e] = {} line[e][1] = prompt_line a = 2 for word in string.gmatch(str[e], '([^.]+)') do line[e][a] = word a = a + 1 end line_number[e] = 1 end function interact_object_main(e) if PlayerLooking(e,use_range,10) == 1 then if state[e] == "active" then TextCenterOnX(textx,texty,textsize,line[e][line_number[e]]) if g_KeyPressE == 1 and obj_pressed == 0 then obj_pressed = 1 if line[e][line_number[e]+1] ~= nil then line_number[e] = line_number[e] + 1 else state[e] = "inactive" end end end else state[e] = "active" line_number[e] = 1 end if g_KeyPressE == 0 then obj_pressed = 0 end end function interact_object_exit(e) end function PlayerLooking(e,dis,v) if g_Entity[e] ~= nil then if dis == nil then dis = 3000 end if v == nil then v = 0.5 end if GetPlayerDistance(e) <= dis then local destx = g_Entity[e]['x'] - g_PlayerPosX local destz = g_Entity[e]['z'] - g_PlayerPosZ 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 while g_PlayerAngY < 0 or g_PlayerAngY > 360 do if g_PlayerAngY <= 0 then g_PlayerAngY = 360 + g_PlayerAngY elseif g_PlayerAngY > 360 then g_PlayerAngY = g_PlayerAngY - 360 end end local L = angle - v local R = angle + v if L <= 0 then L = 360 + L elseif L > 360 then L = L - 360 end if R <= 0 then R = 360 + R elseif R > 360 then R = R - 360 end if (L < R and math.abs(g_PlayerAngY) > L and math.abs(g_PlayerAngY) < R) then return 1 elseif (L > R and (math.abs(g_PlayerAngY) > L or math.abs(g_PlayerAngY) < R)) then return 1 else return 0 end else return 0 end end end