not stopping return a cmd
#1

Code:
CMD:day(playerid, params[])
{
if(PlayerInfo[playerid][pAdmin] <= 2) return SendClientMessage(playerid, COLOR_RED, "ERROR: Insufficient Permissions!");
for(new i = 0; i < MAX_PLAYERS; i++)
{
SetPlayerTime(i, 12, 0);
SendClientMessageToAll(COLOR_RED, "Server's time has been set to day time!");
}
return 1;
}
If I make the command this way, It returns again and again with no end.

And if I make it that way:

Code:
CMD:day(playerid, params[])
{
if(PlayerInfo[playerid][pAdmin] <= 2) return SendClientMessage(playerid, COLOR_RED, "ERROR: Insufficient Permissions!");
for(new i = 0; i < MAX_PLAYERS; i++)
{
SetPlayerTime(i, 12, 0);
SendClientMessageToAll(COLOR_RED, "Server's time has been set to day time!");
return 1;
}
return 1;
}
It does not make any effect at all.
Please can somebody fix my problem and explain the reasons, thanks.

Btw, I know that I can use SetWorldTime(12) but anyway I just want to know if it possible to make it like I did.
Reply
#2

You just need to switch the function 'SendClientMessageToAll' with 'SendClientMessage' to the ID (i) because you're using a loop anyway. I've fixed it for you.

Code:
CMD:day(playerid, params[])
{
	if(PlayerInfo[playerid][pAdmin] <= 2) return SendClientMessage(playerid, COLOR_RED, "ERROR: Insufficient Permissions!");
	for(new i = 0; i < MAX_PLAYERS; i++)
	{
		SetPlayerTime(i, 12, 0);
		SendClientMessage(i, COLOR_RED, "Server's time has been set to day time!");
	}
	return 1;
}
Also, I recommend you to remember to indent your codes.
Reply
#3

Why not replacing it like this (much better than doing loop):

Code:
CMD:day(playerid, params[])
{
	if(PlayerInfo[playerid][pAdmin] <= 2) return SendClientMessage(playerid, COLOR_RED, "ERROR: Insufficient Permissions!");
	SetWorldTime(12);
        SendClientMessageToAll(COLOR_RED, "Server's time has been set to day time!");
	return 1;
}
Check it more here:
SetWorldTime
Reply
#4

This one is better, and you won't need to script the loop inside every time command.

PHP Code:
#define SetTimeForAll(0%, %1)     for(new i; i<MAX_PLAYERS; i++) { SetPlayerTime(i, 0%, %1) } 

PHP Code:
CMD:day(playeridparams[])
{
    if(
PlayerInfo[playerid][pAdmin] <= 2) return SendClientMessage(playeridCOLOR_RED"ERROR: Insufficient Permissions!");
        
SetTimeForAll(12,0);
    
SendClientMessageToAll(COLOR_RED"Server's time has been set to day time!");
    return 
1;

Reply
#5

Quote:
Originally Posted by Lucases
View Post
This one is better, and you won't need to script the loop inside every time command.

PHP Code:
#define SetTimeForAll(0%, %1)     for(new i; i<MAX_PLAYERS; i++) { SetPlayerTime(i, 0%, %1) } 

PHP Code:
CMD:day(playeridparams[])
{
    if(
PlayerInfo[playerid][pAdmin] <= 2) return SendClientMessage(playeridCOLOR_RED"ERROR: Insufficient Permissions!");
        
SetTimeForAll(12,0);
    
SendClientMessageToAll(COLOR_RED"Server's time has been set to day time!");
    return 
1;

For sure, specially since he doesn't need a loop at all for that since he has SetWorldTime(12) and SendClientMessageToAll()?

I don't recommend using a loop for that.
The default value of MAX_PLAYERS is 500 meaning that, the loop you're doing will run 500 times which is totally useless, unless you have 500 slots/players in your server.
Not only it's useless IMO, but if you have other loops running at the same time as this one, it may cause lag which is something your players wouldn't enjoy that much.

I recommend you to do this:

Quote:
Originally Posted by TomRedlake
View Post
Why not replacing it like this (much better than doing loop):

Code:
CMD:day(playerid, params[])
{
	if(PlayerInfo[playerid][pAdmin] <= 2) return SendClientMessage(playerid, COLOR_RED, "ERROR: Insufficient Permissions!");
	SetWorldTime(12);
        SendClientMessageToAll(COLOR_RED, "Server's time has been set to day time!");
	return 1;
}
Check it more here:
SetWorldTime
Reply
#6

Yes, if you aren't interested in setting minutes use "SetWorldTime( hours );"
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)