Author Topic: Rules script help  (Read 1062 times)

What I have here is a rules script that if you don't agree to it (click no) then it kicks you, but if you
do agree to it (click yes) it spawns you. I cannot get the 'Yes' button to do its function correctly.
Code: [Select]
package ServerRules
{
function showRules(%client)
{
commandToClient(%client,'MessageBoxYesNo',"Rules by Simpeli","1. No spamming 2. Be respectful to others 3. Only certain client mods are allowed 4. Listen to all admins and moderators 5. Have fun :)",'acceptRules');
%client.hasRules = true;
}
function serverCMDacceptRules(%client)
{
if(%client.hasRules)
{
%client.hasRules = false;
parent::onClientEnterGame(%client); //Error here, it won't spawn the player
}
}
function serverCMDMessageBoxNo(%client)
{
if(%client.hasRules)
{
%client.hasRules = false;
messageAll('MsgAdminForce',"Kicking \c3"@%client.name@" \c0for disagreeing to server rules.");
%client.delete("Disagreed to server rules!");
}
}
function gameConnection::onClientEnterGame(%client)
{
showRules(%client);
}
};
activatePackage("ServerRules");

You forgot to parent onClientEnterGame.

You forgot to parent onClientEnterGame.
It's supposed to parent it when the person clicks 'Yes'
If I were to just parent it, they would spawn whether they click Yes or No. Right?

Your function for onClientEnterGame is

function gameConnection::onClientEnterGame(%client)
   {
      showRules(%client);
   }

That is what is calling the parent, I believe. Did you try doing, %client.spawnPlayer?

Like this?

package ServerRules
{
   function showRules(%client)
   {
      commandToClient(%client,'MessageBoxYesNo',"Rules by Simpeli","1. No spamming 2. Be respectful to others 3. Only certain client mods are allowed 4. Listen to all admins and moderators 5. Have fun :)",'acceptRules');
      %client.hasRules = true;
   }
   function serverCMDacceptRules(%client)
   {
      if(%client.hasRules)
      {
         %client.hasRules = false;
         %client.spawnPlayer();
      }
   }
   function serverCMDMessageBoxNo(%client)
   {
      if(%client.hasRules)
      {
         %client.hasRules = false;
         messageAll('MsgAdminForce',"Kicking \c3"@%client.name@" \c0for disagreeing to server rules.");
         %client.delete("Disagreed to server rules!");
      }
   }
   function gameConnection::onClientEnterGame(%client)
   {
      showRules(%client);
      if(%client.hasRules)
         Parent::onClientEnterGame(%client);
   }      
};
activatePackage("ServerRules");

I haven't tested this, so I'm not sure if it can work.

You'll have to call oncliententergame again in the servercmd for accepting it instead of spawnplayer (oncliententergame does way more), and only call showrules if hasrules isnt 1.

I see I've inspired a lot of new rule mods...

Anyway, Pecon released his own version here, which you can look at for reference.

edit. Here's part of my own version:

Code: [Select]
package Rules
{
function GameConnection::OnClientEnterGame(%this)
{
if(%this.rulesSent || %this.getClassName() !$= "GameConnection")
return parent::onClientEnterGame(%this);
else
%this.sendRules();
}

function GameConnection::sendRules(%this)
{
%this.rulesSent = true;
commandToClient(%this,'MessageBoxYesNo', $Rules_Title, $Rules_Body, 'rulesAccept');
}

function serverCmdMessageBoxNo(%client)
{
parent::serverCmdMessageBoxNo(%client);

if(%client.rulesSent && !%client.hasSpawnedOnce)
{
echo(%client.getSimpleName() SPC "does not agree with the rules!");
%client.delete("You must agree to the rules before you can play.");
}
}
};
activatePackage(Rules);

Please don't copy it; instead try to learn from it.
« Last Edit: June 22, 2014, 09:14:27 PM by Greek2me »

I see I've inspired a lot of new rule mods...

Anyway, Pecon released his own version here, which you can look at for reference.

edit. Here's part of my own version:

Code: [Select]
function GameConnection::OnClientEnterGame(%this)
{
if(%this.rulesSent || %this.getClassName() !$= "GameConnection")
return parent::onClientEnterGame(%this);
else
%this.sendRules();
}


Why would you need to put %this.getClassName() !$= "GameConnection" in that if statement?

Why would you need to put %this.getClassName() !$= "GameConnection" in that if statement?

AiConnection inherits from GameConnection. It's probably not necessary, just an extra safeguard.