Roland Posted December 21, 2012 Share Posted December 21, 2012 Hello there all LUA Guru's I have the need for showing a colored ring around an object in the Editor (not in game) when its selected. Any suggestion on how to accomplish that ? Like this Quote Roland Strålberg Website: https://rstralberg.com Link to comment Share on other sites More sharing options...
Daimour Posted December 21, 2012 Share Posted December 21, 2012 I did something similar for waypoints. Video: But it's not a ring actually (it's a 12 connected lines). It's not for selected entity (only for newly created or moved entity). It's for only one entity class (so it works not for all entities on the scene). And it's hiding automatically after some period of time. Code example (for entity-attached lua-script): local class=CreateClass(...) function class:CreateObject(model) local object=self.super:CreateObject(model) function object:Init() self.show_markers = 0 AddHook("Flip", object.Render) end function object:Render() if object.show_markers > 0 then SetColor(Vec4(1, 1, 0.5, 1)) local pos = EntityPosition(object.model, 1) local range = 5 for i = 1, 12 do local angle = math.rad((i - 1) * 30) local dx = math.cos(angle) * range local dz = math.sin(angle) * range local pos1 = CameraUnproject(fw.main.camera, Vec3(pos.x + dx, pos.y, pos.z + dz)) angle = math.rad(i * 30) dx = math.cos(angle) * range dz = math.sin(angle) * range local pos2 = CameraUnproject(fw.main.camera, Vec3(pos.x + dx, pos.y, pos.z + dz)) if pos1.z >= 0 and pos2.z >= 0 then DrawLine(pos1.x, pos1.y, pos2.x, pos2.y) end end end SetColor(Vec4(1, 1, 1, 1)) end function object:ReceiveMessage(message,extra) local values=string.Explode(message,",") local command = values[1] if command == "hide_markers" then self.show_markers = 0 end end function object:ShowMarkers() self.show_markers = os.clock () + 1 SendEntityMessage(self.model, "hide_markers", nil, 1000) end function object:UpdateMatrix() self:ShowMarkers() end function object:UnlockKeys() self:ShowMarkers() end function object:Free(model) RemoveHook("Flip", object.Render) self.super:Free() end object:Init() end 1 Quote Link to comment Share on other sites More sharing options...
Roland Posted December 21, 2012 Author Share Posted December 21, 2012 Great. Exactly what i need. Does not have to be exactly a ring. Many thank's Quote Roland Strålberg Website: https://rstralberg.com Link to comment Share on other sites More sharing options...
Daimour Posted December 21, 2012 Share Posted December 21, 2012 You can try to add this code to class.lua script. So it will work for all entities on the scene. If they have attached script with: local class=CreateClass(...) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.