I need help in making Commands
#1

Hello I am new in this SAMP Forum and I am learning to Script.
Can Any one Help me in telling me that How can I spawn cars and I how can I create command /spawn <vehicleid>

Please Help me I am new!!!
Reply
#2

First welcome to the samp community
Then to help you create a new pawno file
Quote:

open pawno in the /pawno driectory

Then create a new file ( the blank page icon or CTRL + N )
It will show u a new file with a lot of public and text.

To create a new command search (CTRL + F)
pawn Код:
public OnPlayerCommandText
Replace the
pawn Код:
/mycommand
by your command.
And then write your code. (where it's writed // write your code here bla bla bla)

IF you want to create a car spawner, create a new file, and then select all the text and delete it.

Copy this :
pawn Код:
#include <a_samp>
// the include

#define FILTERSCRIPT
// this is for defining if it's a filterscript
#if defined FILTERSCRIPT
// this is for defining if it's a filterscript

#define l_red 0xFF0000AA
// that's the colors
#define l_green 0x33FF33AA

public OnPlayerSpawn(playerid)
{
#if !defined IGNORE_SPAWN_MESSAGES  // that's the define of the error msg //
        SendClientMessage( playerid, 0x00FF00AA, "[*CarSpawner By VanillaRain*]: Use the command '/car + car name' to spawn the selected car" );
    #endif
    return 1;
}
// that's the define of the error msg

new aVehicleNames[212][] = // all the vehicles names
{
    {"Landstalker"},
    {"Bravura"},
    {"Buffalo"},
    {"Linerunner"},
    {"Perrenial"},
    {"Sentinel"},
    {"Dumper"},
    {"Firetruck"},
    {"Trashmaster"},
    {"Stretch"},
    {"Manana"},
    {"Infernus"},
    {"Voodoo"},
    {"Pony"},
    {"Mule"},
    {"Cheetah"},
    {"Ambulance"},
    {"Leviathan"},
    {"Moonbeam"},
    {"Esperanto"},
    {"Taxi"},
    {"Washington"},
    {"Bobcat"},
    {"Mr Whoopee"},
    {"BF Injection"},
    {"Hunter"},
    {"Premier"},
    {"Enforcer"},
    {"Securicar"},
    {"Banshee"},
    {"Predator"},
    {"Bus"},
    {"Rhino"},
    {"Barracks"},
    {"Hotknife"},
    {"Trailer 1"},
    {"Previon"},
    {"Coach"},
    {"Cabbie"},
    {"Stallion"},
    {"Rumpo"},
    {"RC Bandit"},
    {"Romero"},
    {"Packer"},
    {"Monster"},
    {"Admiral"},
    {"Squalo"},
    {"Seasparrow"},
    {"Pizzaboy"},
    {"Tram"},
    {"Trailer 2"},
    {"Turismo"},
    {"Speeder"},
    {"Reefer"},
    {"Tropic"},
    {"Flatbed"},
    {"Yankee"},
    {"Caddy"},
    {"Solair"},
    {"Berkley's RC Van"},
    {"Skimmer"},
    {"PCJ-600"},
    {"Faggio"},
    {"Freeway"},
    {"RC Baron"},
    {"RC Raider"},
    {"Glendale"},
    {"Oceanic"},
    {"Sanchez"},
    {"Sparrow"},
    {"Patriot"},
    {"Quad"},
    {"Coastguard"},
    {"Dinghy"},
    {"Hermes"},
    {"Sabre"},
    {"Rustler"},
    {"ZR-350"},
    {"Walton"},
    {"Regina"},
    {"Comet"},
    {"BMX"},
    {"Burrito"},
    {"Camper"},
    {"Marquis"},
    {"Baggage"},
    {"Dozer"},
    {"Maverick"},
    {"News Chopper"},
    {"Rancher"},
    {"FBI Rancher"},
    {"Virgo"},
    {"Greenwood"},
    {"Jetmax"},
    {"Hotring"},
    {"Sandking"},
    {"Blista Compact"},
    {"Police Maverick"},
    {"Boxville"},
    {"Benson"},
    {"Mesa"},
    {"RC Goblin"},
    {"Hotring Racer A"},
    {"Hotring Racer B"},
    {"Bloodring Banger"},
    {"Rancher"},
    {"Super GT"},
    {"Elegant"},
    {"Journey"},
    {"Bike"},
    {"Mountain Bike"},
    {"Beagle"},
    {"Cropdust"},
    {"Stunt"},
    {"Tanker"},
    {"Roadtrain"},
    {"Nebula"},
    {"Majestic"},
    {"Buccaneer"},
    {"Shamal"},
    {"Hydra"},
    {"FCR-900"},
    {"NRG-500"},
    {"HPV1000"},
    {"Cement Truck"},
    {"Tow Truck"},
    {"Fortune"},
    {"Cadrona"},
    {"FBI Truck"},
    {"Willard"},
    {"Forklift"},
    {"Tractor"},
    {"Combine"},
    {"Feltzer"},
    {"Remington"},
    {"Slamvan"},
    {"Blade"},
    {"Freight"},
    {"Streak"},
    {"Vortex"},
    {"Vincent"},
    {"Bullet"},
    {"Clover"},
    {"Sadler"},
    {"Firetruck LA"},
    {"Hustler"},
    {"Intruder"},
    {"Primo"},
    {"Cargobob"},
    {"Tampa"},
    {"Sunrise"},
    {"Merit"},
    {"Utility"},
    {"Nevada"},
    {"Yosemite"},
    {"Windsor"},
    {"Monster A"},
    {"Monster B"},
    {"Uranus"},
    {"Jester"},
    {"Sultan"},
    {"Stratum"},
    {"Elegy"},
    {"Raindance"},
    {"RC Tiger"},
    {"Flash"},
    {"Tahoma"},
    {"Savanna"},
    {"Bandito"},
    {"Freight Flat"},
    {"Streak Carriage"},
    {"Kart"},
    {"Mower"},
    {"Duneride"},
    {"Sweeper"},
    {"Broadway"},
    {"Tornado"},
    {"AT-400"},
    {"DFT-30"},
    {"Huntley"},
    {"Stafford"},
    {"BF-400"},
    {"Newsvan"},
    {"Tug"},
    {"Trailer 3"},
    {"Emperor"},
    {"Wayfarer"},
    {"Euros"},
    {"Hotdog"},
    {"Club"},
    {"Freight Carriage"},
    {"Trailer 3"},
    {"Andromada"},
    {"Dodo"},
    {"RC Cam"},
    {"Launch"},
    {"Police Car (LSPD)"},
    {"Police Car (SFPD)"},
    {"Police Car (LVPD)"},
    {"Police Ranger"},
    {"Picador"},
    {"S.W.A.T. Van"},
    {"Alpha"},
    {"Phoenix"},
    {"Glendale"},
    {"Sadler"},
    {"Luggage Trailer A"},
    {"Luggage Trailer B"},
    {"Stair Trailer"},
    {"Boxville"},
    {"Farm Plow"},
    {"Utility Trailer"}
};

#endif

public OnPlayerCommandText(playerid, cmdtext[]) // there is our command
{
    new cmd[200], idx;
    cmd = strtok(cmdtext, idx);

    if(strcmp(cmd, "/car", true, 10) == 0)
    {

        new String[200];
        new tmp[256];
        new Float:x, Float:y, Float:z;

        tmp = strtok(cmdtext, idx);
        if(!strlen(tmp)) return SendClientMessage(playerid, l_red, "You diden't give a vehicle name");

        new vehicle = GetVehicleModelIDFromName(tmp);

        if(vehicle < 400 || vehicle > 611) return SendClientMessage(playerid, l_red, "That vehicle name was not found");

        new Float:a;
        GetPlayerFacingAngle(playerid, a);
        GetPlayerPos(playerid, x, y, z);

        if(IsPlayerInAnyVehicle(playerid) == 1)
        {
            GetXYInFrontOfPlayer(playerid, x, y, 8);
        }
        else
        {
            GetXYInFrontOfPlayer(playerid, x, y, 5);
        }

        new PlayersVehicle = CreateVehicle(vehicle, x, y, z, a+90, -1, -1, -1);
        LinkVehicleToInterior(PlayersVehicle, GetPlayerInterior(playerid));

        format(String, sizeof(String), "You have spawned a %s", aVehicleNames[vehicle - 400]);
        SendClientMessage(playerid, l_green, String);
        return 1;
    }
    return 0;
}

strtok(const string[], &index) // that's infos for the script
{
    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;
}

GetVehicleModelIDFromName(vname[]) // all there is for the car name spawner ect...
{
    for(new i = 0; i < 211; i++)
    {
        if(strfind(aVehicleNames[i], vname, true) != -1)
        return i + 400;
    }
    return -1;
}

stock GetXYInFrontOfPlayer(playerid, &Float:x2, &Float:y2, Float:distance) // that's the car rotation when spawn
{
    new Float:a;

    GetPlayerPos(playerid, x2, y2, a);
    GetPlayerFacingAngle(playerid, a);

    if(GetPlayerVehicleID(playerid))
    {
        GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
    }

    x2 += (distance * floatsin(-a, degrees));
    y2 += (distance * floatcos(-a, degrees));
}
Reply
#3

https://sampforum.blast.hk/showthread.php?tid=456280

Follow the instructions what is explained in the tutorial.Once you catch up the basics, try these:
To add a vehicle there are two functions namely AddStaticVehicle and CreateVehicle.AddStaticVehicle will not do well here because it cannot be use outside OnGameModeInit.So you'll have be using CreateVehicle.Specify the parameters into the function.You can get the location where to spawn using GetPlayerPos(Type in the wiki search box and it will show the details).

CreateVehicle - https://sampwiki.blast.hk/wiki/CreateVehicle

An idea:
Quote:

COMMAND:vspawn(playerid,params[])
{
new mid,c1,c2,Float,Float:y,Float:z,Float:ror,string[256];
if(sscanf(params,"iii",mid,c1,c2)) { return SendClientMessage(playerid,0xEEEEEE,"Usage:/vspawn [mid] [color1] [color2]"); }
GetPlayerPos(playerid,x,y,z);
GetPlayerFacingAngle(playerid,ror);
new vid = CreateVehicle(mid,x,y,z,ror,c1,c2,60000);
if(vid == INVALID_VEHICLE_ID) { return SendClientMessage(playerid,COLOR_RED,"Invalid Parameters"); }
format(string,sizeof(string),"Vehicle ID:%d ModelID:%s(%d) Color1:%d Color2:%d",vid,VehicleNames[mid-400],mid,c1,c2);
SendClientMessage(playerid,COLOR_GREEN,string);
PutPlayerInVehicle(playerid,vid,0);
return 1;
}

Reply
#4

Thank you for your Replies!

But @1_geek, I have did all the things what you said and Copy / Paste them But I am founding 2 Errors. Can you help me in fixing it?

here are the screen shot...



Reply
#5

You can't use OnPlayerCommandText if you use ZCMD.Don't copy the code.Just understand his idea and how his code works and try to implement the same idea in your code.

NOTE:Copying will never work!
Reply
#6

Just learn script by your self with the tutorial. And copy will never work like Yashas say.

And if you use normal command. Remove the include zcmd
Reply
#7

Don't use strcmp for commands, it's slow. Use ZCMD instead. It can be combined with sscanf and it's really easy and fast to make commands. There are many tutorials about how to use zcmd + sscanf for commands.

pawn Код:
CMD:spawn( playerid, params[ ] )
{
    new
        modelid
    ;
    if( sscanf( params, "i", modelid ) ) return SendClientMessage( playerid, -1, "Usage: /spawn <modelid>" );
    if( modelid < 400 || modelid > 611 ) return SendClientMessage( playerid, -1, "Modelids: 400-611" );
   
    new
        Float: p[ 4 ]
    ;
    GetPlayerPos( playerid, p[ 0 ], p[ 1 ], p[ 2 ] );
    GetPlayerFacingAngle( playerid, p[ 3 ] );
   
    switch( GetPlayerState( playerid ) )
    {
        case PLAYER_STATE_DRIVER: DestroyVehicle( GetPlayerVehicleID( playerid ) );
        case PLAYER_STATE_PASSENGER: RemovePlayerFromVehicle( playerid );
    }
   
    new
        vehicleid = CreateVehicle( modelid, p[ 0 ], p[ 1 ] + 2, p[ 2 ] + 2, p[ 3 ], -1, -1, 60 )
    ;
    LinkVehicleToInterior( vehicleid, GetPlayerInterior( playerid ) );
    SetVehicleVirtualWorld( vehicleid, GetPlayerVirtualWorld( playerid ) );
    PutPlayerInVehicle( playerid, vehicleid, 0 );
    return 1;
}
Reply
#8

Thanks All for the Help
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)