Spawn a vehicle close to my player -
Dugzor - 11.09.2013
So here we go, another scripting beginner asking something easy. I've been trying to learn PAWN lately and understanding it was not so hard, since I know several other programming languages, but I'm still gonna have to adapt to the SAMP specific functions and such.
Introducing aside, my problem is as it follows:
I'm trying to create a command using zcmd to spawn a vehicle in a close range to my player. I know about the CreateVehicle command and its parameters, but I'm not sure how to get my player's position and angle. If I knew how to get those, I'd simply increase the numbers a bit and add them to the function parameter list causing the vehicle to spawn nearby.
I'm sorry if this question was asked before. I did use the search function, but I could not find something that would help me fix this issue.
P.S:
I also read about GetPlayerPos(), but I'm not sure how to use it in this case.
I just need the right information to get started in PAWN and I don't see a problem adapting myself into it. Some of the tutorials around are great and some have missing videos. I'll try to squeeze information out of those to make myself a nice scripter in PAWN.
Thanks for reading.
Re: Spawn a vehicle close to my player -
[HK]Ryder[AN] - 11.09.2013
Sorry for the bad indentation, typed it down directly
pawn Код:
CMD:createcar(playerid, params[])
{
new Float:X, Float:Y, Float:Z, Float:Angle;
GetPlayerPos(playerid, X, Y, Z);
GetPlayerFacingAngle(playerid, Angle);
AddStaticVehicle(CAR MODEL NUMBER, X+5, Y+5, Z, Angle, 0, 1); //You can also use CreateVehicle if you want
return 1;
}
Re: Spawn a vehicle close to my player -
Dugzor - 11.09.2013
Thank you for the response. It worked! This is the final code I am using:
pawn Код:
CMD:veh(playerid, params[])
{
new Float:x, Float:y, Float:z, Float:angle;
new vehid, color1, color2;
GetPlayerPos(playerid, x, y, z);
GetPlayerFacingAngle(playerid, angle);
if (sscanf(params, "iii", vehid, color1, color2))
{
return SendClientMessage(playerid, -1, "Command usage: /veh [model id] [color 1] [color 2]");
}
if (IsPlayerInAnyVehicle(playerid))
{
return SendClientMessage(playerid, -1, "You can't spawn a vehicle while being inside one.");
}
AddStaticVehicle(vehid, (x + 5), (y + 5), z, angle, color1, color2);
SendClientMessage(playerid, -1, "Vehicle was spawned.");
return 1;
}
I would appreciate if someone listed down the improvements that need to be done and the mistakes I did.
Re: Spawn a vehicle close to my player -
Kirollos - 11.09.2013
you should use CreateVehicle instead as AddStaticVehicle is only used in OnGameModeInit
as written here
https://sampwiki.blast.hk/wiki/AddStaticVehicle
Re: Spawn a vehicle close to my player -
[HK]Ryder[AN] - 11.09.2013
Quote:
Originally Posted by kirollos
|
Oh I am so sorry. Should have given this guy the code with CreateVehicle
Quote:
Originally Posted by Dugzor
Thank you for the response. It worked! This is the final code I am using:
pawn Код:
CMD:veh(playerid, params[]) { new Float:x, Float:y, Float:z, Float:angle; new vehid, color1, color2; GetPlayerPos(playerid, x, y, z); GetPlayerFacingAngle(playerid, angle); if (sscanf(params, "iii", vehid, color1, color2)) { return SendClientMessage(playerid, -1, "Command usage: /veh [model id] [color 1] [color 2]"); } if (IsPlayerInAnyVehicle(playerid)) { return SendClientMessage(playerid, -1, "You can't spawn a vehicle while being inside one."); } AddStaticVehicle(vehid, (x + 5), (y + 5), z, angle, color1, color2); SendClientMessage(playerid, -1, "Vehicle was spawned."); return 1; }
I would appreciate if someone listed down the improvements that need to be done and the mistakes I did.
|
Changed to createvehicle
pawn Код:
CMD:veh(playerid, params[])
{
new Float:x, Float:y, Float:z, Float:angle;
new vehid, color1, color2;
GetPlayerPos(playerid, x, y, z);
GetPlayerFacingAngle(playerid, angle);
if (sscanf(params, "iii", vehid, color1, color2))
{
return SendClientMessage(playerid, -1, "Command usage: /veh [model id] [color 1] [color 2]");
}
if (IsPlayerInAnyVehicle(playerid))
{
return SendClientMessage(playerid, -1, "You can't spawn a vehicle while being inside one.");
}
CreateVehicle(vehid, (x + 5), (y + 5), z, angle, color1, color2, 60);
SendClientMessage(playerid, -1, "Vehicle was spawned.");
return 1;
}