Call vehicles.
#1

Hello I need need help with a command, it is called /callcar and it calls a car for example

Vehicle1 = AddStaticVehicleEx(559,-1043.0850,1560.0236,32.9163,262.8105,86,86, 5000);
Vehicle2 = AddStaticVehicleEx(559,-1043.0850,1560.0236,32.9163,262.8105,86,86, 5000);

i want to call these vehicles which is in OnGameModeInit with /callcar [carname]
so if i wanted to call Vehicle1 i would type, /callcar Vehicle1 and it would come in front of me

Any ideas on how i can do this??
Reply
#2

pawn Код:
SetVehiclePos(/*vehicleid, Float:x, Float:y, Float:z*/)
Reply
#3

but how would i do this with multiple names
Reply
#4

would this be it

Код:
dcmd_callcar(playerid, params[])
{
	new Float:X, Float:Y, Float:Z;
  if(sscanf(params, "s", vehicleid)) SendClientMessage(playerid, TEXT_COLOR, "USAGE: \"/callcar [carname]\"");
  else if(GetPlayerState(playerid) == 2) SendClientMessage(playerid, TEXT_COLOR, "You must be on foot to call your car.");
  else
  {
  	new string[70];
  		format(string, sizeof(string), "You have called car id: %s", carname);
    GetVehiclePos(vehicleid, X, Y, Z);
  	SetVehiclePos(vehicleid, X, Y, Z);
		SendClientMessage(playerid, 0x00FFFFAA, string);
    return 1;
}
return 1;
}
Reply
#5

pawn Код:
GetVehiclePos(vehicleid, X, Y, Z);
SetVehiclePos(vehicleid, X, Y, Z);
replace with:

pawn Код:
GetPlayerPos(playerid, X, Y, Z);
new Float:pX, Float:pY;
GetXYInFrontOfPlayer(playerid, pX, pY, 3.0);
SetVehiclePos(/*vehicleid*/, pX, pY, Z); //Vehicle ID being the actual vehicle ID number, not just 'vehicleid'
Place this at the bottom of your script:

pawn Код:
GetXYInFrontOfPlayer(playerid, &Float:x, &Float:y, Float:distance)
{
new Float:a;
GetPlayerPos(playerid, x, y, a);
GetPlayerFacingAngle(playerid, a);
if (GetPlayerVehicleID(playerid))
{
  GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
}
x += (distance * floatsin(-a, degrees));
y += (distance * floatcos(-a, degrees));
}
Reply
#6

ok i got it but it just calls random cars and not the ones i want to be able to call the ones with the names like

vehicle2 = addstaticvehicle etc
heres the code
Код:
dcmd_callcar(playerid, params[])
{
	new vehicleid = GetPlayerVehicleID(playerid);
	new s[128];
	new Float:X, Float:Y, Float:Z;
  if(sscanf(params, "s", vehicleid)) SendClientMessage(playerid, TEXT_COLOR, "USAGE: \"/callcar [carname]\"");
  else if(GetPlayerState(playerid) == 2) SendClientMessage(playerid, TEXT_COLOR, "You must be on foot to call your car.");
  else
  {
  	new string[70];
  		format(string, sizeof(string), "You have called car id: %s", s);
    GetPlayerPos(playerid, X, Y, Z);
		new Float:pX, Float:pY;
		GetXYInFrontOfPlayer(playerid, pX, pY, 3.0);
		SetVehiclePos(vehicleid, pX, pY, Z); //Vehicle ID being the actual vehicle ID number, not just 'vehicleid'
		SendClientMessage(playerid, 0x00FFFFAA, string);
    return 1;
}
return 1;
}
Reply
#7

Read my comment.. vehicle ID should be the vehicle ID which you want to move..

For example:

pawn Код:
SetVehiclePos(1, pX, pY, Z);
And before you post back saying it teleports the wrong car.. change the vehicleid
Reply
#8

And, vehicle id should not be mistaken with model id if you don't know already.
Код:
Vehicle1 = AddStaticVehicleEx(559,-1043.0850,1560.0236,32.9163,262.8105,86,86, 5000);//this is id 0
Vehicle2 = AddStaticVehicleEx(559,-1043.0850,1560.0236,32.9163,262.8105,86,86, 5000);//this id 1
.
.
.
.//and so on
Reply
#9

Vehicle ID's actually start at 1.
Reply
#10

oh ok, but how to you get it so you type a name instead of it being a number?
so if its /callcar 1 instead it'll be /callcar jester
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)