what wrong with this script?!
#1

hey

i write it for use megaphone when player is cop and sit in police vehicles


Код HTML:
CMD:m(playerid,params[])
{
	new text[128],carid = GetPlayerVehicleID(playerid);
	for(new tt = 0; tt < sizeof police_vehicles; tt++)
	if(gTeam[playerid] == Police && carid == police_vehicles[tt])
	{
    if(sscanf(params,"s[128]",text))
	{
	SendClientMessage(playerid,white,"Usage: /m [text]");
	return 1;
	}
	for(new i = 0; i < MAX_PLAYERS; i++)
    {
    new Float:tx,Float:ty,Float:tz;
    GetPlayerPos(i,tx,ty,tz);
	new Float: pdistance = GetPlayerDistanceFromPoint(i,tx,ty,tz);
    if(IsPlayerConnected(i))
    if(pdistance < 8.0)
    {
    SendClientMessage(i, white, text);
	return 1;
    }
    }
	}
	else
	{
	SendClientMessage(playerid,white,"You must be on Police Duty and sit in Police Vehicle");
	return 1;
	}
	return 1;
	
}
when im not in car or pd vehicles it say You must be on Police Duty and sit in Police Vehicle
but when i be cop and sit in pd vehicles it say You must be on Police Duty and sit in Police Vehicle!

whats my wrong move?
Reply
#2

Код:
CMD:m(playerid,params[])
{
	new text[128],carid = GetPlayerVehicleID(playerid);
	for(new tt = 0; tt < sizeof police_vehicles; tt++)
	if(gTeam[playerid] == Police && carid == police_vehicles[tt])
	{
    if(sscanf(params,"s[128]",text))
	{
	SendClientMessage(playerid,white,"Usage: /m [text]");
	return 1;
	}
	for(new i = 0; i < MAX_PLAYERS; i++)
    {
    new Float:tx,Float:ty,Float:tz;
    GetPlayerPos(i,tx,ty,tz);
	new Float: pdistance = GetPlayerDistanceFromPoint(i,tx,ty,tz);
    if(IsPlayerConnected(i))
    if(pdistance < 8.0)
    {
    SendClientMessage(i, white, text);
    }
    }
	}
	else
	{
	 return SendClientMessage(playerid,white,"You must be on Police Duty and sit in Police Vehicle");
	}
	return 1;
	
}
Reply
#3

pawn Код:
CMD:m(playerid,params[])
{
    new text[128], carid = GetPlayerVehicleID(playerid);
   
    for(new tt = 0; tt < sizeof police_vehicles; tt++)
   
    if(gTeam[playerid] == TEAM_POLICE && carid == police_vehicles[tt])
    {
        if(sscanf(params,"s[128]",text)) return SendClientMessage(playerid,white,"Usage: /m [text]");
   
        foreach (new i : Player)
    {
        new Float:tx,Float:ty,Float:tz;
        GetPlayerPos(i,tx,ty,tz);
       
        new Float: pdistance = GetPlayerDistanceFromPoint(i,tx,ty,tz);
        if(pdistance < 8.0) SendClientMessage(i, white, text);
    }
   
    }
    else
    {
        return SendClientMessage(playerid,white,"You must be on Police Duty and sit in Police Vehicle");
    }
    return 1;

}
I don't know how are you using gTeam but it should be "TEAM_POLICE" and not just "Police". Also use foreach for loops.

And, your code is a mess.
Reply
#4

Quote:
Originally Posted by Onfroi
Посмотреть сообщение
Код:
CMD:m(playerid,params[])
{
	new text[128],carid = GetPlayerVehicleID(playerid);
	for(new tt = 0; tt < sizeof police_vehicles; tt++)
	if(gTeam[playerid] == Police && carid == police_vehicles[tt])
	{
    if(sscanf(params,"s[128]",text))
	{
	SendClientMessage(playerid,white,"Usage: /m [text]");
	return 1;
	}
	for(new i = 0; i < MAX_PLAYERS; i++)
    {
    new Float:tx,Float:ty,Float:tz;
    GetPlayerPos(i,tx,ty,tz);
	new Float: pdistance = GetPlayerDistanceFromPoint(i,tx,ty,tz);
    if(IsPlayerConnected(i))
    if(pdistance < 8.0)
    {
    SendClientMessage(i, white, text);
    }
    }
	}
	else
	{
	 return SendClientMessage(playerid,white,"You must be on Police Duty and sit in Police Vehicle");
	}
	return 1;
	
}
this work but after text server say You must be on Police Duty and sit in Police Vehicle!!!!!!!!!!
Reply
#5

Quote:
Originally Posted by SymonClash
Посмотреть сообщение
pawn Код:
CMD:m(playerid,params[])
{
    new text[128], carid = GetPlayerVehicleID(playerid);
   
    for(new tt = 0; tt < sizeof police_vehicles; tt++)
   
    if(gTeam[playerid] == TEAM_POLICE && carid == police_vehicles[tt])
    {
        if(sscanf(params,"s[128]",text)) return SendClientMessage(playerid,white,"Usage: /m [text]");
   
        foreach (new i : Player)
    {
        new Float:tx,Float:ty,Float:tz;
        GetPlayerPos(i,tx,ty,tz);
       
        new Float: pdistance = GetPlayerDistanceFromPoint(i,tx,ty,tz);
        if(pdistance < 8.0) SendClientMessage(i, white, text);
    }
   
    }
    else
    {
        return SendClientMessage(playerid,white,"You must be on Police Duty and sit in Police Vehicle");
    }
    return 1;

}
I don't know how are you using gTeam but it should be "TEAM_POLICE" and not just "Police". Also use foreach for loops.

And, your code is a mess.
its not about Police or TEAM_POLICE
gTeam == Police work fine


about your code it replay like first think i say

You must be on Police Duty and sit in Police Vehicle
Reply
#6

Exactly, indent your code to understand better the problem. I seriously don't understand how can you guys script with that bad indentation without getting a headache after 5 minutes.

A TIP: Instead of looping for all police vehicles, just check them by id, without doing a single loop. (EG: 497 - 596).

Unless you have personal vehicles created, no need to make a loop where you can just check by vehicle ID.

pawn Код:
CMD:m(playerid,params[])
{
    new text[128], carid = GetPlayerVehicleID(playerid);

    if(gTeam[playerid] == TEAM_POLICE)
    {
        switch(carid)
        {
            case 497, 596:
            {
                if(sscanf(params,"s[128]",text)) return SendClientMessage(playerid,white,"Usage: /m [text]");

                foreach (new i : Player)
            {
                new Float:tx,Float:ty,Float:tz;
                GetPlayerPos(i,tx,ty,tz);

                new Float: pdistance = GetPlayerDistanceFromPoint(i,tx,ty,tz);
                if(pdistance < 8.0) SendClientMessage(i, white, text);
            }
            }
        }
    }
    else
    {
        return SendClientMessage(playerid,white,"You must be on Police Duty and sit in Police Vehicle");
    }
    return 1;

}
Not tested.
Reply
#7

Quote:
Originally Posted by ******
Посмотреть сообщение
Indent your code, then the statements and logic will be much clearer.
Quote:
Originally Posted by SymonClash
Посмотреть сообщение
Exactly, indent your code to understand better the problem. I seriously don't understand how can you guys script with that bad indentation without getting a headache after 5 minutes.

A TIP: Instead of looping for all police vehicles, just check them by id, without doing a single loop. (EG: 497 - 596).

Unless you have personal vehicles created, no need to make a loop where you can just check by vehicle ID.

pawn Код:
CMD:m(playerid,params[])
{
    new text[128], carid = GetPlayerVehicleID(playerid);

    if(gTeam[playerid] == TEAM_POLICE)
    {
        switch(carid)
        {
            case 497, 596:
            {
                if(sscanf(params,"s[128]",text)) return SendClientMessage(playerid,white,"Usage: /m [text]");

                foreach (new i : Player)
            {
                new Float:tx,Float:ty,Float:tz;
                GetPlayerPos(i,tx,ty,tz);

                new Float: pdistance = GetPlayerDistanceFromPoint(i,tx,ty,tz);
                if(pdistance < 8.0) SendClientMessage(i, white, text);
            }
            }
        }
    }
    else
    {
        return SendClientMessage(playerid,white,"You must be on Police Duty and sit in Police Vehicle");
    }
    return 1;

}
Not tested.
yes you say right
now i check and retry it
Reply
#8

Quote:
Originally Posted by SymonClash
Посмотреть сообщение
Exactly, indent your code to understand better the problem. I seriously don't understand how can you guys script with that bad indentation without getting a headache after 5 minutes.

A TIP: Instead of looping for all police vehicles, just check them by id, without doing a single loop. (EG: 497 - 596).

Unless you have personal vehicles created, no need to make a loop where you can just check by vehicle ID.

pawn Код:
CMD:m(playerid,params[])
{
    new text[128], carid = GetPlayerVehicleID(playerid);

    if(gTeam[playerid] == TEAM_POLICE)
    {
        switch(carid)
        {
            case 497, 596:
            {
                if(sscanf(params,"s[128]",text)) return SendClientMessage(playerid,white,"Usage: /m [text]");

                foreach (new i : Player)
            {
                new Float:tx,Float:ty,Float:tz;
                GetPlayerPos(i,tx,ty,tz);

                new Float: pdistance = GetPlayerDistanceFromPoint(i,tx,ty,tz);
                if(pdistance < 8.0) SendClientMessage(i, white, text);
            }
            }
        }
    }
    else
    {
        return SendClientMessage(playerid,white,"You must be on Police Duty and sit in Police Vehicle");
    }
    return 1;

}
Not tested.
its dont work bro
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)