diff --git a/scripts/bricks.cs b/scripts/bricks.cs index bc77e73..416641f 100644 --- a/scripts/bricks.cs +++ b/scripts/bricks.cs @@ -1,21 +1,30 @@ -function lualogic_addwire(%wire) -{ - %color = %wire.getColorID(); +function lualogic_getlayer(%wire) { + // -1 if the brick is rainbow, its color ID otherwise + if(%wire.getColorFxId()==6) { + return -1; + } else { + return %wire.getColorId(); + } +} + +function lualogic_addwire(%wire) { + %layer = lualogic_getlayer(%wire); + %box = %wire.getWorldBox(); - + %minX = mFloatLength(getWord(%box, 0)*2, 0)/2; %minY = mFloatLength(getWord(%box, 1)*2, 0)/2; %minZ = mFloatLength(getWord(%box, 2)*5, 0)/5; - + %maxX = mFloatLength(getWord(%box, 3)*2, 0)/2; %maxY = mFloatLength(getWord(%box, 4)*2, 0)/2; %maxZ = mFloatLength(getWord(%box, 5)*5, 0)/5; - + %min = lualogic_pos(%minX SPC %minY SPC %minZ); %max = lualogic_pos(%maxX SPC %maxY SPC %maxZ); - - lualogic_send("W;" @ %wire.getID() @ ";" @ %color @ ";" @ %min @ ";" @ %max); + + lualogic_send("W;" @ %wire.getID() @ ";" @ %layer @ ";" @ %min @ ";" @ %max); %wire.logicIsAdded = true; } @@ -56,23 +65,22 @@ function lualogic_removegate(%gate) } } -function lualogic_sendall() -{ - %groups = mainBrickGroup.getCount(); - for(%i = 0; %i < %groups; %i++) - { +function lualogic_sendall() { + %num_groups = mainBrickGroup.getCount(); + for(%i = 0; %i < %num_groups; %i++) { %group = mainBrickGroup.getObject(%i); - %bricks = %group.getCount(); - for(%a = 0; %a < %bricks; %a++) - { + + %num_bricks = %group.getCount(); + for(%a = 0; %a < %num_bricks; %a++) { %brick = %group.getObject(%a); + %data = %brick.getDataBlock(); - if(%data.isLogic && %brick.isPlanted() && !%brick.logicIsRemoved) - { - if(%data.isLogicWire) + if(%data.isLogic && %brick.isPlanted() && !%brick.isDead() && !%brick.logicIsRemoved) { + if(%data.isLogicWire) { lualogic_addwire(%brick); - else if(%data.isLogicGate) + } else if(%data.isLogicGate) { lualogic_addgate(%brick); + } } } } @@ -136,13 +144,47 @@ package LuaLogic_Bricks %brick.Logic_HandlePlant(); } } - + + function fxDtsBrick::setColorFx(%brick, %fx, %bypass) { + %data = %brick.getDatablock(); + if( // If the brick is a wire - act specially + isObject(%brick) && + %brick.isPlanted && + !%brick.isDead() && + %data.isLogic && + %data.isLogicWire + ) { + if(%bypass) { // If this is a glow update generated by logic backend - act normally + if(%brick.getColorFxId()!=6) { // If the brick is not rainbow, act normally + parent::setColorFx(%brick, %fx); + } else { // if the brick is rainbow, do nothing + return; + } + } else { // If this is a manual FX change on a wire - act specially + if( + (%fx==0 && %brick.getColorFxId()==6) || + (%fx==6 && (%brick.getColorFxId()==0 || %brick.getColorFxId()==3)) + ) { // If toggling rainbowness - act normally, and send a color update if the brick is added + parent::setColorFx(%brick, %fx); + if(%brick.logicIsAdded) { + lualogic_send("SL;" @ %brick @ ";" @ lualogic_getlayer(%brick)); + } + } else { // If not toggling rainbowness - do nothing + return; + } + } + } else { // The brick is not a wire - act normally + parent::setColorFx(%brick, %fx); + } + } + function fxDTSBrickData::onColorChange(%data, %obj) { parent::onColorChange(%data, %obj); - - if(isObject(%obj) && %obj.isPlanted() && !%obj.isDead() && %data.isLogic && %data.isLogicWire) - lualogic_send("SL;" @ %obj @ ";" @ %obj.getColorID()); + + if(isObject(%obj) && %obj.isPlanted() && !%obj.isDead() && %data.isLogic && %data.isLogicWire && %obj.logicIsAdded) { + lualogic_send("SL;" @ %obj @ ";" @ lualogic_getlayer(%obj)); + } } function fxDTSBrickData::onDeath(%this, %brick) diff --git a/scripts/cmds.cs b/scripts/cmds.cs index e78931a..2f71da2 100644 --- a/scripts/cmds.cs +++ b/scripts/cmds.cs @@ -21,7 +21,7 @@ function serverCmdLST(%client, %time) function serverCmdLSM(%client, %mult){ if(%client.isAdmin || %client.isSuperAdmin){ - %mult = mFloor(mClamp(%mult, 1, 1000)); + %mult = mFloor(mClamp(%mult, 1, 10000)); $Pref::Server::LuaLogic::OPT_TICK_MULT = %mult; messageAll('', '\c3%1\c6 has set the logic tick multiplier to \c3%2\c6.', %client.name, %mult); lualogic_sendoptions(); diff --git a/scripts/tcp.cs b/scripts/tcp.cs index 0ad046a..430e179 100644 --- a/scripts/tcp.cs +++ b/scripts/tcp.cs @@ -42,7 +42,7 @@ function LuaLogicTCP::onLine(%this, %line) { %brick = getField(%line, %i); if(isObject(%brick)) - %brick.setColorFX(3); + %brick.setColorFX(3, true); } } else @@ -51,7 +51,7 @@ function LuaLogicTCP::onLine(%this, %line) { %brick = getField(%line, %i); if(isObject(%brick)) - %brick.setColorFX(0); + %brick.setColorFX(0, true); } } case "TPS":