Help with some cmd's
#1

So as the title says i have created my server but i couldn't fix one thing so decided to ask on the forums..

Код:
dcmd_gzinvisible(playerid,params[])
{
   #pragma unused params
   if(CanUseGangZ[playerid] == 0)
   {
     SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You must be a Gang-Z Member to use this command.");
     return 1;
   }
   for(new i; i != MAX_PLAYERS; ++i) if (IsPlayerConnected(i)) return SetPlayerMarkerForPlayer(i, playerid, 0xFFFFFF00);
   SendClientMessage(playerid,COLOR_PURPLE,"[Gang-Z] You are now invisible on the radar.");
   return 1;
}

dcmd_gzvisible(playerid,params[])
{
   #pragma unused params
   if(CanUseGangZ[playerid] == 0)
   {
	 SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You must be a Gang-Z Member to use this command.");
	 return 1;
   }
   for(new i; i != MAX_PLAYERS; ++i) if (IsPlayerConnected(i)) return SetPlayerMarkerForPlayer(i,playerid,0xFFFFFFAA);
   SendClientMessage(playerid,COLOR_PURPLE,"[Gang-Z] You are now visible on the radar.");
   return 1;
}
These are 2 cmds made for a faction to go invisible and visible.. Now thing wrong with them is that they dont work.
Nothing Appears..Please help asap
Reply
#2

Try this
PHP код:
dcmd_gzinvisible(playerid,params[])
{
   
#pragma unused params
   
if(CanUseGangZ[playerid] == 0)
   {
     
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You must be a Gang-Z Member to use this command.");
     return 
1;
   }
   for(new 
i!= MAX_PLAYERSi++){
   if (
IsPlayerConnected(i)) return SetPlayerMarkerForPlayer(iplayerid0xFFFFFF00);
   }
   
SendClientMessage(playerid,COLOR_PURPLE,"[Gang-Z] You are now invisible on the radar.");
   return 
1;
}

dcmd_gzvisible(playerid,params[])
{
   
#pragma unused params
   
if(CanUseGangZ[playerid] == 0)
   {
     
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You must be a Gang-Z Member to use this command.");
     return 
1;
   }
   for(new 
i!= MAX_PLAYERSi++){
   if (
IsPlayerConnected(i)) return SetPlayerMarkerForPlayer(i,playerid,0xFFFFFFAA);
   }
   
SendClientMessage(playerid,COLOR_PURPLE,"[Gang-Z] You are now visible on the radar.");
   return 
1;

Reply
#3

Never use return in loops unless intended to (same goes for cuzido's code). It will stop on the first iterator and it won't loop through the rest of the players.

Another recommendation is using foreach but if you don't want to, at least use the pool size added in 0.3.7
pawn Код:
foreach(new i : Player)
// or
for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
Reply
#4

Quote:
Originally Posted by cuzido
Посмотреть сообщение
Try this
PHP код:
dcmd_gzinvisible(playerid,params[])
{
   
#pragma unused params
   
if(CanUseGangZ[playerid] == 0)
   {
     
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You must be a Gang-Z Member to use this command.");
     return 
1;
   }
   for(new 
i!= MAX_PLAYERSi++){
   if (
IsPlayerConnected(i)) return SetPlayerMarkerForPlayer(iplayerid0xFFFFFF00);
   }
   
SendClientMessage(playerid,COLOR_PURPLE,"[Gang-Z] You are now invisible on the radar.");
   return 
1;
}
dcmd_gzvisible(playerid,params[])
{
   
#pragma unused params
   
if(CanUseGangZ[playerid] == 0)
   {
     
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You must be a Gang-Z Member to use this command.");
     return 
1;
   }
   for(new 
i!= MAX_PLAYERSi++){
   if (
IsPlayerConnected(i)) return SetPlayerMarkerForPlayer(i,playerid,0xFFFFFFAA);
   }
   
SendClientMessage(playerid,COLOR_PURPLE,"[Gang-Z] You are now visible on the radar.");
   return 
1;

Not working bro.. Anyone else gonna help?
Reply
#5

Sorry I missed the returns on your loop.
Always follow what Konstantinos said.

PHP код:
dcmd_gzinvisible(playerid,params[])
{
   
#pragma unused params
   
if(CanUseGangZ[playerid] == 0)
   {
     
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You must be a Gang-Z Member to use this command.");
     return 
1;
   }
   for(new 
i!= MAX_PLAYERSi++){
      if (
IsPlayerConnected(i)) {
      
SetPlayerMarkerForPlayer(iplayerid0xFFFFFF00);
      }
   }
   
SendClientMessage(playerid,COLOR_PURPLE,"[Gang-Z] You are now invisible on the radar.");
   return 
1;
}
dcmd_gzvisible(playerid,params[])
{
   
#pragma unused params
   
if(CanUseGangZ[playerid] == 0)
   {
     
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You must be a Gang-Z Member to use this command.");
     return 
1;
   }
   for(new 
i!= MAX_PLAYERSi++){
      if (
IsPlayerConnected(i)){
      
SetPlayerMarkerForPlayer(i,playerid,0xFFFFFFAA);
      }
   }
   
SendClientMessage(playerid,COLOR_PURPLE,"[Gang-Z] You are now visible on the radar.");
   return 
1;

Reply
#6

Thanks!! Its working but there were only 2 bugs in my gamemode.. I know this is going off the title but can you help me with /kidnap too?

PHP код:
dcmd_kidnap(playerid,params[])
{
    new 
string[128];
    new 
ID;
    if(
sscanf(params"u"ID))
    {
        
SendClientMessage(playerid,COLOR_ERROR,"USAGE: /kidnap (Player Name/ID)");
        return 
1;
    }
    if(
IsSpawned[playerid] != 1)
    {
        
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You must be alive and spawned in order to be able to use this command.");
        return 
1;
    }
    if(
CommandsBlocked[playerid] == 1)
    {
        
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] Your commands are blocked, You cannot use commands.");
        return 
1;
    }
    if(
InDuel[playerid] == 1)
    {
        
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You cannot use commands while on duel, Use /leaveduel to exit the duel.");
        return 
1;
    }
    if(
IsFrozen[playerid] == 1)
    {
        
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You have been frozen by a Server Administrator. You cannot use this command.");
        return 
1;
    }
    if(
LastVehicle[playerid] == 0)
    {
        
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You must enter a vehicle before attempting to kidnap a player.");
        return 
1;
    }
    if(
InAdminMode[ID] == 1)
    {
        
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You cannot use this command on this player because they are in Administrator mode.");
        return 
1;
    }
    if(
InVIPMode[ID] == 1)
    {
        
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You cannot use this command on this player because they are in VIP mode.");
        return 
1;
    }
    if(
IsKidnapped[playerid] == 1)
    {
        
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You are kidnapped. You cannot use this command.");
        return 
1;
    }
    if(
IsKidnapped[ID] == 1)
    {
        
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] They are kidnapped. You cannot kidnap them twice.");
        return 
1;
    }
    if(
gTeam[playerid] != TEAM_KIDNAP && gTeam[playerid] != TEAM_GANGZ)
    {
        
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] Only kidnappers and GangZ members can use this command to kidnap players.");
        return 
1;
    }
    if(!
IsPlayerConnected(ID))
    {
        
format(string,sizeof(string),"[ERROR] The player ID (%d) is not connected to the server. You cannot kidnap them",ID);
        
SendClientMessage(playerid,COLOR_ERROR,string);
        return 
1;
    }
    if(
GetDistanceBetweenPlayers(playerid,ID) > 4)
    {
        
format(string,sizeof(string),"[ERROR] %s(%d) is too far away. You cannot reach him to kidnap him.",PlayerName(ID),ID);
        
SendClientMessage(playerid,COLOR_ERROR,string);
        return 
1;
    }
    if(
GetPlayerState(playerid) == PLAYER_STATE_DRIVER || GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)
    {
        
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You cannot kidnap someone while in a vehicle. Exit the vehicle first.");
        return 
1;
    }
    if(
GetPlayerState(ID) == PLAYER_STATE_DRIVER || GetPlayerState(ID) == PLAYER_STATE_PASSENGER)
    {
        
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You cannot kidnap someone while they are in a vehicle. Get them to exit the vehicle first.");
        return 
1;
    }
    if(
playerid == ID)
    {
        
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You cannot kidnap yourself, how can you even manage that?");
        return 
1;
    }
    if(
IsSpawned[ID] != 1)
    {
        
format(string,sizeof(string),"[ERROR] %s(%d) is not spawned. You cannot kidnap dead people ..",PlayerName(ID),ID);
        
SendClientMessage(playerid,COLOR_ERROR,string);
        return 
1;
    }
    if(
IsFrozen[ID] == 1)
    {
        
format(string,sizeof(string),"[ERROR] %s(%d) is frozen by a Server Administrator. You cannot kidnap them.",PlayerName(ID),ID);
        
SendClientMessage(playerid,COLOR_ERROR,string);
        return 
1;
    }
    if(
AttemptedToKidnapRecently[playerid] >= 1)
    {
        
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You are tired from your last kidnap attempt. Please wait before trying to kidnap again.");
        return 
1;
    }
    if(
HasKidnappedRecently[playerid] >= 1)
    {
        
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You are tired from your last kidnap. Please wait before kidnapping someone again.");
        return 
1;
    }
    if(
HasRope[playerid] == 0)
    {
        
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You must have rope in order to use this command. Buy one from Supa Save.");
        return 
1;
    }
    new 
crand random(100);
    if(
crand <= 30)
    {
        
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] Kidnap attempt failed. The player slipped out of your grasp.");
        
AttemptedToKidnapRecently[playerid] =60;
        return 
1;
    }
    if(
GetDistanceBetweenPlayers(playerid,ID) <= && crand 30)
    {
        new 
current_zone player_zone[playerid];
    
        
SendClientMessage(playerid,COLOR_DEADCONNECT,"[[_Kidnapped Player_]]");
        
format(string,sizeof(string),"You have grabbed %s(%d), tied them up with your rope and thrown them into your vehicle.",PlayerName(ID),ID);
        
SendClientMessage(playerid,COLOR_RED,string);
        
IncreaseWantedLevel(playerid,8);
        
HasKidnappedRecently[playerid] =300;
        
HasRope[playerid] --;
        
IncreasePlayerScore(playerid,3);
        
        
SendClientMessage(ID,COLOR_DEADCONNECT,"[[_Kidnapped_]]");
        
format(string,sizeof(string),"%s(%d) has tied you up and thrown you into their vehicle!. If you have scissors you can /cutrope.",PlayerName(playerid),playerid);
        
SendClientMessage(ID,COLOR_RED,string);
        
PutPlayerInVehicle(ID,LastVehicle[playerid],1);
        
TogglePlayerControllable(ID,0);
        
IsKidnapped[ID] =120;
        
        
format(string,sizeof(string),"[KIDNAP] %s(%d) has tied %s(%d) up and thrown them into their vehicle!",PlayerName(playerid),playerid,PlayerName(ID),ID);
        
SendClientMessageToAll(COLOR_RED,string);
        
        
format(string,sizeof(string),"[POLICE RADIO] %s(%d) has tied %s(%d) up with rope and thrown them into their vehicle! Location: %s",PlayerName(playerid),playerid,PlayerName(ID),ID,zones[current_zone][zone_name]);
        
SendClientMessageToAllCops(string);
        return 
1;
    }
    return 
1;

This says that you must enter a car before kidnaping even tho i sat in it like 100 times.
Reply
#7

When does LastVehicle[playerid] becomes anything other than 0?
Reply
#8

Err what do you mean by that? It doesn't become anything other than 0.. Its just written LastVehicle[playerid] everywhere. No 0 , 1 ,2 or any other shit..
Reply
#9

Please reply as soon as possible..
Reply
#10

What cuzido is asking is when LastVehicle[playerid] is set. If it's never set then of course the script is going to think you're not in a vehicle.

Another question is, why not just use IsPlayerInAnyVehicle?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)