Blockland Forums > General Discussion
Server rule add-ons that outputs rules to the chat.
<< < (2/2)
Pentium:
I was thinking about the one that read the rules from a text file, but this will do for now. Thanks a lot.
sh0ckthealien:

--- Quote from: Pentium on April 19, 2011, 03:33:54 AM ---I was thinking about the one that read the rules from a text file, but this will do for now. Thanks a lot.

--- End quote ---

In that case, I would do this.

--- Code: ---$Rules = "config/server/rules.txt";

function loadRules()
{   
    $Rules_Tot = 0;
    %file = new fileObject(fileStream);
    %file.openForRead($Rules);
    $Rules_Ttl = %file.readLine();
    while(!%file.isEOF())
    {
        $Rules_Tot++;
     $Rules_Ln[$Rules_Tot] = %file.readLine();
    }
    %file.close();
    %file.delete();
}

package showRules
{
    function GameConnection::OnClientEnterGame(%client)
    { 
       if(isFile($Rules))
          {
              messageClient(%client,'',"\c2" @ $Rules_Ttl);
              for(%i=1;%i<=$Rules_Tot;%i++)
              {
              messageClient(%client,'',"\c3" @ $Rules_Ln[%i]);
              }
          }
      Parent::OnClientEnterGame(%client);
    }
};
activatePackage(showRules);

loadRules();
--- End code ---

I would format my text file like so:


--- Code: ---Rules:
1. Rule 1
2. Rule 2
--- End code ---
Pentium:
You are awesome.
DontCare4Free:

--- Quote from: DrenDran on April 18, 2011, 06:13:14 PM ---It'd be fairly simple to do, for example:

--- Code: ---$numberofrules = 4; //one less than actual
$rule[0] = "Rule one.";
$rule[1] = "Rule two.";
$rule[2] = "Rule three.";
$rule[3] = "Rule four.";
$rule[4] = "Rule five.";
package rulesforplayerjoin
{
function Gameconnection::onPlayerSpawn(%client,%otherstuff)//probably not the actual function name
{
Parent::onPlayerSpawn(%client,%otherstuff);
for(%a=0;%a<$numberofrules;%a++)
messageclient(%client,'',$rule[%a]);
}
};
activatepackage(rulesforplayerjoin);

--- End code ---

--- End quote ---

--- Code: ---$numberofrules = 5;
$rule[0] = "Rule one.";
$rule[1] = "Rule two.";
$rule[2] = "Rule three.";
$rule[3] = "Rule four.";
$rule[4] = "Rule five.";
package rulesforplayerjoin
{
function Gameconnection::onPlayerSpawn(%client,%otherstuff)//probably not the actual function name
{
Parent::onPlayerSpawn(%client,%otherstuff);
for(%a=0;%a<$numberofrules - 1;%a++)
messageclient(%client,'',$rule[%a]);
}
};
activatepackage(rulesforplayerjoin);

--- End code ---
Would be much easier to understand
Navigation
Message Index
Previous page

Go to full version