-- LUA Script - precede every function and global member with lowercase name of script + '_main' -- Default script - does nothing. local speeches = {} local speechNames = {} local deg = math.deg local rad = math.rad local sin = math.sin local cos = math.cos local sqrt = math.sqrt function speeches_init_name(e, name) speechNames[e] = name if speeches[name] == nil then speeches[name] = {Ent = e, showing = false} Hide(e) end end local function Rotate3D (x, y, z, xrot, yrot, zrot) function RotatePoint2D (x, y, Ang) -- Ang in radians local Sa, Ca = sin(Ang), cos(Ang) return x*Ca - y*Sa, x*Sa + y*Ca end local NX, NY, NZ = x, y, z -- X NZ, NY = RotatePoint2D (NZ, NY, -xrot) -- Y NX, NZ = RotatePoint2D (NX, NZ, -yrot) -- Z NY, NX = RotatePoint2D (NY, NX, -zrot) return NX, NY, NZ end function ShowSpeech(speech, x, y, z, px, pz, ang) local speech = speeches[speech] if speech then -- work out position just in front of bubble wrt to player local xo, yo, zo = Rotate3D(0, 0, -2, 0, ang, 0) -- position speech wrt bubble ResetPosition(speech.Ent, x + xo, y, z + zo) -- rotate to face player ResetRotation(speech.Ent, 0, deg(ang), 0) if not speech.showing then Show(speech.Ent) speech.showing = true end end end function HideSpeech(name) local speech = speeches[name] if speech.showing then Hide(speech.Ent) speech.showing = false end end function speeches_main(e) local speech = speeches[speechNames[e]] if speech.Ent ~= e then PromptLocal(e, "Duplicate speech") end end