Need help with my roller-baller script, which I want to introduce to everybody. It is absolutely free and can be used for any purpose without any fee.
This is a script, which can be useful for creating some kind of light cirquits. Take a look on working example. There are two light cirquits in this demo. They are very simple but show what my script can do. First of all I want to mention that I used several threads on forum to get some info and these are the links.
Information about visibility
Entity name parser
Light control
Light Cirquit Script as i call it has two parts: entity script and light cirquits switch. Look at the picture how it looks like in editor.
Prepared scene with two light cirquits
You can see many lights on the picture: 3 red decals, 7 blue decals, 1 orange light source, 3 blue light sources, but red lights not active, only blue lights play role of cirquit parts.
The term curquit means group of lights that can be held separately by the script. Ideally, the script can program the behaviour of lights easily in one string. So each light itself is just a part of cirquit one. Nevertheless, lights can be combined in parts of cirquits to become equal between each other. In my example, the first cirquit has one part, which consists of 4 elements: 3 blue decals and blue light source, and the second cirquit has two independent parts with 3 elements in every part: 2 blue decals and 1 blue light source.
To setup each cirquit you need to place lights and give the right names to them. The syntax for naming is very simple, but it must be used without any mistakes or spaces. It's a pity, but my try to use string.match function like i saw in Barrel example leads to errors. So, all numbers in name are to have single digits, because i used string.sub function. The name of single light is to be as following:
Light Cirquit:-=Cirquit Number=- -=Cirquit Part Number=- -=Single Entity Number in Part=- -=Light Flag "l"=-
For example: "Light Cirquit:1 2 1", or "Light Cirquit:2 1 2", or "Light Cirquit:2 1 2 l"
Pay an attention to letter "l" in the third example name. It is very important, because it is used respawn lights in separate way from decals.
So, here is the result of many hours.
Light Cirquit Script in action
To program the cirquit you need to set the value "interval" into _init function of light cirquit switch.
And here it is Light Cirquit Script as is:
1. Entity script (must applied to each single entity without change, entity is to be in "No static" mode)
-- LUA Script - precede every function and global member with lowercase name of script + '_main'
function light_cirquit_init_name(e,name)
local there
local num
local lcarr_num
local lcparr_num
local lcearr_num
light_entity_name[e]=name
-- light cirquit number
local numpos=string.find(name,":")+1;
local lc_num = string.sub(name,numpos,numpos)
-- search FIRST index - light cirquit
there=0
for num=0,lc_amount,1 do
if light_cirquit_num[num]==lc_num then
lcarr_num=num
there=1
end
end
if there==0 then
light_cirquit_num[lc_amount]=lc_num
-- lcp_amount - light cirquit part amount
lcp_amount[lc_amount] = 0
lcarr_num=lc_amount
light_cirquit_part_num[lcarr_num]= {}
light_entity_part_num[lcarr_num]={}
lcse_amount[lcarr_num]={}
light_entity[light_cirquit_num[lcarr_num]]={}
is_game_guru_light_entity[light_cirquit_num[lcarr_num]]={}
lcse_visibility[light_cirquit_num[lcarr_num]]={}
lc_amount=lc_amount+1
end
numpos=numpos+2
local lc_part_num = string.sub(name,numpos,numpos)
-- search SECOND index - light cirquit part
there=0
for num=0,lcp_amount[lcarr_num],1 do
if light_cirquit_part_num[lcarr_num][num]==lc_part_num then
lcparr_num=num
there=1
end
end
if there==0 then
light_cirquit_part_num[lcarr_num][lcp_amount[lcarr_num]]=lc_part_num
-- lcse_amount - light cirquit single entity amount
lcse_amount[lcarr_num][lcp_amount[lcarr_num]] = 0
lcparr_num=lcp_amount[lcarr_num]
light_entity_part_num[lcarr_num][lcparr_num]= {}
light_entity[light_cirquit_num[lcarr_num]][light_cirquit_part_num[lcarr_num][lcparr_num]]={}
is_game_guru_light_entity[light_cirquit_num[lcarr_num]][light_cirquit_part_num[lcarr_num][lcparr_num]]={}
lcse_visibility[light_cirquit_num[lcarr_num]][light_cirquit_part_num[lcarr_num][lcparr_num]]={}
lcp_amount[lcarr_num]=lcp_amount[lcarr_num]+1
end
numpos=numpos+2
local lc_ent_num = string.sub(name,numpos,numpos)
numpos=numpos+2
local is_game_guru_light = string.sub(name,numpos,numpos)
-- search THIRD index - light cirquit part
there=0
for num=0,lcse_amount[lcarr_num][lcparr_num],1 do
if light_entity_part_num[lcarr_num][lcparr_num][num]==lc_ent_num then
lcearr_num=num
there=1
end
end
if there==0 then
light_entity_part_num[lcarr_num][lcparr_num][lcse_amount[lcarr_num][lcparr_num]]=lc_ent_num
lcearr_num=lcse_amount[lcarr_num][lcparr_num]
light_entity[light_cirquit_num[lcarr_num]][light_cirquit_part_num[lcarr_num][lcparr_num]][light_entity_part_num[lcarr_num][lcparr_num][lcearr_num]]=e
lcse_visibility[light_cirquit_num[lcarr_num]][light_cirquit_part_num[lcarr_num][lcparr_num]][light_entity_part_num[lcarr_num][lcparr_num][lcearr_num]]=1
if is_game_guru_light=='l' then
is_game_guru_light_entity[light_cirquit_num[lcarr_num]][light_cirquit_part_num[lcarr_num][lcparr_num]][light_entity_part_num[lcarr_num][lcparr_num][lcearr_num]]=1
else
is_game_guru_light_entity[light_cirquit_num[lcarr_num]][light_cirquit_part_num[lcarr_num][lcparr_num]][light_entity_part_num[lcarr_num][lcparr_num][lcearr_num]]=0
end
-- light_entity[light_cirquit_num[lcarr_num]][light_cirquit_part_num[lcarr_num][lcparr_num]][light_entity_part_num[lcarr_num][lcparr_num][lcearr_num]]=e
-- lcse_amount - light cirquit single entity amount
lcse_amount[lcarr_num][lcparr_num]=lcse_amount[lcarr_num][lcparr_num]+1
end
end
function light_cirquit_main(e)
RotateToCamera(e)
end
2. Main Light Switch (must be applied one time to any asset in "No static mode")
-- LUA Script - precede every function and global member with lowercase name of script + '_main'
light_entity_name = {}
light_cirquit_num = {}
light_cirquit_part_num = {}
light_cirquit_part_amount = {}
light_entity_part_num = {}
light_entity_part_amount = {}
light_entity = {}
is_game_guru_light_entity = {}
light_params = {}
light_timer = {}
lights = {}
lc_amount = 0
lcp_amount = {}
-- light cirquit single entity
lcse_amount = {}
light_timer[0]=0
empty = {}
lc_settings = {}
lc_timer = {}
lc_onoff_status = {}
-- light cirquit single entity visibility status array
lcse_visibility = {}
function level1_lightswitch_init(e)
local num
lc_settings[1]= { interval=150 }
lc_settings[2]= { interval=60 }
for num=0,100,1 do
lc_timer[num]=0
lc_onoff_status[num]=0
end
end
function level1_lightswitch_main(e)
local num
local num2
local str_num=2
Text(2,2,3,"Number of light cirquits found: " .. #light_cirquit_num+1);
for num=0,#light_cirquit_num,1 do
str_num=str_num+3
Text(2,str_num,3,"Number of parts in cirquit #" .. num+1 .. ":" .. lcp_amount[num]);
if lc_timer[num]<lc_settings[num+1].interval then
lc_timer[num]=lc_timer[num]+1
else
for num2=0,#light_cirquit_part_num[num],1 do
for num3=0,#light_entity_part_num[num][num2],1 do
local entityname="Light Cirquit:" .. num+1 .. " " .. num2+1 .. " " .. num3+1
str_num=str_num+3
local entitynum = light_entity[light_cirquit_num[num]][light_cirquit_part_num[num][num2]][light_entity_part_num[num][num2][num3]]
Text(2,str_num,3,"Name of entity #" .. num3+1 .. ":" .. entityname .. " Entity Number: " .. entitynum);
if(lc_onoff_status[num]==num2) then
if(#light_cirquit_part_num[num]>0) then
if is_game_guru_light_entity[light_cirquit_num[num]][light_cirquit_part_num[num][num2]][light_entity_part_num[num][num2][num3]]==0 then
Hide(entitynum);
else
HideLight(entitynum);
end
if(lc_onoff_status[num]==#light_cirquit_part_num[num]) then
num2_next=0
else
num2_next=lc_onoff_status[num]+1
end
local entitynum2 = light_entity[light_cirquit_num[num]][light_cirquit_part_num[num][num2_next]][light_entity_part_num[num][num2_next][num3]]
if is_game_guru_light_entity[light_cirquit_num[num]][light_cirquit_part_num[num][num2_next]][light_entity_part_num[num][num2_next][num3]]==0 then
Show(entitynum2);
else
ShowLight(entitynum2);
end
else
if lcse_visibility[light_cirquit_num[num]][light_cirquit_part_num[num][num2]][light_entity_part_num[num][num2][num3]]==0 then
if is_game_guru_light_entity[light_cirquit_num[num]][light_cirquit_part_num[num][num2]][light_entity_part_num[num][num2][num3]]==0 then
Hide(entitynum);
else
HideLight(entitynum);
end
lcse_visibility[light_cirquit_num[num]][light_cirquit_part_num[num][num2]][light_entity_part_num[num][num2][num3]]=1
else
if is_game_guru_light_entity[light_cirquit_num[num]][light_cirquit_part_num[num][num2]][light_entity_part_num[num][num2][num3]]==0 then
Show(entitynum);
else
ShowLight(entitynum);
end
lcse_visibility[light_cirquit_num[num]][light_cirquit_part_num[num][num2]][light_entity_part_num[num][num2][num3]]=0
end
end
end
end
end
if(lc_onoff_status[num]==#light_cirquit_part_num[num]) then
lc_onoff_status[num]=0
else
lc_onoff_status[num]=lc_onoff_status[num]+1
end
lc_timer[num]=0
end
end
end
To program you need to change Main Light Switch Script like below:
lc_settings[1]= { interval=150 }
lc_settings[2]= { interval=60 }
These settings are for my example. I created two cirquits, so i was to write two setting strings with separate interval. And the numbers in index of array lc_settings must correspond to the first number in entity's name, because it means light cirquit number.
If you have comments, feel free to post it. I will be glad to read any answers.