SA-MP Forums Archive
Spawning car rows in front of the player - 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: Spawning car rows in front of the player (/showthread.php?tid=348246)



Spawning car rows in front of the player - MarinacMrcina - 04.06.2012

I made this code which should spawn the cars in fornt of the player. The problem is that cars spawn corectly only when the player is facing north or south.
pawn Код:
CMD:eveh(playerid, params[])
{
    new vehid;
    if(sscanf(params, "i", vehid)) SendClientMessage(playerid, Red, Use: /eveh <car id>");
    else
    {
        new Float:x, Float:y, Float:z;new Float:angle;
        GetPlayerFacingAngle(playerid,angle);
        GetPlayerPos(playerid, x, y, z);
        CreateVehicle(vehid, x + 5, y +2, z, angle-180, 1,1, 60000);
        CreateVehicle(vehid, x + 5, y -2, z, angle-180, 2,2, 60000);
       
        CreateVehicle(vehid, x + 11, y +2, z, angle-180, 3,3, 60000);
        CreateVehicle(vehid, x + 11, y -2, z, angle-180, 4,4, 60000);
       
        CreateVehicle(vehid, x + 17, y +2, z, angle-180, 5,5, 60000);
        CreateVehicle(vehid, x + 17, y -2, z, angle-180, 6,6, 60000);
       
    }
    return 1;
}
I will draw you to explaint better




Re: Spawning car rows in front of the player - ViniBorn - 04.06.2012

https://sampforum.blast.hk/showthread.php?tid=344951


Re: Spawning car rows in front of the player - MarinacMrcina - 04.06.2012

Quote:
Originally Posted by Viniborn
Посмотреть сообщение
This is a little too hard for me to understand,can you please explain it to me? +REP


Re: Spawning car rows in front of the player - iggy1 - 05.06.2012

pawn Код:
CMD:eveh(playerid, params[])
{
    new vehid;
   
    if(sscanf(params, "i", vehid)) SendClientMessage(playerid, Red, "Use: /eveh <car id>");
    else
    {
        new
            Float:x, Float:y, Float:z, Float: a;
           
        GetPlayerFacingAngle(playerid, a);
       
        //second parameter is distance, use negative velue to get pos behind playerid
        GetXYZInFrontOfPlayer(playerid, 2, x, y, z);
       
        CreateVehicle(vehid, x , y , z, a-180, 1,1, 60000);
        CreateVehicle(vehid, x , y , z, a-180, 2,2, 60000);
       
        GetXYZInFrontOfPlayer(playerid, 11, x, y, z);

        CreateVehicle(vehid, x, y , z, a-180, 3,3, 60000);
        CreateVehicle(vehid, x, y , z, a-180, 4,4, 60000);
       
        GetXYZInFrontOfPlayer(playerid, 17, x, y, z);

        CreateVehicle(vehid, x, y, z, a-180, 5,5, 60000);
        CreateVehicle(vehid, x, y, z, a-180, 6,6, 60000);

    }
    return 1;
}

stock TE::GetXYZInFrontOfPlayer(playerid, Float:range, &Float:x, &Float:y, &Float:z)
{
    new
        Float:fPX, Float:fPY, Float:fPZ,
        Float:fVX, Float:fVY, Float:fVZ;
    GetPlayerCameraPos(playerid, fPX, fPY, fPZ);
    GetPlayerCameraFrontVector(playerid, fVX, fVY, fVZ);
    x = fPX + floatmul(fVX, range);
    y = fPY + floatmul(fVY, range);
    z = fPZ + floatmul(fVZ, range);
}
EDIT: I'm not sure about distances they may be too far away or too close together (i used your numbers). The respawn time for vehicles is done in seconds, so your making those vehicles respawn after 60000 (16 hours and 40 minutes). If you don't want them to respawn use -1 as respawn time parameter.