Action every given time from the beginning

Started by kennedyarz, Mar 14, 2017, 07:14 PM

Previous topic - Next topic

kennedyarz

Hi guys.
a question. Can I make an action run every 30 seconds once the server is turned on? example:
Function Blablabla ()
{
Message ("Bla bla bla")
}
it's an example

This message must be transmitted every 30 seconds once the server is started


Eva

You can use this
function onServerStart()
{
NewTimer("MessengerAllGlobal", 40000, 0 );
}

function MessengerAllGlobal()
{
if ( GetPlayers() >= 1 )
{
local RanNum = Random(1, 5);
if ( RanNum == 1 )  Message("Blabla1");
else if ( RanNum == 2 )  Message("Blabla2");
else if ( RanNum == 3 )  Message("IBlabla3");
else if ( RanNum == 4 )  Message("Blabla4");
else if ( RanNum == 5 ) Message( "Blabla5");
}

function Random(min=0, max=RAND_MAX)
{
local r = rand();
srand(GetTickCount() * r);
return (r % ((max + 1) - min)) + min;
}

kennedyarz

Quote from: Eva on Mar 14, 2017, 09:40 PMYou can use this
function onServerStart()
{
NewTimer("MessengerAllGlobal", 40000, 0 );
}

function MessengerAllGlobal()
{
if ( GetPlayers() >= 1 )
{
local RanNum = Random(1, 5);
if ( RanNum == 1 )  Message("Blabla1");
else if ( RanNum == 2 )  Message("Blabla2");
else if ( RanNum == 3 )  Message("IBlabla3");
else if ( RanNum == 4 )  Message("Blabla4");
else if ( RanNum == 5 ) Message( "Blabla5");
}

function Random(min=0, max=RAND_MAX)
{
local r = rand();
srand(GetTickCount() * r);
return (r % ((max + 1) - min)) + min;
}


But you think it will work.? Could it be that he will only give one advertisement? And will not announce more?

KAKAN

I see no reason to not use an array instead of those life-taking hell of if statements
oh no

Eva

Quote from: kennedyarz on Mar 15, 2017, 01:04 AM
Quote from: Eva on Mar 14, 2017, 09:40 PMYou can use this
function onServerStart()
{
NewTimer("MessengerAllGlobal", 40000, 0 );
}

function MessengerAllGlobal()
{
if ( GetPlayers() >= 1 )
{
local RanNum = Random(1, 5);
if ( RanNum == 1 )  Message("Blabla1");
else if ( RanNum == 2 )  Message("Blabla2");
else if ( RanNum == 3 )  Message("IBlabla3");
else if ( RanNum == 4 )  Message("Blabla4");
else if ( RanNum == 5 ) Message( "Blabla5");
}

function Random(min=0, max=RAND_MAX)
{
local r = rand();
srand(GetTickCount() * r);
return (r % ((max + 1) - min)) + min;
}


But you think it will work.? Could it be that he will only give one advertisement? And will not announce more?
If you want just 1 just set it like this:  local RanNum = Random(1, 1);

Quote from: KAKAN on Mar 15, 2017, 02:46 AMI see no reason to not use an array instead of those life-taking hell of if statements
I just gave an example of how i did it, and it works fine.
Maybe you can show how to do it in a different "more efficient way"

KAKAN

Quote from: Eva on Mar 15, 2017, 09:12 AMMaybe you can show how to do it in a different "more efficient way"
dunno if its efficient, but its better than typing if all the time.
yourMsgs <- [ "Message 1",
"Message 2" ]; //....
function RandMsg(){
Message( yourMsgs[ Random( 0, yourMsgs.len() - 1 ) ] );
}
I was not talking about efficiency, for a lazy person like me, its hard to type 100 if statements if you got 100 messages to print.
oh no

EK.IceFlake

Quote from: Eva on Mar 14, 2017, 09:40 PMYou can use this
If you want just 1 just set it like this:  local RanNum = Random(1, 1);
LMAO
Quote from: Eva on Mar 14, 2017, 09:40 PMMaybe you can show how to do it in a different "more efficient way"
function onScriptLoad()
{
    NewTimer("BlaBla", 30000, 0);
}
function BlaBla()
{
    MessageAll("Blah Blah Blah!!!");
}

Eva

Quote from: KAKAN on Mar 15, 2017, 11:53 AMI was not talking about efficiency, for a lazy person like me, its hard to type 100 if statements if you got 100 messages to print.
xD i use ctrl c and v , still you have to type the 100 messages.
but anyway i learned something :) thnx

kennedyarz

The truth is that thanks @Eva, I worked as you say, and @KAKAN my function was not to give messages, just an example. Topic solved