how to make a command to add any vehicle? -
Alzzy - 17.07.2011
Hey, I have just started to learn to script and i need to add vehicles.. like a simple command like /car bullet and then that spawns a bullet? I need a car adding command.. If anyone knows how to do that or got a system that does that already please tell me or show me link to it thanks.
Re: how to make a command to add any vehicle? -
||123|| - 17.07.2011
If you just learnt pawno, I'm not gonna make it hard on you and just try to make it simple. If you wanna spawn vehicle name from command then it's gonna take you to add all the vehicle name first, which is lengthy and hard for a newbie, for now you can just use /car [ID]. You just have to put the ID of the car where you had to put the name. Here is a list of vehicle names and IDs:
https://sampwiki.blast.hk/wiki/Vehicles:All. Bullet's ID is 541. Here's the function:
pawn Код:
if(strcmp(string, "/car", true) == 0)
{
string = strtok(cmdtext,idx);
if(!strlen(string))
{
SendClientMessage(playerid, COLOR_GREY, "USAGE: /car [carid]");
return 1;
}
object = strval(string);
new Float:playerx, Float:playery, Float:playerz;
GetPlayerPos(playerid, playerx, playery, playerz);
CreateVehicle(object, playerx, playery, playerz, 0, 0, 0, 60000);
}
Re: how to make a command to add any vehicle? -
Alzzy - 17.07.2011
Thanks duude you rock (:
Re: how to make a command to add any vehicle? -
Alzzy - 17.07.2011
Im getting all errors :/
Re: how to make a command to add any vehicle? -
freshOrange - 17.07.2011
Add
pawn Код:
strtok(const string[], &index)
{
new length = strlen(string);
while ((index < length) && (string[index] <= ' '))
{
index++;
}
new offset = index;
new result[20];
while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
{
result[index - offset] = string[index];
index++;
}
result[index - offset] = EOS;
return result;
}
Re: how to make a command to add any vehicle? -
Johnson_boy - 17.07.2011
Strtok isn't really even needed there.
You can do just
pawn Код:
new car = strval(cmdtext[5]);
or new "object" as it was in reply above.
Re: how to make a command to add any vehicle? -
freshOrange - 17.07.2011
pawn Код:
CMD:car(playerid, params[])
{
new string[128];
new object;
string = strtok(params, idx);
if(!strlen(string))
{
SendClientMessage(playerid, COLOR_WHITE, "USAGE: /car [carid]");
return 1;
}
object = strval(string);
new Float:playerx, Float:playery, Float:playerz;
GetPlayerPos(playerid, playerx, playery, playerz);
CreateVehicle(object, playerx, playery, playerz, 0, 0, 0, 60000);
return 1;
}
How do I convert it to zcmd? Getting undefined symbol "idx"
Re: how to make a command to add any vehicle? -
Johnson_boy - 17.07.2011
Easiest way:
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
if(!strcmp("/car", cmdtext, true, 4))
{
new vehicle = strval(cmdtext[5]);
if(vehicle < 400 || vehicle > 611) return SendClientMessage(playerid, 0xFFFFFFFF, "Error: invalid vehicle id");
new Float:x, Float:y, Float:z, Float:a;
GetPlayerPos(playerid, x, y, z);
GetPlayerFacingAngle(playerid, a);
CreateVehicle(vehicle, x+2,y+2,z,a,-1,-1,-1);
return 1;
}
return 0;
}
Re: how to make a command to add any vehicle? -
freshOrange - 18.07.2011
It crashes down the server, lol.
Re: how to make a command to add any vehicle? -
Bakr - 18.07.2011
Try this:
pawn Код:
COMMAND:car( playerid, params[ ] )
{
if( strval( params ) < 400 || strval( params ) > 611 )
return SendClientMessage( playerid, 0xFF0000FF, "Invalid model ID." );
new Float: x, Float: y, Float: z, Float: a;
GetPlayerPos( playerid, x, y, z );
GetPlayerFacingAngle( playerid, a );
CreateVehicle( strval( params ), ( x += ( 5 * floatsin( -a, degrees ) ) ), ( y += ( 5 * floatcos( -a, degrees ) ) ), z, ( a - 90 ), -1, -1, 100000 );
return 1;
}