Anyone help me with these commands
#1

Give all cash command does work

Код:
else if(strcmp(cmdtext, "/giveallcash", true) == 0)
	{
	    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "You need to be rcon admin use /rcon login {pass}");
 		new var, string[128];
  		for(new i = 0; i < MAX_PLAYERS; i++)
			{
				if(IsPlayerConnected(i))
				{
					PlayerPlaySound(i,1057,0.0,0.0,0.0);
					GivePlayerMoney(i,var);
				}
			}
		format(string,sizeof(string)," Administrator \"%s\" has given all Players '$%d'.");
		return SendClientMessageToAll(COLOR_BLUE, string);
	}
Kicks me as well? plus does display the message before kick
Код:
else if(strcmp(cmdtext, "/kickall", true) == 0)
	{
	    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "You need to be rcon admin use /rcon login {pass}");
		for(new i = 0; i < MAX_PLAYERS; i++)
		{
		if(IsPlayerConnected(i) && (i != playerid))}
		{
		PlayerPlaySound(i,1057,0.0,0.0,0.0);
		Kick(i);
		}
		new string[128];
		format(string,sizeof(string),"[ Administrator \"%s\" has Kicked all players. ]");
		return 1;
	}
killall command kills me as well. Also it sends 100 client messages and floods my cchat.

Код:
	else if(strcmp(cmdtext, "/killall", true) == 0)
	{
		if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "You need to be rcon admin use /rcon login {pass}");
	 	for(new i = 0; i < MAX_PLAYERS; i++)
          {
          	if(IsPlayerConnected(i)) { SetPlayerHealth(i, 0); }
          	SendClientMessage(playerid, COLOR_LIGHTBLUE, "You have killed all players");
          }
   		return 1;
   }
Код:
	else if(strcmp(cmdtext, "/getall", true) == 0)
	{
		if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "You need to be rcon admin use /rcon login {pass}");
        new Float:x,Float:y,Float:z, interior = GetPlayerInterior(playerid);
		GetPlayerPos(playerid,x,y,z);
		for(new i = 0; i < MAX_PLAYERS; i++)
			{
				if(IsPlayerConnected(i) && (i != playerid))
				PlayerPlaySound(i,1057,0.0,0.0,0.0);
				SetPlayerPos(i,x+(playerid/4)+1,y+(playerid/4),z);
				SetPlayerInterior(i,interior);
			}
        SendClientMessage(playerid, COLOR_LIGHTBLUE, "You have got all players to your self");
        new string[128];
		format(string,sizeof(string)," Administrator \"%s\" has Teleported all players.");
		return 1;
	}
this command is kinda bugged i think
Reply
#2

Код:
else if(strcmp(cmdtext, "/kickall", true) == 0)
	{
	    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "You need to be rcon admin use /rcon login {pass}");
		for(new i = 0; i < MAX_PLAYERS; i++)
		{
		if(IsPlayerConnected(i) && (i != playerid))}
		{
		PlayerPlaySound(i,1057,0.0,0.0,0.0);
		Kick(i);
		}
		new string[128];
		format(string,sizeof(string),"[ Administrator \"%s\" has Kicked all players. ]");
		return 1;
	}
1. you are not getting the message cause you arent sending any, you are just formating it
PS: even if u send it at last the player wont recieve it cause you will be send the message AFTER kicking
2. it kicks you cause you are looping through all players and NOT EXCLUDING yourself
Reply
#3

Btw I suggest you to do loops like this
pawn Код:
for(new i = 0; i < GetMaxPlayers();i++)
It's faster
Reply
#4

Quote:
Originally Posted by UltraScripter
Посмотреть сообщение
Btw I suggest you to do loops like this
pawn Код:
for(new i = 0; i < GetMaxPlayers();i++)
It's faster
That still calls a function each iteration how about.

Код:
new m = GetMaxPlayers();
for(new i = 0; i < m; i++)
Reply
#5

Quote:
Originally Posted by Pottus
Посмотреть сообщение
That still calls a function each iteration how about.

Код:
new m = GetMaxPlayers();
for(new i = 0; i < m; i++)
that is same
Reply
#6

Actually GetPlayerPoolSize is the better choice. But foreach is better, still.

Quote:
Originally Posted by UltraScripter
Посмотреть сообщение
that is same
No, it is not. Your code calls GetMaxPlayers with each iteration, Pottus' code calls GetMaxPlayers once. Huge difference.

Now:
- /giveallcash: you declare var but it never gets assigned a value, hence everyone simply gets $0.
- /kickall: misplaced closing brace after the if-statement in the loop, resulting in Kick being unconditional and kicking everyone.
- /killall: no exception clause for 'playerid'. Done right in /kickall but not here. Odd.
- /getall: integer divided by integer is still integer. For example: 3 / 4 yields 0, not 0.75. Plus, if player 100 happens to be connected they will get placed 25 meters away from the originating player, quite possibly placing them outside of the interior or within buildings or other structures. It is probably the best to spawn each player in a circle around the originating player.

PHP код:
new
    
Float:x,
    
Float:y,
    
Float:z;
GetPlayerPos(playeridxyz);
new 
    
maxPlayerId GetPlayerPoolSize(),
    
Float:angleIncrement 360.0 float(maxPlayerId);
    
static const 
Float:cDistance 2.0// distance from originating player
for(new iFloat:0.0<= maxPlayerIdi++, += angleIncrement)
{
    if(
IsPlayerConnected(i) && != playerid)
    {
        
SetPlayerPos
        
(
            
i
            
+ (cDistance floatsin(-adegrees)), 
            
+ (cDistance floatcos(-adegrees)), 
            
0.25
        
);
    }

Reply
#7

kick all:
you were not checking if player id not i wrong and were not closing isplayerconnected it should be :

PHP код:
    else if(strcmp(cmdtext"/kickall"true) == 0)
    {
        if(!
IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1"You need to be rcon admin use /rcon login {pass}");
          for(new 
0MAX_PLAYERSi++)
           {
           if(
IsPlayerConnected(i) && != playerid)
            {
            
PlayerPlaySound(i,1057,0.0,0.0,0.0);
            
Kick(i);
           }
         }
        new 
string[128],pname[MAX_PLAYER_NAME+1]; GetPlayerName(playerid,pname,sizeof pname);
        
format(string,sizeof(string),"[ Administrator \"%s\" has Kicked all players. ]",pname);
        
SendClientMessageToAll(COLOR_LIGHTBLUE,string);
        return 
1;
    } 
kill all same as above you did not close isplayerconnected and you did not load player id not [ i] well, spam messages on chat cause you send a client message in a loop you should close the loop and send your message like below:

PHP код:
    else if(strcmp(cmdtext"/killall"true) == 0)
    {
        if(!
IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1"You need to be rcon admin use /rcon login {pass}");
         for(new 
0MAX_PLAYERSi++)
          {
              if(
IsPlayerConnected(i) && != playerid) { SetPlayerHealth(i0); }
          }
        
SendClientMessage(playeridCOLOR_LIGHTBLUE"You have killed all players");
           return 
1;
   } 
get all:
you did not check isplayerconnected well and you did not send message to all players you just made a format also you did not open isplayerconnected + i not player id you just closed it by : }
here we go this should work:

PHP код:
    else if(strcmp(cmdtext"/getall"true) == 0)
    {
        if(!
IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1"You need to be rcon admin use /rcon login {pass}");
        new 
Float:x,Float:y,Float:zinterior GetPlayerInterior(playerid);
        
GetPlayerPos(playerid,x,y,z);
        for(new 
0MAX_PLAYERSi++)
            {
                if(
IsPlayerConnected(i)) && != playerid) {
                
PlayerPlaySound(i,1057,0.0,0.0,0.0);
                
SetPlayerPos(i,x+(playerid/4)+1,y+(playerid/4),z);
                
SetPlayerInterior(i,interior);
            }
          }
        
SendClientMessage(playeridCOLOR_LIGHTBLUE"You have got all players to your self");
        new 
string[128],pname[MAX_PLAYER_NAME+1]; GetPlayerName(playerid,pname,sizeof pname);
        
format(string,sizeof(string)," Administrator \"%s\" has Teleported all players.",pname);
        
SendClientMessageToAll(COLOR_LIGHTBLUE,string);
        return 
1;
    } 
Reply
#8

Thanks all, im am only a beginner
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)