Script doesn't execute a sendclientmessage
#1

title.
This is my code:
PHP код:
        else if(!strcmp(tmp"list"true5))
        {
            new 
iBigStr[386];
               
SendClientMessage(playerid, -1"{3696EB}________________________________________________________________________");
               for(new 
1sizeof(Vehicle); i++)
                {
                           if(!
strcmp(Vehicle[i][vOwner], Name(playerid), false))
                        {
                            new 
zone80 ], Float:vipos[3], lockstr[10];
                            if(
Vehicle[i][tmplocked]) myStrcpy(lockstr"Yes");
                            else 
myStrcpy(lockstr"No");
                            
GetVehiclePos(ivipos[0], vipos[1], vipos[2]);
                            
GetZone(vipos[0], vipos[1], vipos[2], zone);
                             
format(iBigStrsizeof(iBigStr), "{bebaba}(ID %d) {51983e}%s [Location: {bebaba}%s{51983e}] [Locked: {bebaba}%s{51983e}]"iGetVehicleName(i), zonelockstr);
                            
SendClientMessage(playerid, -1iBigStr);
                        }
                        else return 
1;
                }
            
SendClientMessage(playerid, -1"{3696EB}________________________________________________________________");
        } 
it doesn't execute this:
PHP код:
        else if(!strcmp(tmp"list"true5))
        {
            new 
iBigStr[386];
               
SendClientMessage(playerid, -1"{3696EB}________________________________________________________________________");
               for(new 
1sizeof(Vehicle); i++)
                {
                           if(!
strcmp(Vehicle[i][vOwner], Name(playerid), false))
                        {
                            new 
zone80 ], Float:vipos[3], lockstr[10];
                            if(
Vehicle[i][tmplocked]) myStrcpy(lockstr"Yes");
                            else 
myStrcpy(lockstr"No");
                            
GetVehiclePos(ivipos[0], vipos[1], vipos[2]);
                            
GetZone(vipos[0], vipos[1], vipos[2], zone);
                             
format(iBigStrsizeof(iBigStr), "{bebaba}(ID %d) {51983e}%s [Location: {bebaba}%s{51983e}] [Locked: {bebaba}%s{51983e}]"iGetVehicleName(i), zonelockstr);
                            
SendClientMessage(playerid, -1iBigStr);
                        }
                        else return 
1;
                }
// THIS            SendClientMessage(playerid, -1, "{3696EB}________________________________________________________________");
        

Why is that?
Reply
#2

Don't return inside loops unless you explicitly want to break them.
Reply
#3

Quote:
Originally Posted by Vince
Посмотреть сообщение
Don't return inside loops unless you explicitly want to break them.
But if i don't do that, it shows: SERVER: Unknown command after executing the command successfully
Reply
#4

Return after the loop, after the message that isn't displayed. Also if the very first vehicle in the list isn't owned by you then the loop will just stop on the first iteration and the only thing you will see is the first horizontal rule and nothing else.
Reply
#5

Quote:
Originally Posted by Vince
Посмотреть сообщение
Return after the loop, after the message that isn't displayed. Also if the very first vehicle in the list isn't owned by you then the loop will just stop on the first iteration and the only thing you will see is the first horizontal rule and nothing else.
I am returning it after the loop.

My code right now:

PHP код:
        else if(!strcmp(tmp"list"true5))
        {
            new 
iBigStr[386];
               
SendClientMessage(playerid, -1"{3696EB}________________________________________________________________________");
               
SendClientMessage(playerid, -1sprintf("{D4D4D4}[VEHICLES] {ffffff}%s{D4D4D4}'s vehicles: ",Name(playerid)));
               for(new 
1sizeof(Vehicle); i++)
                {
                           if(!
strcmp(Vehicle[i][vOwner], Name(playerid), false))
                        {
                            new 
zone80 ], Float:vipos[3], lockstr[10];
                            if(
Vehicle[i][tmplocked]) myStrcpy(lockstr"Yes");
                            else 
myStrcpy(lockstr"No");
                            
GetVehiclePos(ivipos[0], vipos[1], vipos[2]);
                            
GetZone(vipos[0], vipos[1], vipos[2], zone);
                             
format(iBigStrsizeof(iBigStr), "{bebaba}(ID %d) {51983e}%s [Location: {bebaba}%s{51983e}] [Locked: {bebaba}%s{51983e}]"iGetVehicleName(i), zonelockstr);
                            
SendClientMessage(playerid, -1iBigStr);
                        }
                }
            
SendClientMessage(playerid, -1"{3696EB}________________________________________________________________");
           } 
output:
Reply
#6

PHP код:
return 1
In the last line after the last SendClientMessage
Reply
#7

Run time error 4 for accessing negative index (-400) because the vehicle does not exist and you are trying to retrieve its name.

Since the vehicle ID is index for the vehicle array, you do not need to loop 2000 times - use the vehicle pools:
pawn Код:
for(new i = 1, j = GetVehiclePoolSize(); i <= j; i++)
{
    if (!GetVehicleModel(i)) continue; // if the vehicle does not exist, skip the iterator
    if(!strcmp(Vehicle[i][vOwner], Name(playerid), false))
    {
        ...
    }
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)