Skip to content

Commit

Permalink
Added fireRelayRandomNum
Browse files Browse the repository at this point in the history
  • Loading branch information
McTwist committed Sep 15, 2017
1 parent 64f520f commit da03e8c
Showing 1 changed file with 45 additions and 2 deletions.
47 changes: 45 additions & 2 deletions server.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// ================
// Name :: FireRelayNum
// Version :: 5
// Version :: 6
// ================
// Made by :: McTwist
// Date :: 17-08-27
// Date :: 17-09-15
// Info :: Event that choose what onRelay to use
// License :: Free to use
// ================
Expand Down Expand Up @@ -112,6 +112,7 @@
// Events

registerOutputEvent(fxDTSBrick, "fireRelayNum", "string 100 100" TAB "list Brick 0 Up 1 Down 2 North 3 East 4 South 5 West 6", true);
registerOutputEvent(fxDTSBrick, "fireRelayRandomNum", "string 100 100" TAB "list Brick 0 Up 1 Down 2 North 3 East 4 South 5 West 6", true);

function fxDTSBrick::fireRelayNum(%brick, %num, %dir, %client)
{
Expand Down Expand Up @@ -150,6 +151,48 @@
return %brick;
}

function fxDTSBrick::fireRelayRandomNum(%brick, %num, %dir, %client)
{
if (%num $= "")
return %brick;

// Get numbers
%pass = FireRelayNum::parseNumbers(%num);

if (%pass $= "")
return %brick;

// Randomly pick one
// Note: If you got the same number several times, then the chance is
// higher for that number to be relayed
%pass = getWord(%pass, getRandom(0, getWordCount(%pass) - 1));

$inputTarget_Self = %brick;

// Brick
if (%dir $= "0")
%brick.ProcessFireRelay(%pass, %client);
// Direction
else
{
%bricks = %brick.getBricksDir(%dir);

%size = getWordCount(%bricks);
for (%i = 0; %i < %size; %i++)
{
%next = getWord(%bricks, %i);

// No events, do nothing
if (%next.numEvents == 0)
continue;

%next.ProcessFireRelay(%pass, %client);
}
}

return %brick;
}

// Package

if (isPackage(FireRelayNum))
Expand Down

0 comments on commit da03e8c

Please sign in to comment.