SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 15/11/2017, 07:28 PM   #1
rakinz
Little Clucker
 
Join Date: Oct 2016
Posts: 44
Reputation: 0
Question not stopping return a cmd

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.
rakinz is offline   Reply With Quote
Old 15/11/2017, 07:42 PM   #2
Jaxium
Little Clucker
 
Join Date: Nov 2017
Location: Egypt
Posts: 11
Reputation: 1
Default Re: not stopping return a cmd

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.
Jaxium is offline   Reply With Quote
Old 15/11/2017, 08:41 PM   #3
TomRedlake
Big Clucker
 
TomRedlake's Avatar
 
Join Date: Feb 2013
Location: Croatia
Posts: 139
Reputation: 6
Default Re: not stopping return a cmd

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
__________________
TomRedlake is offline   Reply With Quote
Old 15/11/2017, 08:42 PM   #4
Lucases
Huge Clucker
 
Join Date: Jul 2017
Posts: 216
Reputation: 11
Default Re: not stopping return a cmd

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;

Lucases is offline   Reply With Quote
Old 15/11/2017, 08:54 PM   #5
Andre02
Huge Clucker
 
Join Date: Jan 2014
Location: France
Posts: 314
Reputation: 44
Default Re: not stopping return a cmd

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
__________________
Quote:
A person who never made a mistake never tried anything new!
Andre02 is offline   Reply With Quote
Old 15/11/2017, 08:57 PM   #6
Lucases
Huge Clucker
 
Join Date: Jul 2017
Posts: 216
Reputation: 11
Default Re: not stopping return a cmd

Yes, if you aren't interested in setting minutes use "SetWorldTime( hours );"
Lucases is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
continue and return 0 and return 1 and break work? MBilal Scripting Help 7 15/05/2016 08:12 AM
How to return a string variable using the multi-return method? Juvanii Scripting Help 7 04/03/2016 09:32 PM
What's the diffrences between Return True and Return False davidstyle1125 Scripting Help 4 09/12/2014 08:34 PM
What's stopping me? WarriorEd22 Scripting Help 4 09/05/2012 02:54 AM
Stopping animation without stopping the player Johndaonee Scripting Help 1 30/12/2011 06:53 PM


All times are GMT. The time now is 12:26 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.