How to creat a vehicle with ZCMD+sscanf
#1

How to creat a vehicle with ZCMD+sscanf?
Hello everybody, i want to creat a car with it, but how?

this is my code.

Код:
CMD:acar(playerid, params[])
{
    if(gPlayerLogged[playerid] == 0) return SendClientMessage(playerid, COLOR_GREY, "[提示]此命令无法在不登陆的情况下使用。");
    if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_GREY, "[提示]此命令无法在车内使用。");
	new vid;
	if(sscanf(params, "u", vid)) return SendClientMessage(playerid, COLOR_GREY, "[提示]使用方法:/acar (vid)");
	if(vid < 400 || vid > 600) return SendClientMessage(playerid, COLOR_GREY, "[提示]无效的车辆ID,请查阅Wiki。");
	new Float:x, Float:y, Float:z;
	GetPlayerPos(playerid, x, y, z);
	CreateVehicle(vid, x, y, z, 0, 0, 0, 0);
	return 1;
}
my code cant run, if you add it in a FS, this FS is invalid.
Reply
#2

pawn Код:
CMD:acar(playerid, params[])
{
    if(gPlayerLogged[playerid] == 0) return SendClientMessage(playerid, COLOR_GREY, "[提示]此命令无法在不登陆的情况下使用。");
    if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_GREY, "[提示]此命令无法在车内使用。");
    new vid;
    if(sscanf(params, "i", vid)) return SendClientMessage(playerid, COLOR_GREY, "[提示]使用方法:/acar (vid)");
    if(vid < 400 || vid > 600) return SendClientMessage(playerid, COLOR_GREY, "[提示]无效的车辆ID,请查阅Wiki。");
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
    CreateVehicle(vid, x, y, z, 0, 0, 0, 0);
    return 1;
}
"u" is used for player-based commands, "u" = user, I suggest you check the sscanf documentation.

Quote:

This forum requires that you wait 120 seconds between posts. Please try again in 21 seconds.

God damn...
Reply
#3

This is ok but it will create the vehicle at the players positions and that can be annoying. So here is what i did:

pawn Код:
{
    if(gPlayerLogged[playerid] == 0) return SendClientMessage(playerid, COLOR_GREY, "[提示]此命令无法在不登陆的情况下使用。");
    if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_GREY, "[提示]此命令无法在车内使用。");
    new vid;
    if(sscanf(params, "i", vid)) return SendClientMessage(playerid, COLOR_GREY, "[提示]使用方法:/acar (vid)");
    if(vid < 400 || vid > 600) return SendClientMessage(playerid, COLOR_GREY, "[提示]无效的车辆ID,请查阅Wiki。");
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
    CreateVehicle(vid, x+2, y, z+2, 0, 0, 0, 0);
    return 1;
}
I just added +2 to x and z. That should create the vehicle further from the player.
Reply
#4

Quote:
Originally Posted by Tee
Посмотреть сообщение
This is ok but it will create the vehicle at the players positions and that can be annoying. So here is what i did:

pawn Код:
{
    if(gPlayerLogged[playerid] == 0) return SendClientMessage(playerid, COLOR_GREY, "[提示]此命令无法在不登陆的情况下使用。");
    if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_GREY, "[提示]此命令无法在车内使用。");
    new vid;
    if(sscanf(params, "i", vid)) return SendClientMessage(playerid, COLOR_GREY, "[提示]使用方法:/acar (vid)");
    if(vid < 400 || vid > 600) return SendClientMessage(playerid, COLOR_GREY, "[提示]无效的车辆ID,请查阅Wiki。");
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
    CreateVehicle(vid, x+2, y, z+2, 0, 0, 0, 0);
    return 1;
}
I just added +2 to x and z. That should create the vehicle further from the player.
Instead of that they could inject a code
PutPlayerInVehicle(playerid, vid);
I'm pretty sure theres another parameter I'm missing
Reply
#5

Quote:
Originally Posted by Lorenc_
Посмотреть сообщение
Instead of that they could inject a code
PutPlayerInVehicle(playerid, vid);
I'm pretty sure theres another parameter I'm missing
Yup, just put them in seatid zero.

pawn Код:
PutPlayerInVehicle(playerid, vid, 0);
Reply
#6

Thanks all of you for helping me to solve the question.
now i can run it !
Reply
#7

I write it again.
Код:
CMD:acar(playerid, params[])
{
    if(gPlayerLogged[playerid] == 0) return SendClientMessage(playerid, COLOR_GREY, "[提示]此命令无法在不登陆的情况下使用。");
    if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_GREY, "[提示]此命令无法在车内使用。");
	new vid, vcar;
	if(sscanf(params, "i", vid)) return SendClientMessage(playerid, COLOR_GREY, "[提示]使用方法:/acar (vid)");
	if(vid < 400 || vid > 600) return SendClientMessage(playerid, COLOR_GREY, "[提示]无效的车辆ID,请查阅Wiki。");
	new Float:x, Float:y, Float:z, Float:angle;
	GetPlayerPos(playerid, x, y, z);
	GetPlayerFacingAngle(playerid, angle);
	vcar = CreateVehicle(vid, x, y, z, angle, 0, 0, 0);
	PutPlayerInVehicle(playerid, vcar, 0);
	return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)