SA-MP Forums Archive
Script doesn't execute a sendclientmessage - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Script doesn't execute a sendclientmessage (/showthread.php?tid=614811)



Script doesn't execute a sendclientmessage - justjamie - 13.08.2016

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?


Re: Script doesn't execute a sendclientmessage - Vince - 13.08.2016

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


Re: Script doesn't execute a sendclientmessage - justjamie - 13.08.2016

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


Re: Script doesn't execute a sendclientmessage - Vince - 13.08.2016

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.


Re: Script doesn't execute a sendclientmessage - justjamie - 13.08.2016

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:



Re: Script doesn't execute a sendclientmessage - Shinja - 13.08.2016

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


Re: Script doesn't execute a sendclientmessage - Konstantinos - 13.08.2016

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))
    {
        ...
    }
}