Jump to content

Coronas and View distance (blinky radio tower beacons)


Flexman
 Share

Recommended Posts

This LUA code is used with one of the Dexsoft radio tower models. It adds three lights and makes the top one blink at a specified interval and colour.

 

But the view range isn't all that great. I was going to ask for suggestions for setting the Corona view range as I tried Lua: entity:SetViewRange( near, far, recursive ) as per the Wiki but only got an error. However the following worked:

 

EntityViewRange(entity.antennalight[i],800,1000)

 

 

Here's the full script if interested.

 

 


dofile("Scripts/base.lua")


function InitDialog(grid)
base_InitDialog(grid)

--custom properties
group=grid:AddGroup( "Beacon" )
group:AddProperty( "blinkspeed",PROPERTY_INTEGER,1000,"Blink Speed")
group:AddProperty("beaconcolor",PROPERTY_COLOR,"","Beacon Color")
group:Expand(1)

end

function Spawn(model)
local entity=base_Spawn(model)
entity.antennalight={}
entity.blinkspeed = tonumber(model:GetKey("blinkspeed","1000"))
entity.beaconcolor = Vec4(1.0,0,0,1)
entity.lasttime = AppTime()
entity.blinktoggle = 1

for i=0,2 do
	entity.antennalight[i] = CreateCorona(model)
	entity.antennalight[i]:Paint(LoadMaterial("abstract::flare1.mat"),1)
	entity.antennalight[i]:SetParent(model,0)
	entity.antennalight[i]:SetColor(entity.beaconcolor,0)
	SetCoronaRadius(entity.antennalight[i],1,1)
	EntityViewRange(entity.antennalight[i],800,1000)

end

-- Fixed light positions on our antenna
entity.antennalight[0]:SetPosition(Vec3(0,35,0.1),0)
entity.antennalight[1]:SetPosition(Vec3(1.5,25.2,0.1),0)
entity.antennalight[2]:SetPosition(Vec3(-1.5,25.2,0.1),0)


base_SetKey("collisiontype",COLLISION_PROP)

--An update function for one instance.  Declaring the function as part of the entity table allows us to use "self" for the table
function entity:Update()

	if (AppTime()-self.lasttime>entity.blinkspeed) then
		self.lasttime = AppTime()
		self.blinktoggle = -self.blinktoggle
		if (self.blinktoggle>0) then
			self.antennalight[0]:Hide()
		else
			self.antennalight[0]:Show()
		end
	end

end


end

function SetKey(model, key, value)
local entity=entitytable[model]
if entity==nil then return 1 end
if entity.model==nil then return 1 end
if key=="blinkspeed" then
	entity.blinkspeed = tonumber(value)
elseif key=="beaconcolor" then
	entity.beaconcolor=StringToColor(value)
	entity.beaconcolor.w = 1
	entity.antennalight[0]:SetColor(entity.beaconcolor,0)
	entity.antennalight[1]:SetColor(entity.beaconcolor,0)
	entity.antennalight[2]:SetColor(entity.beaconcolor,0)
end
return 1
end


--Update function, called during every UpdateWorld()
function Update(world)
if world==world_main then
	local model,entity
	for model,entity in pairs(entitytable) do
		if model.world==world then
			entity:Update()
		end
	end
    end
end

6600 2.4G / GTX 460 280.26 / 4GB Windows 7

Author: GROME Terrain Modeling for Unity, UDK, Ogre3D from PackT

Tricubic Studios Ltd. ~ Combat Helo

Link to comment
Share on other sites

Hi,

 

Did anyone work out how to cut and paste code from the forum? I just get one line no matter where I paste to... :)

 

Robin

Programmer , Intel Quad core, NVIDIA GeForce GT 220, Windows 7 Pro, Galaxy Tab 2 ( 7" and 10"), LE2,LE3,3DWS

Link to comment
Share on other sites

Hi,

 

Did anyone work out how to cut and paste code from the forum? I just get one line no matter where I paste to... :)

 

Robin

 

 

I use wordpad.

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

I get...

 

dofile("Scripts/base.lua")function InitDialog(grid)        base_InitDialog(grid)                --custom properties        group=grid:AddGroup( "Beacon" )        group:AddProperty( "blinkspeed",PROPERTY_INTEGER,1000,"Blink Speed")        group:AddProperty("beaconcolor",PROPERTY_COLOR,"","Beacon Color")        group:Expand(1)endfunction Spawn(model)        local entity=base_Spawn(model)        entity.antennalight={}        entity.blinkspeed = tonumber(model:GetKey("blinkspeed","1000"))        entity.beaconcolor = Vec4(1.0,0,0,1)        entity.lasttime = AppTime()        entity.blinktoggle = 1        for i=0,2 do                entity.antennalight[i] = CreateCorona(model)                entity.antennalight[i]:Paint(LoadMaterial("abstract::flare1.mat"),1)                entity.antennalight[i]:SetParent(model,0)                entity.antennalight[i]:SetColor(entity.beaconcolor,0)                SetCoronaRadius(entity.antennalight[i],1,1)                EntityViewRange(entity.antennalight[i],800,1000)        end        -- Fixed light positions on our antenna        entity.antennalight[0]:SetPosition(Vec3(0,35,0.1),0)        entity.antennalight[1]:SetPosition(Vec3(1.5,25.2,0.1),0)        entity.antennalight[2]:SetPosition(Vec3(-1.5,25.2,0.1),0)        base_SetKey("collisiontype",COLLISION_PROP)        --An update function for one instance.  Declaring the function as part of the entity table allows us to use "self" for the table        function entity:Update()                                if (AppTime()-self.lasttime>entity.blinkspeed) then                        self.lasttime = AppTime()                        self.blinktoggle = -self.blinktoggle                        if (self.blinktoggle>0) then                                self.antennalight[0]:Hide()                        else                                self.antennalight[0]:Show()                        end                end        endendfunction SetKey(model, key, value)        local entity=entitytable[model]        if entity==nil then return 1 end        if entity.model==nil then return 1 end        if key=="blinkspeed" then                entity.blinkspeed = tonumber(value)        elseif key=="beaconcolor" then                entity.beaconcolor=StringToColor(value)                entity.beaconcolor.w = 1                entity.antennalight[0]:SetColor(entity.beaconcolor,0)                entity.antennalight[1]:SetColor(entity.beaconcolor,0)                entity.antennalight[2]:SetColor(entity.beaconcolor,0)        end        return 1end--Update function, called during every UpdateWorld()function Update(world)        if world==world_main then                local model,entity                for model,entity in pairs(entitytable) do                        if model.world==world then                                entity:Update()                        end                end     endend

 

Robin

Programmer , Intel Quad core, NVIDIA GeForce GT 220, Windows 7 Pro, Galaxy Tab 2 ( 7" and 10"), LE2,LE3,3DWS

Link to comment
Share on other sites

Maybe paste it into a different editor? I highly recommend Notepad++ from http://notepad-plus.sourceforge.net/uk/site.htm

Small footprint, versatile and free. Never had a problem pasting code.

 

But what I will do, is make the above code available as a download in the...downloads...section.

6600 2.4G / GTX 460 280.26 / 4GB Windows 7

Author: GROME Terrain Modeling for Unity, UDK, Ogre3D from PackT

Tricubic Studios Ltd. ~ Combat Helo

Link to comment
Share on other sites

Notepad++ gives me...

 

dofile("Scripts/base.lua")function InitDialog(grid)        base_InitDialog(grid)                --custom properties        group=grid:AddGroup( "Beacon" )        group:AddProperty( "blinkspeed",PROPERTY_INTEGER,1000,"Blink Speed")        group:AddProperty("beaconcolor",PROPERTY_COLOR,"","Beacon Color")        group:Expand(1)endfunction Spawn(model)        local entity=base_Spawn(model)        entity.antennalight={}        entity.blinkspeed = tonumber(model:GetKey("blinkspeed","1000"))        entity.beaconcolor = Vec4(1.0,0,0,1)        entity.lasttime = AppTime()        entity.blinktoggle = 1        for i=0,2 do                entity.antennalight[i] = CreateCorona(model)                entity.antennalight[i]:Paint(LoadMaterial("abstract::flare1.mat"),1)                entity.antennalight[i]:SetParent(model,0)                entity.antennalight[i]:SetColor(entity.beaconcolor,0)                SetCoronaRadius(entity.antennalight[i],1,1)                EntityViewRange(entity.antennalight[i],800,1000)        end        -- Fixed light positions on our antenna        entity.antennalight[0]:SetPosition(Vec3(0,35,0.1),0)        entity.antennalight[1]:SetPosition(Vec3(1.5,25.2,0.1),0)        entity.antennalight[2]:SetPosition(Vec3(-1.5,25.2,0.1),0)        base_SetKey("collisiontype",COLLISION_PROP)        --An update function for one instance.  Declaring the function as part of the entity table allows us to use "self" for the table        function entity:Update()                                if (AppTime()-self.lasttime>entity.blinkspeed) then                        self.lasttime = AppTime()                        self.blinktoggle = -self.blinktoggle                        if (self.blinktoggle>0) then                                self.antennalight[0]:Hide()                        else                                self.antennalight[0]:Show()                        end                end        endendfunction SetKey(model, key, value)        local entity=entitytable[model]        if entity==nil then return 1 end        if entity.model==nil then return 1 end        if key=="blinkspeed" then                entity.blinkspeed = tonumber(value)        elseif key=="beaconcolor" then                entity.beaconcolor=StringToColor(value)                entity.beaconcolor.w = 1                entity.antennalight[0]:SetColor(entity.beaconcolor,0)                entity.antennalight[1]:SetColor(entity.beaconcolor,0)                entity.antennalight[2]:SetColor(entity.beaconcolor,0)        end        return 1end--Update function, called during every UpdateWorld()function Update(world)        if world==world_main then                local model,entity                for model,entity in pairs(entitytable) do                        if model.world==world then                                entity:Update()                        end                end     endend

 

Nice looking editor though :mellow:

 

Robin

Programmer , Intel Quad core, NVIDIA GeForce GT 220, Windows 7 Pro, Galaxy Tab 2 ( 7" and 10"), LE2,LE3,3DWS

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...