SA-MP Forums Archive
[Tutorial] How to make car spawning system [Good for Stunt/Freeroam] - 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)
+---- Forum: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] How to make car spawning system [Good for Stunt/Freeroam] (/showthread.php?tid=370506)



How to make car spawning system [Good for Stunt/Freeroam] - lamarr007 - 20.08.2012

How to make car spawning system
(Good for Stunt/Freeroam servers)
Hello! This is my first tutorial on sa-mp forums
In this tutorial, i will teach you, how to make good spawning vehicles system for your Stunt/Freeroam server.
Letґs start!

1) Main variable
We make variable on top of your gamemode of filterscript
pawn Code:
new SpawnedVehicle[MAX_PLAYERS];
This variable will save created vehicle for each player.

2) Spawning function
For simple and easy spawning, we create stock function, which will spawn new car for player.
pawn Code:
stock SpawnVehicleForPlayer(vehicleid, playerid)
{
    if(SpawnedVehicle[playerid] != 0)
    {
    //Check, if player spawned any vehicle
        DestroyVehicle(SpawnedVehicle[playerid]);
        //Destroy it
    }
    new Float:X, Float:Y, Float:Z, Float:Angle;
    //Variable to save playerґs X,Y,Z and angle
    GetPlayerPos(playerid, Float:X, Float:Y, Float:Z);
    //Get player positions and save it to variables
    GetPlayerFacingAngle(playerid, Float:Angle);
    //Get player facing angle and save it to variable
    SpawnedVehicle[playerid] = CreateVehicle(vehicleid, X, Y, Z + 2.0, Angle + 90.0, -1, -1, 600);
    //Spawn vehicle with random color in front of player
    SetVehicleVirtualWorld(SpawnedVehicle[playerid], GetPlayerVirtualWorld(playerid));
    //Set vehicle virtual world to player virtual world
    LinkVehicleToInterior(SpawnedVehicle[playerid], GetPlayerInterior(playerid));
    //Set vehicle interior to player interior
    PutPlayerInVehicle(playerid, SpawnedVehicle[playerid], 0);
    //Put player to spawned vehicle as driver
}
Then, you can simply make command like:
(Using ZCMD (by Zeex) | If you donґt know, how to use it go HERE (tutorial by Gangs_Rocks))
pawn Code:
CMD:nrg500(playerid, params[])
{
    SpawnVehicleForPlayer(522, playerid);
    //Spawn and put player in NRG-500 with our function
    SendClientMessage(playerid, 0xFF0080C8, "*You spawned NRG-500!*");
    //Send info message
    return 1;
}
3) Destroy command
If player want to destroy his vehicle, we make simple command to do this:
pawn Code:
CMD:destroy(playerid, params[])
{
    if(SpawnedVehicle[playerid] == 0) return SendClientMessage(playerid, 0xFF0000C8, "*Error: You must create a vehicle!*");
    //Check, if player created any vehicle
    DestroyVehicle(SpawnedVehicle[playerid]);
    //Destroy player vehicle
    SpawnedVehicle[playerid] = 0;
    //Set vehicle to null
    SendClientMessage(playerid, 0x80FF00C8, "*Your vehicle has been deleted*");
    //Send info message
    return 1;
}
4) Lock and unlock player vehicle
At last, we make simple commands to lock and unlock player created vehicle.
pawn Code:
CMD:lock(playerid, params[])
{
    if(SpawnedVehicle[playerid] == 0) return SendClientMessage(playerid, 0xFF0000C8, "*Error: You must create a vehicle!*");
    //Check, if player created any vehicle
    if(GetPlayerVehicleID(playerid) != SpawnedVehicle[playerid]) return SendClientMessage(playerid, 0xFF0000C8, "*Error: You must be in your vehicle!*");
    //Check, if player is in his vehicle
    for(new i=0; i < MAX_PLAYERS; i++)
    {
    //For each players on server
        if(i != playerid)
        {
            SetVehicleParamsForPlayer(SpawnedVehicle[playerid], i, 0, 1);
            //Lock doors
        }
    }
    return 1;
}
pawn Code:
CMD:unlock(playerid, params[])
{
    if(SpawnedVehicle[playerid] == 0) return SendClientMessage(playerid, 0xFF0000C8, "*Error: You must create a vehicle!*");
    //Check, if player created any vehicle
    if(GetPlayerVehicleID(playerid) != SpawnedVehicle[playerid]) return SendClientMessage(playerid, 0xFF0000C8, "*Error: You must be in your vehicle!*");
    //Check, if player is in his vehicle
    for(new i=0; i < MAX_PLAYERS; i++)
    //For each players on server
    {
        if(i != playerid)
        {
            SetVehicleParamsForPlayer(SpawnedVehicle[playerid], i, 0, 0);
            //Unlock doors
        }
    }
    return 1;
}
Thanks you for watching my tutorial
And sorry for my bad



Re: How to make car spawning system [Good for Stunt/Freeroam] - Sinner - 20.08.2012

Edit: nevermind


Re: How to make car spawning system [Good for Stunt/Freeroam] - lamarr007 - 20.08.2012

?? heh


Re: How to make car spawning system [Good for Stunt/Freeroam] - Toxik - 23.02.2014

THAT NOT GOD SORRY

EDIT IT