#1

Guys can someone help me with making a code which allows me to add saved cars ? im really lost :c
Reply
#2

Hello.
If you want to add some car in game, you need to use AddStaticCar(modelid, Float:spawn_x, Float:spawn_y, Float:spawn_z, Float:angle, color1, color2). Also, check this link.
You have to place this under OnGameModeInit(), a public function. :)
Reply
#3

I want it as a cmd for the owner
Reply
#4

Download zcmd(include) if you are a new pawner

Код:
CMD:spawncar(playerid, params[])
// write the code
or if it is strcmp it is marked on

Код:
public OnPlayerCommandText()
{
    return 1;
}
Reply
#5

Have you already a command which spawn cars like Eymeric69 wrote ?
For a newbie pawner, create a command which is saving and loading vehicle's parameter is hard.
Try to create a simple command like this (create a vehicle at the player's coordinates by typing /v) :
First way (for, it's the best way):
PHP код:
#include <a_samp>
#include <ssanf>
#include <zcmd>
#define COLOR_RED 0xff0000FF // We define COLOR_RED as an hexadecimal color (red)
#define COLOR_GREEN 0x33cc33FF // We define COLOR_GREEN as an hexadecimal color (green)
CMD:v(playeridparams[])
{
    new 
modelFloat:xFloat:yFloat:zFloat:anglevehicleid;
    
/* 6 variables : 4 for the player's coordinates (x, y, z, angle) and 1 for the model of the vehicle and 1 for the vehicle's ID (/!\ Model =/= ID /!\)
    model is an Integer (https://en.wikipedia.org/wiki/Integer) and x, y, z and angle are float values (https://www.techopedia.com/definition/23980/float) */
    
    
if(sscanf(params"i"model)) return SendClientMessage(playeridCOLOR_GREEN"/v [model_id] [400-611]");
    
/*If the parameter 'model' isn't define by the player (ex: he type /v), we send to him a message to make him know what he should do.
    The model to be between 400-611 (Check : https://sampwiki.blast.hk/wiki/Vehicle_Model_ID_List) */
    
if(611 model || model 400) return SendClientMessage(playeridCOLOR_RED"[SYSTEM] Invalid ID [400-611]");
    
/* If the model isn't between 400-611 (ex: /v 99999, send to the player an error message) - '||' mean OR. */
    
GetPlayerPos(playeridxyz);
    
/* We store the player's coordinates into differents variables (x, y, z) */
    
GetPlayerFacingAngle(playeridangle);
     
/* We stock the facing angle in the variable Angle*/
    
vehicleid CreateVehicle(modelxyzangle, -1, -110000);
    
/* CreateVehicle(modelOfTheVehicle, Coordinate x, Coordinate y, Coordinate z, rotation of the vehicle, Primary color (-1 is random), Secondary color (-1 is random), respawn delay (in ms));
    Check this : https://sampwiki.blast.hk/wiki/CreateVehicle */
    
PutPlayerInVehicle(playeridvehicleid0);
    
/*We put the player in the vehicle at the seat 0. Why? 
    There is different seat :
    0 - Driver
    1 - Front passenger
    2 - Back-left passenger
    3 - Back-right passenger
    4+ - Passenger seats (coach etc.) */
    
SendClientMessage(playeridCOLOR_GREEN"You have been teleported!"); // We send a basic message to say the player has been teleported
    
return 1// Return 1 to terminate the command

Second way:
PHP код:
#define COLOR_RED 0xff0000FF // We define COLOR_RED as an hexadecimal color (red)
#define COLOR_GREEN 0x33cc33FF // We define COLOR_GREEN as an hexadecimal color (green)
public OnPlayerCommandText(playeridcmdtext[])
{
    new 
cmd[128], idx;
    
cmd strtok(cmdtextidx);
    if (
strcmp(cmd"/v"true) == 0// If the player type /tp than we executes those following lines
    
{
        new 
Float:xFloat:yFloat:zFloat:angletmp[128], vehicleid;
        
/* 6 variables : 4 for the player's coordinates (x, y, z, angle), 1 for the model of the vehicle and 1 for the vehicle's ID.
        model is an Integer (https://en.wikipedia.org/wiki/Integer) and x, y, z and angle are float values (https://www.techopedia.com/definition/23980/float) */
        
tmp strtok(cmdtextidx);
        if(
strlen(tmp) == 0) return SendClientMessage(playeridCOLOR_GREEN"/v [model_id] [400-611]");
        
/*If the player have just typed /v without parameter return an error message*/
        
if(611 model || model 400) return SendClientMessage(playeridCOLOR_RED"[SYSTEM] Invalid ID [400-611]");
        
/* If the model isn't between 400-611 (ex: /v 99999, send to the player an error message) - '||' mean OR. */
        
GetPlayerPos(playeridxyz);
        
/* We stock the position in differents variables (x, y, z) */
        
GetPlayerFacingAngle(playeridangle);
         
/* We stock the facing angle in the variable Angle*/
        
new vehicleid CreateVehicle(strval(temp)), xyzangle, -1, -11000);
        
/* strval(value) : convert a string to an integer
        CreateVehicle(modelOfTheVehicle, Coordinate x, Coordinate y, Coordinate z, rotation of the vehicle, Primary color (-1 is random), Secondary color (-1 is random), respawn delay (in ms));
        Link can be fin here : https://sampwiki.blast.hk/wiki/Vehicle_M...6.58910580
        We create the vehicle at the player's coordinate */
        
PutPlayerInVehicle(playeridvehicleid0);
        
/*We put the player in the vehicle at the seat 0. Why? Seat 0 = driver
        0 - Driver
        1 - Front passenger
        2 - Back-left passenger
        3 - Back-right passenger
        4+ - Passenger seats (coach etc.)*/
        
SendClientMessage(playeridCOLOR_GREEN"You have spawned an vehicle!"); // We send a basic message to say the player has been teleported
        
return 1;
    }
    return 
0;

I hope this helped you. The both command might work. If not, say it to me.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)