PDA

View Full Version : Help


Xdrime
09/05/2016, 05:44 PM
Guys can someone help me with making a code which allows me to add saved cars ? ????????? im really lost :c

Dayrion
09/05/2016, 06:54 PM
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 (https://wiki.sa-mp.com/wiki/AddStaticVehicle).
You have to place this under OnGameModeInit(), a public function. :)

Xdrime
10/05/2016, 10:09 AM
I want it as a cmd for the owner :(

Eymeric69
10/05/2016, 11:17 AM
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;
}

Dayrion
10/05/2016, 12:27 PM
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):

#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(playerid, params[])
{
new model, Float:x, Float:y, Float:z, Float:angle, vehicleid;
/* 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(playerid, COLOR_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://wiki.sa-mp.com/wiki/Vehicle_Model_ID_List) */

if(611 > model || model < 400) return SendClientMessage(playerid, COLOR_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(playerid, x, y, z);
/* We store the player's coordinates into differents variables (x, y, z) */

GetPlayerFacingAngle(playerid, angle);
/* We stock the facing angle in the variable Angle*/

vehicleid = CreateVehicle(model, x, y, z, angle, -1, -1, 10000);
/* 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://wiki.sa-mp.com/wiki/CreateVehicle */

PutPlayerInVehicle(playerid, vehicleid, 0);
/*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(playerid, COLOR_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:

#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(playerid, cmdtext[])
{
new cmd[128], idx;
cmd = strtok(cmdtext, idx);

if (strcmp(cmd, "/v", true) == 0) // If the player type /tp than we executes those following lines
{
new Float:x, Float:y, Float:z, Float:angle, tmp[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(cmdtext, idx);

if(strlen(tmp) == 0) return SendClientMessage(playerid, COLOR_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(playerid, COLOR_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(playerid, x, y, z);
/* We stock the position in differents variables (x, y, z) */

GetPlayerFacingAngle(playerid, angle);
/* We stock the facing angle in the variable Angle*/

new vehicleid = CreateVehicle(strval(temp)), x, y, z, angle, -1, -1, 1000);
/* 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://wiki.sa-mp.com/wiki/Vehicle_Model_ID_List
We create the vehicle at the player's coordinate */

PutPlayerInVehicle(playerid, vehicleid, 0);
/*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(playerid, COLOR_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.