how to make a command to add any vehicle?
#1

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.
Reply
#2

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);
    }
Reply
#3

Thanks duude you rock (:
Reply
#4

Im getting all errors :/
Reply
#5

Add

pawn Код:
new string[128];
pawn Код:
new object;
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;
}
Reply
#6

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.
Reply
#7

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"
Reply
#8

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;
}
Reply
#9

It crashes down the server, lol.
Reply
#10

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;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)