SA-MP Forums Archive
Help? - 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: Help? (/showthread.php?tid=596712)



Help? - Banditul18 - 21.12.2015

Heloo i need help with a cmd:
Код:
CMD:respawnall(playerid,params[])
{
	new string[128];
        if(APlayerData[playerid][PlayerLevel] < 4) return SendClientMessage(playerid, 0xFF0000FF, "Nu ai level neceasr!");
        for(new car = 1; car <= 1999; car++)
        {
                if(IsVehicleEmpty(car)) SetVehicleToRespawn(car);
        }
        //GetPlayerName(playerid, sendername, sizeof(sendername));
        format(string, sizeof(string), "Adminul %s a respawnat toate masinile.", pName(playerid));
        SendClientMessageToAll(COLOR_ROYALBLUE,string);
        return 1;
}
 
stock IsVehicleEmpty(vehicleid)
{
        for(new i=0; i<MAX_PLAYERS; i++)
        {
                if(IsPlayerInVehicle(i, vehicleid)) return 0;
        }
        return 1;
}
How I can make it to not respawn trailers who is in use?Beacuse this respawn and trailers who attached to a truck


Re: Help? - Mencent - 21.12.2015

Hello!

Here you are. Look, what I changed.

PHP код:
CMD:respawnall(playerid,params[])
{
    new 
string[145];
    if(
APlayerData[playerid][PlayerLevel] < 4)return SendClientMessage(playerid0xFF0000FF"Nu ai level neceasr!");
    for(new 
car=1;car<=1999;car++)
    {
        if(
GetVehicleTrailer(car) > 0)continue;
        if(
IsVehicleEmpty(car)) SetVehicleToRespawn(car);
    }
    
//GetPlayerName(playerid, sendername, sizeof(sendername));
     
format(stringsizeof(string), "Adminul %s a respawnat toate masinile."pName(playerid));
     
SendClientMessageToAll(COLOR_ROYALBLUE,string);
     return 
1;




Re: Help? - Banditul18 - 22.12.2015

It doesn't work, keep respawn the trailer which is attached , but now make little lag


Re: Help? - itsCody - 22.12.2015

Use https://sampwiki.blast.hk/wiki/IsTrailerAttachedToVehicle

Should solve your issue.


Re: Help? - X337 - 22.12.2015

Quote:
Originally Posted by itsCody
Посмотреть сообщение
That function just check if a vehicle has a trailer attached.

You need to loop through every vehicle to see if the trailer is attached.
Use this custom function :
Код:
CMD:respawnall(playerid,params[])
{
	new string[128], vmod;
        if(APlayerData[playerid][PlayerLevel] < 4) return SendClientMessage(playerid, 0xFF0000FF, "Nu ai level neceasr!");
        for(new car = 0; car <= GetVehiclePoolSize(); car++)
        {
                vmod = GetVehicleModel(car);
                if(vmod == 435 || vmod == 450 || vmod == 584) // Check if it's a trailer
                {
                        if(!IsTrailerAttached(car))
                                SetVehicleToRespawn(car)
                }
                else
                        if(IsVehicleEmpty(car)) SetVehicleToRespawn(car);
        }
        //GetPlayerName(playerid, sendername, sizeof(sendername));
        format(string, sizeof(string), "Adminul %s a respawnat toate masinile.", pName(playerid));
        SendClientMessageToAll(COLOR_ROYALBLUE,string);
        return 1;
}
 
stock IsVehicleEmpty(vehicleid)
{
        for(new i=0; i<MAX_PLAYERS; i++)
        {
                if(IsPlayerInVehicle(i, vehicleid)) return 0;
        }
        return 1;
}

stock IsTrailerAttached(trailerid)
{
        for(new i = 0; i <= GetVehiclePoolSize(); i++)
        {
                if(GetVehicleTrailer(i) == trailerid) // Check if this trailer attached to another vehicle
                {
                        return true;
                }
        }
        return false;
}



Re: Help? - itsCody - 22.12.2015

Quote:
Originally Posted by X337
Посмотреть сообщение
That function just check if a vehicle has a trailer attached.

You need to loop through every vehicle to see if the trailer is attached.
Well, he was saying that every vehicle (including attached trailers) were being respawned. So using that to check if it's attached to a vehicle won't make the trailer respawn.


Re: Help? - X337 - 22.12.2015

Quote:
Originally Posted by itsCody
Посмотреть сообщение
Well, he was saying that every vehicle (including attached trailers) were being respawned. So using that to check if it's attached to a vehicle won't make the trailer respawn.
That function is to check if a vehicle has a trailer attached.
Not to check if a trailer is attached to vehicle.


Re: Help? - Banditul18 - 22.12.2015

Thanks alot @X337 , it's worked