#==================================================================================# #Scriptname: cruise_Trafficlight.LPR #Author: Bass-Driver #Version: 1.0.12 #VersionDate: 07-12-2019 #Description: ###1.0.0 # -Initial Release ###1.0.1 # -Changed: Playervar "Cash" change to "TotalCash" # -Add: GlobalVar Versionnumber # -Fix: Input Statenumber of light could be higher than 3. ###1.0.2 # -Add: Blinking yellow light when Intersection is disabled. # -Fix: Empty values when changing type intersection # -Fix: Spamming last IntersectionFile with values from non existing Intersections. # -Fix: Saving Intersection with no TrafficLight info # -Delete:Light Sequence ###1.0.3 # -Changed: Name of Globalvar for saving files ###1.0.4 # -Changed: Disabled TrafficLightFolder GlobalVar (This is assigned in includes\cruise\cruise_configurations\cruise_directories.LPR) ###1.0.5 # -Fix: Minimum greenlight message stuck at 2 seconds, even when input is higher than 2. # -Fix: Loop stopped working after creating a new intersection. ###1.0.6 # -Fix: $Speedlimit var was already used , is now $PlySpeedLimit # -Fix: Kmh or Mph var was wrong. # -Fix: Speedcam wasnt enabled in ManualMode ###1.0.7 # -Add: Reload trafficlight loop command # -Change: Camera OFF as default setting for creating new lights. # -Fix: Could enable intersection without any lights. # -Fix: Non-Admins could execute commands ###1.0.8 # -Changed: Parameters of LoadNotification(); changed. ###1.0.9 # -Update: Buttonstate 'Add Trafficlight' # -Fix: Couldnt load saved intersections # -Fix: Typo's ###1.0.10 # -Add: Variable to change Yellowlight Time # -Change: Fine for running redlight # -Change: Fine for speeding # -Change: Text for speeding and for running a red light # -Fix: Got fined at the wrong speed ###1.0.11 # -Add: Delay between LFSCommand and atcual redlight status # -Change: RedLight flash and notications to the cop: > BLAH ran a redlight on "Street" intersection! # -Fix: Couldnt select insimcircle ID number 10 ###1.0.12 # -Change: Global Sub callback for insim cashflow system. #SetCash(); #==================================================================================# CatchEvent OnLapperStart() #GlobalVar $TrafficLightFolder; $TrafficLightFolder = "C:\Users\Danny\Desktop\SavedTrafficLights"; GlobalVar $TrafficlightVersion; $TrafficlightVersion = "1.0.12"; #Array GlobalVar $LightStatus; GlobalVar $InterSections; GlobalVar $MainTrafficLoop; $MainTrafficLoop = TRUE; GlobalVar $DefaultGreenTime; $DefaultGreenTime = 6; GlobalVar $RedLightSendToLFS; $RedLightSendToLFS = 0; GlobalVar $RedLightDelayTime; $RedLightDelayTime = 1; GlobalVar $RedLightDelayCounter; $RedLightDelayCounter = 0; GlobalVar $SpeedLimit; $SpeedLimit = 60; # Global Speedlimit @ 60 km/h GlobalVar $EnableRedLightFine; $EnableRedLightFine = 0; #Vars for array GlobalVar $NrOfInterSection; GlobalVar $TypeInterSections; GlobalVar $NRofLightsOnInterSection; GlobalVar $NRofLight; GlobalVar $RedLightFine; $RedLightFine = 150; GlobalVar $SpeedingFine; $SpeedingFine = "2.20"; #per km $NrOfInterSection = 0; $NRofLight = 0; $TypeInterSections[1] = "Cross-Intersection"; $TypeInterSections[2] = "T-InterSection"; $TypeInterSections[3] = "Roundabout"; $TypeInterSections[4] = "Pedestrian-Crossing"; $TypeInterSections[5] = "Other-Intersections"; $NRofLightsOnInterSection[$TypeInterSections[1]] = 4.""; $NRofLightsOnInterSection[$TypeInterSections[2]] = 3.""; $NRofLightsOnInterSection[$TypeInterSections[3]] = 4.""; $NRofLightsOnInterSection[$TypeInterSections[4]] = 2.""; $NRofLightsOnInterSection[$TypeInterSections[5]] = 4.""; $InterSections[ $NrOfInterSection,"Active"] = 0.""; #Intersection is active and in use $InterSections[ $NrOfInterSection,"Name"] = ""; #Name of Intersection $InterSections[ $NrOfInterSection,"Type" ] = $TypeInterSections[1].""; #4 way/ 3 way / 2 way intersections. (calculate in list how many lights are needed) $InterSections[ $NrOfInterSection,"ManyLights"] = 0.""; #HowManyLights $InterSections[ $NrOfInterSection,"Control" ] = 1.""; #Manual/AutoMatic $InterSections[ $NrOfInterSection,$NRofLight,"LightID" ] = 0.""; #LightID $InterSections[ $NrOfInterSection,$NRofLight,"GreenTime" ] = 10.""; #Individual GreenTime LightID $InterSections[ $NrOfInterSection,$NRofLight,"GreenTimeCounter" ] = 0.""; #Individual GreenTime LightID $InterSections[ $NrOfInterSection,$NRofLight,"YellowLightTime" ] = 4.""; #Individual Yellow LightID $InterSections[ $NrOfInterSection,$NRofLight,"YellowLightCounter" ] = 4.""; #Individual YellowTime LightID $InterSections[ $NrOfInterSection,$NRofLight,"InsimCircle" ] = -1.""; #InSimCircle ( for Camera) $InterSections[ $NrOfInterSection,$NRofLight,"State" ] = 1.""; #State of light $InterSections[ $NrOfInterSection,$NRofLight,"Camera" ] = 0.""; #Camera Set TrafficLoop(); EndCatchEvent CatchEvent OnMSO( $userName, $text ) # Player event $idxOfFirtsSpace = indexOf( $text, " "); IF( $idxOfFirtsSpace == -1 ) THEN $command = $text; $argv = ""; ELSE $command = subStr( $text,0,$idxOfFirtsSpace ); $argv = trim( subStr( $text,$idxOfFirtsSpace ) ); ENDIF SWITCH( $command ) CASE "!trafficlight": IF ( UserIsAdmin( $userName ) == 1 ) THEN SetInterSections($userName); ELSE privmsg("^1Insufficient privileges!"); ENDIF BREAK; CASE "!resettrafficloop": IF ( UserIsAdmin( $userName ) == 1 ) THEN TrafficLoop(); ELSE privmsg("^1Insufficient privileges!"); ENDIF BREAK; ENDSWITCH EndCatchEvent CatchEvent OnConnect($userName) IF($userName != "") THEN #Chase INIT SetPlayerVar($userName, "DrivenToTrafficLightID", 0); SetPlayerVar($userName, "InterSection", 0); SetPlayerVar($userName, "NrOfLight", 0); SetPlayerVar($userName, "InChase",0); ENDIF EndCatchEvent CatchEvent OnCrossingChecker($userName,$Flags,$Time,$Object,$UserSpeed,$CircleIndex) # Player event #Set approached TrafficLight ID to player By Insim Circle IF ($Object == "Checker") THEN IF ((GetPlayerVar($userName, "DrivenToTrafficLightID") == 0) && ($CircleIndex >= 0)) THEN FOR($i = 1 ; $i < ToNum($NrOfInterSection)+1; $i = $i + 1) IF($InterSections[ ToNum($i),"Active"] == 1) THEN #Check is Intersection is set in AutomaticMode #Check how many light are set for the current intersection IF($InterSections[ ToNum($i),"ManyLights"] > 0) THEN #Check how many light are set for the current intersection FOR($NRofLight = 1; $NRofLight < ToNum($InterSections[ ToNum($i),"ManyLights"])+1; $NRofLight = $NRofLight + 1) IF($CircleIndex == ToNum($InterSections[ ToNum($i),$NRofLight,"InsimCircle" ])) THEN #Set LightID to playerVar SetPlayerVar($userName, "InterSection", $i); SetPlayerVar($userName, "NrOfLight", $NRofLight); SetPlayerVar($userName, "DrivenToTrafficLightID", $InterSections[ ToNum($i),$NRofLight,"LightID" ]); ENDIF ENDFOR ENDIF ENDIF ENDFOR ENDIF ELSE #Stopline = Insim Finishline IF ($Object == "Finish line") THEN $PlyLightID = GetPlayerVar($userName, "DrivenToTrafficLightID"); $Intersect = GetPlayerVar($userName, "InterSection"); $Light = GetPlayerVar($userName, "NrOfLight"); $PlySpeedLimit = $SpeedLimit; $StateOfCurrentLight = ToNum($InterSections[ ToNum($Intersect),ToNum($Light),"State" ]); #Intersection is Active IF($InterSections[ ToNum($Intersect),"Active"] == 1) THEN #Camera is turned on/off IF($InterSections[ ToNum($Intersect),ToNum($Light),"Camera"] == 1) THEN IF( $PlyLightID > 0) THEN #Light is Red globalmsg($PlyLightID); IF ( $StateOfCurrentLight == 1) THEN OpenPrivButton("RadarFlash",0,0,200,200,8,1,16,""); Globalmsg("".GetPlayerVar($userName, "NickName")." ^1RAN A RED LIGHT!"); #Send notifications to cop #Notification to Cops ################################### #Your Code here ################################### IF($EnableRedLightFine == 1) THEN privmsg("^0================================"); privmsg("^3RedLight Fine: ^7€".$RedLightFine); privmsg("^0================================"); #Global CashFlow System ################################### #YOUR MONEYSYSTEM HERE ################################### ENDIF ENDIF #Light is Amber or Green IF (($StateOfCurrentLight == 2)||($StateOfCurrentLight == 3)) THEN IF( ToNum(GetPlayerVar($userName,"InstantSpeed" )) > ToNum($PlySpeedLimit)) THEN $speeddiff = GetPlayerVar($userName,"InstantSpeed" ) - $PlySpeedLimit); $SpeedFine = ToNum($SpeedingFine * $speeddiff ); #MESSAGE OpenPrivButton("RadarFlash",0,0,200,200,8,1,16,""); privmsg("^0================================"); privmsg("^3You have been caught for speeding!!"); IF (GetPlayerVar($userName,"UnitSpeedKmh") == 1) THEN privmsg("^7Your Speed: ^3".Round(GetPlayerVar($userName,"InstantSpeed"),0)." ^7km/h ^0/ ^7".$PlySpeedLimit." km/h"); ELSE privmsg("^7Your Speed: ^3".Round(GetPlayerVar($userName,"InstantSpeed")*0.6214,0)." ^7mph ^0/ ^7".Round($PlySpeedLimit*0.6214,0)." mph"); ENDIF privmsg("^3Fine: ^7€".Round($SpeedFine,2); privmsg("^0================================"); #Global CashFlow System ################################### #YOUR MONEYSYSTEM HERE ################################### ENDIF ENDIF ENDIF ENDIF ENDIF #Reset Playervars because driver is in a chase. SetPlayerVar($userName, "DrivenToTrafficLightID", 0); SetPlayerVar($userName, "InterSection", 0); SetPlayerVar($userName, "NrOfLight", 0); ENDIF ENDIF EndCatchEvent Sub SetInterSections($userName) $sipos_hgt = 40; $sipos_wdt = 50; OpenButton( $userName,"SI_Title",$sipos_wdt,$sipos_hgt,100,5,8,-1,80,"^2» ^7Set InterSections / Trafficlights"); OpenButton( $userName,"SI_Closebutton",$sipos_wdt+95,$sipos_hgt,5,5,8,-1,0,"^0[^1X^0]",CloseSetinterSections); OpenTextButton( $userName,"SI_CreateInter",$sipos_wdt+,$sipos_hgt+6,25,5,8,32,"Enter name","^3Create a Intersection",30,CreateIntersection); OpenButton( $userName,"SI_LoadInter",$sipos_wdt+25,$sipos_hgt+6,25,5,5,-1,32,"^6Load Intersections",LoadIntersection); OpenTextButton( $userName,"SI_SaveInter",$sipos_wdt+50,$sipos_hgt+6,25,5,5,32,"^0Your sure you want to save this list? (Y/N)","^2Save Intersections",1,SaveList); #First Row OpenButton( $userName,"SI_FR_Nr",$sipos_wdt,$sipos_hgt+12,6,4,4,-1,16,"^7Nr"); OpenButton( $userName,"SI_FR_Name",$sipos_wdt+6,$sipos_hgt+12,23,4,4,-1,80,"^7Name of Intersection"); OpenButton( $userName,"SI_FR_Type",$sipos_wdt+29,$sipos_hgt+12,22,4,4,-1,80,"^7Type of Intersection"); OpenButton( $userName,"SI_FR_Lights",$sipos_wdt+51,$sipos_hgt+12,10,4,4,-1,16,"^7Lights"); OpenButton( $userName,"SI_FR_GreenTime",$sipos_wdt+61,$sipos_hgt+12,14,4,4,-1,16,"^7Auto Control"); OpenButton( $userName,"SI_FR_Active",$sipos_wdt+75,$sipos_hgt+12,10,4,4,-1,16,"^7Enabled"); OpenButton( $userName,"SI_FR_Info",$sipos_wdt+85,$sipos_hgt+12,15,4,4,-1,80,""); $CloseSetInterSection = "SI_Title&SI_Closebutton&SI_CreateInter"; SetPlayerVar($userName,"CloseSetInter",$CloseSetInterSection); DisplayInterSectionList($userName); EndSub #=========================================== #Save/Load Intersections #=========================================== Sub SaveList($ID,$argv) IF ($argv == "Y") THEN FOR($Nr = 1; $Nr < ToNum($NrOfInterSection)+1 ;$Nr=$Nr+1) IF($InterSections[ ToNum($Nr),"Name"] != "") THEN $File = "".GetLapperVar("ShortTrackName")."_".$InterSections[ ToNum($Nr),"Name"]; CreateFile( $File,$TrafficLightFolder,1); ENDIF ENDFOR Delayedcommand("SaveListT",2,SaveListTwo); ENDIF EndSub Sub SaveListTwo() $SaveOk = 1; FOR($Nr = 1; $Nr < ToNum($NrOfInterSection)+1 ;$Nr=$Nr+1) IF($InterSections[ ToNum($Nr),"Name"] != "") THEN $File = "".GetLapperVar("ShortTrackName")."_".$InterSections[ ToNum($Nr),"Name"]; $SaveTrafficLight[10] = "Name:".$InterSections[ ToNum($Nr),"Name"].""; $SaveTrafficLight[11] = "Lights:".$InterSections[ ToNum($Nr),"ManyLights"].""; $SaveTrafficLight[12] = "Type:".$InterSections[ ToNum($Nr),"Type"].""; $SaveTrafficLight[13] = "AutoControl:".$InterSections[ ToNum($Nr),"Control"].""; $SaveTrafficLight[14] = "Enabled:".$InterSections[ ToNum($Nr),"Active"].""; FOR($Nra = 15; $Nra < 19 ;$Nra=$Nra+1) $LightID = $InterSections[ ToNum($Nr),ToNum($Nra-15),"LightID" ]; #Indentifier of the light. $InsimCircle = $InterSections[ ToNum($Nr),ToNum($Nra-15),"InsimCircle" ]; #-1 if no insim circle has been set $StateOfLight = $InterSections[ ToNum($Nr),ToNum($Nra-15),"State" ]; #Red/Yellow/Green/Off (blinking yellow) $SetCamera = $InterSections[ ToNum($Nr),ToNum($Nra-15),"Camera" ]; #Set Speed/RedLight camera on current light (1 = on / 0 = off) $GreenTime = $InterSections[ ToNum($Nr),ToNum($Nra-15),"GreenTime" ]; #Set Invididual GreenTime IF(($LightID == "")||($InsimCircle == "")||($StateOfLight == "")||($SetCamera == "")||($GreenTime == ""))THEN $SaveOk = 0; globalmsg("^1ERROR: ^7Storing Trafficlight data for intersection: ^3".$InterSections[ ToNum($Nr),"Name"]); ENDIF $SaveTrafficLight[$Nra] = "LIGHT".$Nra-14.":".$LightID."|".$InsimCircle."|".$StateOfLight."|".$SetCamera."|".$GreenTime.""; ENDFOR IF ($SaveOk == 1) THEN FOR($arraynr = 10; $arraynr < 21 ;$arraynr=$arraynr+1) $Text = $SaveTrafficLight[ToNum($arraynr)]; EditFile( $File,$TrafficLightFolder,$Text,-1,".txt"); ENDFOR globalmsg("^2Successfull: ^7Storing Trafficlight data for intersection: ^3".$InterSections[ ToNum($Nr),"Name"]); ENDIF ENDIF ENDFOR EndSub Sub LoadIntersection($keyflags,$id) #Set init Vars $userName = GetCurrentPlayerVar("UserName"); $ListOfInterFiles = getlistoffiles($TrafficLightFolder); #GlobalVar $NrOfFiles = $ListOfInterFiles["NumberOfFiles"]; $CurrTrack = GetLapperVar("ShortTrackName"); $NrOfInterSection = 1; FOR($Nr = 1; $Nr < ToNum($NrOfFiles+1) ;$Nr=$Nr+1) $FileNamee = $ListOfInterFiles[$Nr,"FileName"]; $GetTrackName = SplitToArray($FileNamee,"_"); IF($GetTrackName[0] == $CurrTrack) THEN $NewFileName = substr( $FileNamee,0,StrLen($FileNamee)-4); $LinesofFile = Readfile($NewFileName,$TrafficLightFolder,".txt"); #########Get Intersection Settings######## $IntName = SplitToArray($LinesofFile[0,"Line"],":"); $IntNrOfLights = SplitToArray($LinesofFile[1,"Line"],":"); $IntType = SplitToArray($LinesofFile[2,"Line"],":"); $IntControl = SplitToArray($LinesofFile[3,"Line"],":"); $IntEnabled = SplitToArray($LinesofFile[4,"Line"],":"); #########Set Arrays's######### $InterSections[ ToNum($NrOfInterSection),"Name"] = $IntName[1].""; #Name of Intersection $InterSections[ ToNum($NrOfInterSection),"ManyLights"] = $IntNrOfLights[1].""; $InterSections[ ToNum($NrOfInterSection),"Type"] = $IntType[1].""; $InterSections[ ToNum($NrOfInterSection),"Control"] = $IntControl[1].""; $InterSections[ ToNum($NrOfInterSection),"Active"] = $IntEnabled[1].""; #########Get Light Settings######## FOR($NrLight = 5; $NrLight < 10 ;$NrLight=$NrLight+1) $IntLightGet = SplitToArray($LinesofFile[ToNum($NrLight),"Line"],":"); $IntLightGet_B = SplitToArray($IntLightGet[1],"|"); $InterSections[ ToNum($NrOfInterSection),ToNum($NrLight-4),"LightID" ] = $IntLightGet_B[0].""; #Indentifier of the light. $InterSections[ ToNum($NrOfInterSection),ToNum($NrLight-4),"InsimCircle" ] = $IntLightGet_B[1].""; #-1 if no insim circle has been set $InterSections[ ToNum($NrOfInterSection),ToNum($NrLight-4),"State" ] = $IntLightGet_B[2].""; #Red/Yellow/Green/Off (blinking yellow) $InterSections[ ToNum($NrOfInterSection),ToNum($NrLight-4),"Camera" ] = $IntLightGet_B[3].""; #Set Speed/RedLight camera on current light (1 = on / 0 = off) $InterSections[ ToNum($NrOfInterSection),ToNum($NrLight-4),"GreenTime" ] = $IntLightGet_B[4].""; #Set Invididual GreenTime $InterSections[ ToNum($NrOfInterSection),ToNum($NrLight-4),"GreenTimeCounter" ] = $IntLightGet_B[4].""; ENDFOR $NrOfInterSection = $NrOfInterSection+1; ENDIF ENDFOR DisplayInterSectionList($userName); EndSub #=========================================== #END Save/Load Intersections #=========================================== #=========================================== #CReate / Display info/ Edit #=========================================== Sub CreateIntersection($ID,$argv) $userName = GetCurrentPlayerVar("UserName"); $NrOfInterSection = $NrOfInterSection + 1; $InterSections[ ToNum($NrOfInterSection),"Name"] = $argv.""; #Name of Intersection $InterSections[ ToNum($NrOfInterSection),"ManyLights"] = 4.""; $InterSections[ ToNum($NrOfInterSection),"Type"] = "Cross-Intersection"; $InterSections[ ToNum($NrOfInterSection),"Control"] = 0.""; $InterSections[ ToNum($NrOfInterSection),"Active"] = 0.""; privmsg("^7A new intersection has been created: ^3".$InterSections[ ToNum($NrOfInterSection),"Name"]); DisplayInterSectionList($userName); EndSub Sub DisplayInterSectionList($userName) $sipos_hgt = 40; $sipos_wdt = 50; $CloseIntersectionList = ""; FOR($Nr = 1; $Nr < 16 ;$Nr=$Nr+1) IF($InterSections[ ToNum($Nr),"Name"] != "") THEN $InterIsEnabled = $InterSections[ ToNum($Nr),"Active"]; #Intersection is active and in use $TypeOfInter = $InterSections[ ToNum($Nr),"Type" ]; #4 way/ 3 way / 2 way intersections. (calculate in list how many lights are needed) $Control = $InterSections[ ToNum($Nr),"Control" ]; #Control of the startlights $ManyLightsOfInter = $InterSections[ ToNum($Nr),"ManyLights" ]; #How many lights $NameOfInter = $InterSections[ ToNum($Nr),"Name"]; #Name of Intersection IF ( $Control == 1) THEN $Control = "^3AUTO"; ELSE $Control = "^3MANUAL"; ENDIF IF ( $InterIsEnabled == 1) THEN $InterIsEnabled = "^2ON"; ELSE $InterIsEnabled = "^1OFF"; ENDIF OpenButton( $userName,"TL_FR_Nr_".$Nr,$sipos_wdt,$sipos_hgt+16,6,4,4,-1,ISB_LEFT |ISB_LIGHT | ISB_C2 | ISB_C4 ,"".$Nr); OpenButton( $userName,"TL_FR_Name_".$Nr,$sipos_wdt+6,$sipos_hgt+16,23,4,4,-1,80,"^0".$NameOfInter); OpenButton( $userName,"TL_FR_Type_".$Nr,$sipos_wdt+29,$sipos_hgt+16,22,4,4,-1,80,"^0".$TypeOfInter); OpenButton( $userName,"TL_FR_ManyLight_".$Nr,$sipos_wdt+51,$sipos_hgt+16,10,4,4,-1,16,"^0".$ManyLightsOfInter); OpenButton( $userName,"TL_FR_GreenTime_".$Nr,$sipos_wdt+61,$sipos_hgt+16,14,4,4,-1,16,"^0".$Control); OpenButton( $userName,"TL_FR_Enabled_".$Nr,$sipos_wdt+75,$sipos_hgt+16,10,4,4,-1,16,"^0".$InterIsEnabled); OpenButton( $userName,"TL_FR_Edit_".$Nr,$sipos_wdt+85,$sipos_hgt+16,15,4,4,-1,16,"^3Edit / Info",EditIntersection); $sipos_hgt = $sipos_hgt+4; $CloseIntersectionList = $CloseIntersectionList . "&TL_FR_Nr_".$Nr."&TL_FR_Name_".$Nr."&TL_FR_Type_".$Nr."&TL_FR_ManyLight_".$Nr."&TL_FR_GreenTime_".$Nr."&TL_FR_Enabled_".$Nr."&TL_FR_Edit_".$Nr."&TL_FR_Info_".$Nr; ENDIF ENDFOR OpenButton( $userName,"SI_Bgd_Dark",$sipos_wdt-1,39,102,$sipos_hgt-21 ,8,-1,32,""); $CloseIntersectionList = $CloseIntersectionList ."&SI_Bgd_Dark&SI_Title&SI_Closebutton&SI_CreateInter&SI_FR_Nr&SI_FR_Name&SI_FR_Type&SI_FR_Lights&SI_FR_GreenTime&SI_FR_Active&SI_FR_Info&SI_FR_Edit&SI_LoadInter&SI_SaveInter"; SetPlayerVar($userName,"CloseInterList",$CloseIntersectionList); EndSub Sub EditIntersection($keyflags,$id) $userName = GetCurrentPlayerVar("UserName"); closebutton($userName,GetPlayerVar($userName,"CloseInterList")); $InterSection = trim(subStr($id,11)); SetPlayerVar($userName,"SetInterSection",$InterSection); $CountLights = 0; $CloseLightsList = ""; $sipos_hgt = 40; $sipos_wdt = 72; OpenButton( $userName,"SI_Bgd_Dark",$sipos_wdt-1,39,63,70,8,-1,32,""); OpenButton( $userName,"SI_Title",$sipos_wdt,$sipos_hgt,61,5,8,-1,80,"^2» ^7Set Lights"); OpenButton( $userName,"SI_Closebutton",$sipos_wdt+56,$sipos_hgt,5,5,8,-1,0,"^0[^1X^0]",CloseSetinterSections); #Intersection Setting: OpenButton( $userName,"SI_TitleInterSetting",$sipos_wdt,$sipos_hgt+6,61,5,8,-1,80,"^0Intersection settings:"); $Name = $InterSections[ ToNum($InterSection),"Name"]; $Type = $InterSections[ ToNum($InterSection),"Type" ]; #Indentifier of the light. $ManyLights = $InterSections[ ToNum($InterSection),"ManyLights"]; #-1 if no insim circle has been set $Control = $InterSections[ ToNum($InterSection),"Control" ]; $InterIsEnabled = $InterSections[ ToNum($InterSection),"Active" ]; IF ( $Control == 1) THEN $Control = "^3AUTO"; ELSE $Control = "^3MANUAL"; ENDIF IF ( $InterIsEnabled == 1) THEN $InterIsEnabled = "^2ON"; ELSE $InterIsEnabled = "^1OFF"; ENDIF $sipos_hgt = $sipos_hgt+5; OpenButton( $userName,"SI_FR_NameA_" .$InterSection,$sipos_wdt,$sipos_hgt+6,25,4,4,-1,80,"^7Name of Intersection"); OpenButton( $userName,"SI_FR_TypeA_" .$InterSection,$sipos_wdt,$sipos_hgt+10,25,4,4,-1,80,"^7Intersection Type"); OpenButton( $userName,"SI_FR_ManyLightA_" .$InterSection,$sipos_wdt,$sipos_hgt+14,25,4,4,-1,80,"^7Nr Of Lights"); OpenButton( $userName,"SI_FR_GreenTimeA_" .$InterSection,$sipos_wdt,$sipos_hgt+18,25,4,4,-1,80,"^7Automatic Control"); OpenButton( $userName,"SI_FR_EnabledA_" .$InterSection,$sipos_wdt,$sipos_hgt+22,25,4,4,-1,80,"^7Intersection On/Off"); $CloseLightsList = $CloseLightsList ."&SI_FR_NameA_".$InterSection."&SI_FR_TypeA_".$InterSection."&SI_FR_ManyLightA_".$InterSection."&SI_FR_SeqA_".$InterSection."&SI_FR_GreenTimeA_".$InterSection."&SI_TitleInterSetting&SI_FR_EnabledA_".$InterSection; OpenTextButton( $userName,"SI_FR_NameB_" .$InterSection,$sipos_wdt+25,$sipos_hgt+6,36,4,4,80,"^0Enter name of the Intersection","^0".$Name,30,EditInterName); OpenTextButton( $userName,"SI_FR_TypeB_" .$InterSection,$sipos_wdt+25,$sipos_hgt+10,36,4,4,80,"^0Choose 1 to 5","^0".$Type,30,EditInterType); OpenButton( $userName,"SI_FR_ManyLightB_" .$InterSection,$sipos_wdt+25,$sipos_hgt+14,36,4,4,-1,80,"^0".$ManyLights); OpenTextButton( $userName,"SI_FR_GreenTimeB_" .$InterSection,$sipos_wdt+25,$sipos_hgt+18,36,4,4,80,"^0Set Control value ( 0 = manual / 1 = automatic)","^0".$Control,1,EditControl); OpenTextButton( $userName,"SI_FR_EnabledB_" .$InterSection,$sipos_wdt+25,$sipos_hgt+22,36,4,4,80,"^0Turn ON/OFF Intersection 0 = OFF / 1 = ON","^0".$InterIsEnabled,1,EditEnabled); $CloseLightsList = $CloseLightsList ."&SI_FR_NameB_".$InterSection."&SI_FR_TypeB_".$InterSection."&SI_FR_ManyLightB_".$InterSection."&SI_FR_SeqB_".$InterSection."&SI_FR_GreenTimeB_".$InterSection."&SI_FR_EnabledB_".$InterSection; $sipos_hgt = $sipos_hgt+25; OpenButton( $userName,"SI_TitleLightSettingSetting",$sipos_wdt,$sipos_hgt+7,61,5,8,-1,80,"^0TrafficLight Settings:"); OpenButton( $userName,"SI_FR_NrC_" .$InterSection,$sipos_wdt,$sipos_hgt+12,6,4,4,-1,16,"^7Nr"); OpenButton( $userName,"SI_FR_LightIDC_" .$InterSection,$sipos_wdt+6,$sipos_hgt+12,10,4,4,-1,16,"^7LightID"); OpenButton( $userName,"SI_FR_InsimCircleC_" .$InterSection,$sipos_wdt+16,$sipos_hgt+12,10,4,4,-1,16,"^7InsimCircle"); OpenButton( $userName,"SI_FR_CamC_" .$InterSection,$sipos_wdt+26,$sipos_hgt+12,10,4,4,-1,16,"^7Camera"); OpenButton( $userName,"SI_FR_GreenTimeC_" .$InterSection,$sipos_wdt+36,$sipos_hgt+12,15,4,4,-1,16,"^7GreenTime"); OpenButton( $userName,"SI_FR_StateC_" .$InterSection,$sipos_wdt+51,$sipos_hgt+12,10,4,4,-1,16,"^7State"); $CloseLightsList = $CloseLightsList ."&SI_Title&SI_Closebutton&SI_CreateInterC_".$InterSection."&SI_FR_NrC_".$InterSection."&SI_FR_LightIDC_".$InterSection."&SI_FR_InsimCircleC_".$InterSection."&SI_FR_CamC_".$InterSection."&SI_FR_StateC_".$InterSection."&SI_FR_GreenTimeC_".$InterSection."&SI_TitleLightSettingSetting&SI_Refresh"; FOR($Nr = 1; $Nr < 5 ; $Nr = $Nr +1) IF ( $InterSections[ ToNum( $InterSection ),ToNum( $Nr ),"LightID" ] > 0) THEN $CountLights = $CountLights+1; #Set Vars $LightID = $InterSections[ ToNum($InterSection),ToNum($Nr),"LightID" ]; #Indentifier of the light. $InsimCircle = $InterSections[ ToNum($InterSection),ToNum($Nr),"InsimCircle" ]; #-1 if no insim circle has been set $StateOfLight = $InterSections[ ToNum($InterSection),ToNum($Nr),"State" ]; #Red/Yellow/Green/Off (blinking yellow) $SetCamera = $InterSections[ ToNum($InterSection),ToNum($Nr),"Camera" ]; #Set Speed/RedLight camera on current light (1 = on / 0 = off) $GreenTime = $InterSections[ ToNum($InterSection),ToNum($Nr),"GreenTime" ]; #Set Invididual GreenTime IF($SetCamera == 1)THEN $SetCamera = "^2ON"; ELSE $SetCamera = "^1OFF"; ENDIF #Set buttons OpenButton( $userName,"SI_FR_Nr_" .$Nr,$sipos_wdt,$sipos_hgt+16,6,4,4,-1,ISB_LIGHT | ISB_C2 | ISB_C4 ,"".$Nr); OpenTextButton( $userName,"SI_FR_LightID_" .$Nr,$sipos_wdt+6,$sipos_hgt+16,10,4,4,16,"^0Choose between 1 and 63","^0".$LightID,2,EditLightID); OpenTextButton( $userName,"SI_FR_InsimCircle_" .$Nr,$sipos_wdt+16,$sipos_hgt+16,10,4,4,16,"^0Choose between 1 and 100","^0".$InsimCircle,3,EditInsimCircle); OpenTextButton( $userName,"SI_FR_Cam_" .$Nr,$sipos_wdt+26,$sipos_hgt+16,10,4,4,16,"^00 = ^1OFF ^0/ 1 = ^2ON","^0".$SetCamera,1,EditCamera); OpenTextButton( $userName,"SI_FR_GreenTime_" .$Nr,$sipos_wdt+36,$sipos_hgt+16,15,4,4,16,"^0Enter value in seconds","^0".$GreenTime." Seconds",2,EditGreenLight); OpenTextButton( $userName,"SI_FR_State_" .$Nr,$sipos_wdt+51,$sipos_hgt+16,10,4,4,16,"^00/1/2/3 (OFF/Red/Yellow/Green)","".$StateOfLight,1,EditStateOfLight); $sipos_hgt = $sipos_hgt+4; $CloseLightsList = $CloseLightsList ."&SI_CreateInter_".$Nr."&SI_FR_Nr_".$Nr."&SI_FR_LightID_".$Nr."&SI_FR_InsimCircle_".$Nr."&SI_FR_Cam_".$Nr."&SI_FR_State_".$Nr."&SI_FR_GreenTime_".$Nr; ENDIF ENDFOR #Buttonstate add trafficlights IF($CountLights >= $ManyLights) THEN $CountLights == $ManyLights; OpenButton( $userName,"SI_CreateInterC_" .$InterSection,$sipos_wdt,72,25,5,8,-1,16,"^8Create TrafficLight ^1[".$CountLights."/".$ManyLights."]"); ELSE OpenTextButton( $userName,"SI_CreateInterC_" .$InterSection,$sipos_wdt,72,25,5,8,16,"^0Enter LightID","^0Create TrafficLight ^3[".$CountLights+1."/".$ManyLights."]",2,CreateLight); ENDIF DisplayLightState(0,0); OpenButton( $userName,"SI_GOBACK",$sipos_wdt,103,61,5,8,-1,16,"^3GO BACK",GoBackToIntersectionsList); SetPlayerVar($userName,"CloseLightList",$CloseLightsList); EndSub Sub DisplayLightState($keyflags,$id) $userName = GetCurrentPlayerVar("UserName"); $InterSection = GetPlayerVar($userName,"SetInterSection"); $CloseLightsList = GetPlayerVar($userName,"CloseLightList"); $sipos_hgt = 70; $sipos_wdt = 72; OpenButton( $userName,"SI_Refresh",$sipos_wdt,$sipos_hgt+7,61,5,8,2,128,"",DisplayLightState); FOR ( $Nr = 1; $Nr < 7 ; $Nr = $Nr + 1) IF($InterSections[ ToNum($InterSection),ToNum($Nr),"LightID" ] > 0) THEN OpenTextButton( $userName,"SI_FR_State_" .$Nr,$sipos_wdt+51,$sipos_hgt+16,10,4,4,16,"^00/1/2/3 (OFF/Red/Yellow/Green)","".GetStateLightColor($InterSections[ ToNum($InterSection),ToNum($Nr),"State" ]),1,EditStateOfLight); $sipos_hgt = $sipos_hgt+4; $CloseLightsList = $CloseLightsList ."&SI_FR_State_".$Nr; ENDIF ENDFOR SetPlayerVar($userName,"CloseLightList",$CloseLightsList); EndSub Sub GoBackToIntersectionsList($keyflags,$id) $userName = GetCurrentPlayerVar("UserName"); Closebutton($userName,GetPlayerVar($userName,"CloseLightList")."&SI_GOBACK"); SetInterSections($userName); EndSub ######################################################################## #InterSection Settings ######################################################################## Sub EditInterName($ID,$argv) $userName = GetCurrentPlayerVar("UserName"); $InterSection = trim(subStr($ID,12)); $InterSections[ ToNum($InterSection),"Name"] = $argv.""; textprivbutton( "SI_FR_NameB_".$InterSection,"^0".$InterSections[ ToNum($InterSection),"Name"] ); EndSub Sub EditInterType($ID,$argv) $userName = GetCurrentPlayerVar("UserName"); $InterSection = trim(subStr($ID,12)); IF (IsNum($argv) == 1) THEN IF($argv > 0 && $argv < 6) THEN $InterSections[ ToNum($InterSection),"Type"] = $TypeInterSections[ToNum($argv)].""; $InterSections[ ToNum($InterSection),"ManyLights"] = $NRofLightsOnInterSection[$TypeInterSections[ToNum($argv)]].""; textprivbutton( "SI_FR_TypeB_".$InterSection,"^0".$InterSections[ ToNum($InterSection),"Type"] ); textprivbutton( "SI_FR_ManyLightB_".$InterSection,"^0".$InterSections[ ToNum($InterSection),"ManyLights"] ); ELSE privmsg("^1ERROR: ^7Choose between Type 1 and 5"); ENDIF ELSE privmsg("^1ERROR: ^7value cannot contain illigal characters"); ENDIF EndSub Sub EditControl($ID,$argv) $userName = GetCurrentPlayerVar("UserName"); $InterSection = trim(subStr($ID,17)); IF (IsNum($argv) == 1) THEN IF($argv == 0 || $argv == 1) THEN $InterSections[ ToNum($InterSection),"Control"] = $argv.""; IF ($argv == 0) THEN textprivbutton( "SI_FR_GreenTimeB_".$InterSection,"^3MANUAL"); ENDIF IF ($argv == 1) THEN textprivbutton( "SI_FR_GreenTimeB_".$InterSection,"^3AUTO"); ENDIF ELSE privmsg("^1ERROR: ^7Choose 1[Automatic] or 0[Manual]"); ENDIF ELSE privmsg("^1ERROR: ^7value cannot contain illigal characters"); ENDIF EndSub Sub EditEnabled($ID,$argv) $userName = GetCurrentPlayerVar("UserName"); $InterSection = trim(subStr($ID,15)); IF ($InterSections[ ToNum($InterSection),"ManyLights"] > 0) THEN IF (IsNum($argv) == 1) THEN IF($argv == 0 || $argv == 1) THEN $InterSections[ ToNum($InterSection),"Active"] = $argv.""; IF ($argv == 0) THEN textprivbutton( "SI_FR_EnabledB_".$InterSection,"^1OFF"); ENDIF IF ($argv == 1) THEN textprivbutton( "SI_FR_EnabledB_".$InterSection,"^2ON"); FOR($NRofLight = 1; $NRofLight < $InterSections[ ToNum($InterSection),"ManyLights"]+1; $NRofLight = $NRofLight + 1) IF($NRofLight == 1) THEN $InterSections[ ToNum($InterSection),ToNum($NRofLight),"State" ] = 3.""; $InterSections[ ToNum($InterSection),ToNum($NRofLight),"GreenTime" ] = $DefaultGreenTime.""; $InterSections[ ToNum($InterSection),ToNum($NRofLight),"GreenTimeCounter" ] = $DefaultGreenTime.""; startlightcontrol(5,149,$InterSections[ ToNum($InterSection),ToNum($NRofLight),"LightID" ],8); ELSE $InterSections[ ToNum($InterSection),ToNum($NRofLight),"State" ] = 1.""; $InterSections[ ToNum($InterSection),ToNum($NRofLight),"GreenTime" ] = $DefaultGreenTime.""; $InterSections[ ToNum($InterSection),ToNum($NRofLight),"GreenTimeCounter" ] = $DefaultGreenTime.""; startlightcontrol(5,149,$InterSections[ ToNum($InterSection),ToNum($NRofLight),"LightID" ],1); ENDIF ENDFOR ENDIF ELSE privmsg("^1ERROR: ^7Choose 1[Enable] or 0[Disable]"); ENDIF ELSE privmsg("^1ERROR: ^7value may not contain illigal characters"); ENDIF ELSE privmsg("^1ERROR: ^7No Lights found. Please add lights before enabling the intersection!!"); ENDIF EndSub ######################################################################## #END InterSection Settings ######################################################################## ## Light Settings Sub EditLightID($ID,$argv) $userName = GetCurrentPlayerVar("UserName"); $InterSection = GetPlayerVar($userName,"SetInterSection"); $NrOfLight = trim(subStr($ID,14)); IF (IsNum($argv) == 1) THEN IF($argv > 0 && $argv < 64) THEN $InterSections[ ToNum($InterSection),ToNum($NrOfLight),"LightID" ] = $argv.""; textprivbutton( "SI_FR_LightID_" .$NrOfLight,"^0".$InterSections[ ToNum($InterSection),ToNum($NrOfLight),"LightID" ]); ELSE privmsg("^1ERROR: ^7Choose from 1 to 63"); ENDIF ELSE privmsg("^1ERROR: ^7value cannot contain illegal characters"); ENDIF EndSub ## Set Insimcircle ID Sub EditInsimCircle($ID,$argv) $userName = GetCurrentPlayerVar("UserName"); $InterSection = GetPlayerVar($userName,"SetInterSection"); $NrOfLight = trim(subStr($ID,18)); IF (IsNum($argv) == 1) THEN IF( ToNum($argv) >= 0 && ToNum($argv) <= 100) THEN $InterSections[ ToNum($InterSection),ToNum($NrOfLight),"InsimCircle" ] = $argv.""; textprivbutton( "SI_FR_InsimCircle_" .$NrOfLight,"^0".$InterSections[ ToNum($InterSection),ToNum($NrOfLight),"InsimCircle" ]); ELSE privmsg("^1ERROR: ^7Choose from 1 to 100"); ENDIF ELSE privmsg("^1ERqqROR: ^7value cannot contain illegal characters"); ENDIF EndSub ## Set Camera On/Off Sub EditCamera($ID,$argv) $userName = GetCurrentPlayerVar("UserName"); $InterSection = GetPlayerVar($userName,"SetInterSection"); $NrOfLight = trim(subStr($ID,10)); IF (IsNum($argv) == 1) THEN IF($argv == 0 || $argv == 1) THEN $InterSections[ ToNum($InterSection),ToNum($NrOfLight),"Camera" ] = $argv.""; IF ($argv == 0) THEN textprivbutton( "SI_FR_Cam_".$NrOfLight,"^1OFF"); ENDIF IF ($argv == 1) THEN textprivbutton( "SI_FR_Cam_".$NrOfLight,"^2ON"); ENDIF ELSE privmsg("^1ERROR: ^7Choose 1[Enable] or 0[Disable]"); ENDIF ELSE privmsg("^1ERROR: ^7value cannot contain illegal characters"); ENDIF EndSub ## Set Greenlight timer Sub EditGreenLight($ID,$argv) $userName = GetCurrentPlayerVar("UserName"); $InterSection = GetPlayerVar($userName,"SetInterSection"); $NrOfLight = trim(subStr($ID,16)); IF (IsNum($argv) == 1) THEN IF (ToNum($argv) >= 2) THEN $InterSections[ ToNum($InterSection),ToNum($NrOfLight),"GreenTime" ] = $argv.""; $InterSections[ ToNum($InterSection),ToNum($NrOfLight),"GreenTimeCounter" ] = $argv.""; textprivbutton( "SI_FR_GreenTime_".$NrOfLight,"^0".$InterSections[ ToNum($InterSection),ToNum($NrOfLight),"GreenTime" ]." Seconds"); ELSE privmsg("^1ERROR: ^7Minimum greentime is 2 seconds!"); ENDIF ELSE privmsg("^1ERROR: ^7value cannot contain illegal characters"); ENDIF EndSub ## Set State of light Sub EditStateOfLight($ID,$argv) $userName = GetCurrentPlayerVar("UserName"); $InterSection = GetPlayerVar($userName,"SetInterSection"); IF ($InterSections[ ToNum($InterSection),"Control"] == 0) THEN $NrOfLight = trim(subStr($ID,12)); $LightColor = 0; $LightIndentifier = $InterSections[ ToNum($InterSection),ToNum($NrOfLight),"LightID" ]; IF (IsNum($argv) == 1) THEN IF($argv >= 0 && $argv < 4) THEN $InterSections[ ToNum($InterSection),ToNum($NrOfLight),"State" ] = $argv.""; IF ($argv == 0) THEN $LightColor = 0; ENDIF IF ($argv == 1) THEN $LightColor = 1; ENDIF IF ($argv == 2) THEN $LightColor = 2; ENDIF IF ($argv == 3) THEN $LightColor = 8; ENDIF textprivbutton( "SI_FR_State_".$NrOfLight,"".GetStateLightColor($argv)); startlightcontrol(5,149,$LightIndentifier,$LightColor); ELSE privmsg("^1ERROR: ^7Choose 0/1/2/3"); ENDIF ELSE privmsg("^1ERROR: ^7value cannot contain illegal characters"); ENDIF ELSE privmsg("^1ERROR: ^7Set intersection into manual mode!!!"); ENDIF EndSub ######################################################################## #END Light Settings ######################################################################## Sub GetStateLightColor($State) IF ($State == 0) THEN $Color = "^0•••••"; ENDIF IF ($State == 1) THEN $Color = "^1•••••"; ENDIF IF ($State == 2) THEN $Color = "^3•••••"; ENDIF IF ($State == 3) THEN $Color = "^2•••••"; ENDIF Return($Color); EndSub Sub CreateLight($ID,$argv) $userName = GetCurrentPlayerVar("UserName"); $InterSection = ToNum(trim(subStr($ID,16))); $LightIndentifier = $argv; $LightSet = TRUE; #Numeric value check IF (IsNum( $LightIndentifier) == 1 && IsNum( $InterSection ) == 1) THEN IF ((ToNum($LightIndentifier) < 64)&&(ToNum($LightIndentifier) > 0)) THEN #Loop to check each lightnumber FOR($i = 1; $i < 7; $i = $i + 1 ) IF ($LightSet == TRUE) THEN IF (ToNum($i) <= $InterSections[ ToNum($InterSection),"ManyLights"]) THEN IF ( $InterSections[ ToNum($InterSection),ToNum($i),"LightID" ] < 1) THEN #Set new light $InterSections[ ToNum($InterSection),ToNum($i),"LightID" ] = $LightIndentifier.""; $InterSections[ ToNum($InterSection),ToNum($i),"InsimCircle" ] = -1.""; $InterSections[ ToNum($InterSection),ToNum($i),"State" ] = 1.""; $InterSections[ ToNum($InterSection),ToNum($i),"Camera" ] = 0.""; $InterSections[ ToNum($InterSection),ToNum($i),"GreenTime" ] = 5.""; $InterSections[ ToNum($InterSection),ToNum($i),"GreenTimeCounter" ] = 5.""; $InterSections[ ToNum($InterSection),ToNum($i),"YellowTimeCounter" ] = 4.""; privmsg("^7New trafficlight has been created: ^3Nr ".ToNum($i) ." ^0[ ^6LightID: ^7".$LightIndentifier ."^0]"); startlightcontrol(5,149,$LightIndentifier,3); EditIntersection(0,$InterSection); $LightSet = FALSE; ENDIF ENDIF ENDIF ENDFOR ELSE privmsg("^1ERROR: ^7Enter a ID number from 1 to 63"); ENDIF ELSE privmsg("^1ERROR: ^7value cannot contain illegal characters"); ENDIF EndSub Sub TrafficLoop() IF( $NrOfInterSection > 0) THEN FOR($i = 1 ; $i < $NrOfInterSection+1; $i = $i + 1) IF($InterSections[ ToNum($i),"Active"] == 1) THEN #Check is Intersection is set in AutomaticMode IF ($InterSections[ ToNum($i),"Control"] == 1) THEN #Check how many lights are set for the current intersection IF($InterSections[ ToNum($i),"ManyLights"] > 0) THEN #Check how many light are set for the current intersection FOR($NRofLight = 1; $NRofLight < $InterSections[ ToNum($i),"ManyLights"]+1; $NRofLight = $NRofLight + 1) #Check the state of light is Amber ( Lightstatus = 2 ) IF(ToNum($InterSections[ ToNum($i),ToNum($NRofLight),"State" ]) == 2) THEN IF($InterSections[ ToNum($i),ToNum($NRofLight),"YellowLightCounter" ] == "") THEN $InterSections[ ToNum($i),ToNum($NRofLight),"YellowLightCounter" ] = 4.""; ENDIF #Check duration of yellowlight. IF( ToNum($InterSections[ ToNum($i),ToNum($NRofLight),"YellowLightCounter" ]) == 1) THEN startlightcontrol(5,149,ToNum($InterSections[ ToNum($i),ToNum($NRofLight),"LightID" ]),1); #globalmsg("^6[DEBUG]Send IS_UCO insimpacket ".$NRofLight); $InterSections[ ToNum($i),ToNum($NRofLight),"GreenTimeCounter" ] = $InterSections[ ToNum($i),ToNum($NRofLight),"GreenTime" ].""; IF ($InterSections[ ToNum($i),ToNum($NRofLight+1),"LightID" ] != "") THEN $InterSections[ ToNum($i),ToNum($NRofLight+1),"State" ] = 3.""; #Set Light to green startlightcontrol(5,149,$InterSections[ ToNum($i),ToNum($NRofLight+1),"LightID" ],8); ELSE $InterSections[ ToNum($i),ToNum(1),"State" ] = 3.""; #Set Light to green startlightcontrol(5,149,$InterSections[ ToNum($i),ToNum(1),"LightID" ],8); ENDIF ENDIF IF( ToNum($InterSections[ ToNum($i),ToNum($NRofLight),"YellowLightCounter" ]) < 1) THEN #globalmsg("^3[DEBUG]Changed state to red ".$NRofLight); $InterSections[ ToNum($i),ToNum($NRofLight),"State" ] = 1.""; #Set Light to Red $InterSections[ ToNum($i),ToNum($NRofLight),"YellowLightCounter" ] = 4.""; #Reset YellowLightCounter ELSE $InterSections[ ToNum($i),ToNum($NRofLight),"YellowLightCounter" ] = $InterSections[ ToNum($i),ToNum($NRofLight),"YellowLightCounter" ] - 1.""; #globalmsg("[DEBUG]YellowTime:". $InterSections[ ToNum($i),ToNum($NRofLight),"YellowLightCounter" ]); ENDIF ENDIF #Check the state of light is Green ( lightstatus = 3 ) IF(ToNum($InterSections[ ToNum($i),ToNum($NRofLight),"State" ]) == 3) THEN IF($InterSections[ ToNum($i),ToNum($NRofLight),"GreenTimeCounter" ] == 0) THEN startlightcontrol(5,149,ToNum($InterSections[ ToNum($i),ToNum($NRofLight),"LightID" ]),2); $InterSections[ ToNum($i),ToNum($NRofLight),"State" ] = 2.""; #Set Light to amber ELSE $InterSections[ ToNum($i),ToNum($NRofLight),"GreenTimeCounter" ] = $InterSections[ ToNum($i),ToNum($NRofLight),"GreenTimeCounter" ] - 1.""; ENDIF ENDIF ENDFOR ENDIF ENDIF ELSE #Create new loop for blinking yellow light when intersection is inactive. FOR($NRofLighttwo = 1; $NRofLighttwo < $InterSections[ ToNum($i),"ManyLights"]+1; $NRofLighttwo = $NRofLighttwo + 1) #Check stats of each light. IF ($InterSections[ ToNum($i),ToNum($NRofLighttwo),"LightID" ] != "") THEN $StateofLight = $InterSections[ ToNum($i),ToNum($NRofLighttwo),"State" ]; IF ((ToNum( $StateofLight ) == 1)||(ToNum( $StateofLight ) == 2)||(ToNum( $StateofLight ) == 3)) THEN startlightcontrol(5,149,ToNum($InterSections[ ToNum($i),ToNum($NRofLighttwo),"LightID" ]),0); $InterSections[ ToNum($i),ToNum($NRofLighttwo),"State" ] = 0.""; #Set Light to 0 ELSE startlightcontrol(5,149,ToNum($InterSections[ ToNum($i),ToNum($NRofLighttwo),"LightID" ]),2); $InterSections[ ToNum($i),ToNum($NRofLighttwo),"State" ] = 2.""; #Set Light to amber ENDIF ENDIF ENDFOR ENDIF ENDFOR ENDIF delayedcommand("TrafficLoop",1,TrafficLoop); EndSub ######################################################################## #Close Menu ######################################################################## Sub CloseSetinterSections($keyflags,$id) $userName = GetCurrentPlayerVar("UserName"); Closebutton($userName,GetPlayerVar($userName,"CloseLightList")."&SI_GOBACK"); Closebutton($userName,GetPlayerVar($userName,"CloseInterList")); EndSub