Author Topic: My questions thread  (Read 9670 times)

Make a function loop another function with schedules.

Code: [Select]
function autoAnnounce(%msg)
{
  cancel($announceSched); //you should cancel schedules once they are used so they don't build up
  talk(%msg); //you can make this more sophisticated if you want by using chatMessageAll instead
  $announceSched = schedule(1000 * 60 * 2, 0, autoAnnounce, %msg); //1000 * 60 * 2 = two minutes in ms. we assign a pointer to the schedule so we can cancel it
}

Can anyone link/explain how one would go about making a keybind that plays code? Client-sided.

Code: [Select]
function autoAnnounce(%msg)
{
  cancel($announceSched); //you should cancel schedules once they are used so they don't build up
  talk(%msg); //you can make this more sophisticated if you want by using chatMessageAll instead
  $announceSched = schedule(1000 * 60 * 2, 0, autoAnnounce, %msg); //1000 * 60 * 2 = two minutes in ms. we assign a pointer to the schedule so we can cancel it
}

Where would you define %msg?
Does it have to be inside the function or can it be outside?
I'm not very clear on how local variables work...
« Last Edit: November 24, 2013, 01:03:48 PM by Johnny Blockhead »

...% is for LOCAL variables, not global variables.

...% is for LOCAL variables, not global variables.

My bad, I meant to say local.


//Made by Johnny Blockhead
package Hubcore
{
   //Auto Announcer
   function autoAnnounce(%AnnounceMsg)
   {
      cancel($announceSched);
      talk(%AnnounceMsg);
      $announceSched = schedule(1000 * 60 * 2, 0, autoAnnounce, %AnnounceMsg);
      %announceMsg = "Auto announcer";
   }
   
   //Check to see if file is up
   function servercmdIsUp(%Client)
   {
      messageClient(%client,'',"<color:ffffff>Johnny's Server Mod is up and running.");
   }
   
};
activatepackage("Hubcore");


I used the serverCmd to check if the package was executed. It was.
The Auto Announcer doesn't work

Code: [Select]
//Made by Johnny Blockhead
package Hubcore
{
//You never called the function to start the loop
function autoAnnounce(%AnnounceMsg)
{
cancel($announceSched);
talk(%AnnounceMsg);
$announceSched = schedule(1000 * 60 * 2, 0, autoAnnounce, %AnnounceMsg);
%announceMsg = "Auto announcer";   //This variable is set here but is never used again
}

//This is a horribly generic name and using it WILL cause a conflict with someone else's mods
function servercmdIsUp(%Client)
{
messageClient(%client,'',"<color:ffffff>Johnny's Server Mod is up and running.");
}

};
activatepackage("Hubcore");

autoAnnounce("This will be the only message that's ever announced");


//Made by Johnny Blockhead
package Hubcore
{
   //Auto Announcer
   function autoAnnounce(%AnnounceMsg)
   {
      cancel($announceSched);
      talk(%AnnounceMsg);
      $announceSched = schedule(1000 * 60 * 2, 0, autoAnnounce, %AnnounceMsg);
      %announceMsg = "Auto announcer";
   }
   
   //Check to see if file is up
   function servercmdIsUp(%Client)
   {
      messageClient(%client,'',"<color:ffffff>Johnny's Server Mod is up and running.");
   }
   
};
activatepackage("Hubcore");


I used the serverCmd to check if the package was executed. It was.
The Auto Announcer doesn't work
You have to pass the autoAnnounce function at least once for the loop to begin.

Can anyone link/explain how one would go about making a keybind that plays code? Client-sided.
http://forum.blockland.us/index.php?topic=182190.0


How would one set a delay for a servercmd? I know this exists, can't really find it.
I want to use this so people don't spam the /report command which talks the issue into server chat.

How would one set a delay for a servercmd? I know this exists, can't really find it.
I want to use this so people don't spam the /report command which talks the issue into server chat.
You'd probably want a timeout, not a delay. A delay would just make the spamming occur a few seconds later. A timeout would prevent use of the command until the time is up again.
Let me demonstrate.
Code: [Select]

function swag(%msg,%timeout)
{
   %time = getSimTime();

   if(!(getSimTime() - %time > %timeout))
   {
       chatMessageAll(%msg);
   }
   else
   {
       echo(%msg SPC "not sent, timeout not complete");
   }
}


You'd probably want a timeout, not a delay. A delay would just make the spamming occur a few seconds later. A timeout would prevent use of the command until the time is up again.
Let me demonstrate.
Code: [Select]

function swag(%msg,%timeout)
{
   %time = getSimTime();

   if(!(getSimTime() - %time > %timeout))
   {
       chatMessageAll(%msg);
   }
   else
   {
       echo(%msg SPC "not sent, timeout not complete");
   }
}


There's multiple things wrong with this code.

There's multiple things wrong with this code.
what was i thinking
sorry i based it off this from the coding resources sticky:
http://pastebin.com/raw.php?i=Vcg7XsDt
Code: [Select]
function serverCmdTimeoutMessage(%cl,%msg)
{
  if($timeoutLength $= "")
     $timeoutLength = 3000; //3 seconds default

   if(%cl.lastTimeUsed < getSimTime() - $timeoutLength)
  {
       chatMessageAll(%msg);
       %cl.lastTimeUsed = getSimTime();
  }
   else
   {
       echo(%cl.name @ "'s" SPC %msg SPC "not sent, timeout not complete");
   }
}
please tell me this will work it's 1 am i am tired pls  :panda:
« Last Edit: November 26, 2013, 09:08:33 PM by ultimamax »