SA-MP Forums Archive
a little problem - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: a little problem (/showthread.php?tid=280892)



a little problem - Davz*|*Criss - 03.09.2011

hey guys i got this code:
on top:

pawn Код:
new VehicleNames[212][] =
{
    {"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"}
};
pawn Код:
CMD:car(playerid,params[])
{
    if(!IsPlayerAdmin(playerid))
    {
        SendClientMessage(playerid,red,"You are not authorized to use that command!");
        return 1;
    }
    else if(IsPlayerAdmin(playerid))
    {
        new vehicle,color1,color2;
        if(sscanf(params,"sdd",vehicle,color1,color2)) SendClientMessage(playerid,0xFFFFAAFF,"Correct Usage: /car[Vehicle Name] [Color 1][Color 2]");
        else
        {
            vehicle = VehicleNames;
            new Float:x, Float:y, Float:z,angle;
            GetPlayerPos(playerid,x,y,z);
            new id = CreateVehicle(vehicle, x+3,y,z, angle, -1,-1,-1);
            new vehicleid = GetPlayerVehicleID(playerid);
            PutPlayerInVehicle(playerid, vehicleid, 0 );
            ChangeVehicleColor(id, color1, color2);
        }
    }
    return 1;
}
error:

Код:
C:\Users\Ayyyt\Desktop\Server\filterscripts\ev.pwn(277) : error 006: must be assigned to an array
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Error.
line 277: vehicle = VehicleNames;


Re: a little problem - =WoR=Varth - 03.09.2011

pawn Код:
VehicleNames[GetVehicleModel(vehicleid) + 400]
Make a sense?


Re: a little problem - Davz*|*Criss - 03.09.2011

What are you saying


Re: a little problem - =WoR=Varth - 03.09.2011

pawn Код:
format(string,sizeof(string),"%s",VehicleNames[GetVehicleModel(vehicleid) + 400]);
It's 400+ because vehicle model start from 400 (Or 300, check it by your self).


Re: a little problem - Davz*|*Criss - 03.09.2011

thanks


Re: a little problem - JaTochNietDan - 03.09.2011

You could really do with cleaning up the code a little, for example, there's no need for a second if check in the statement when the only other possibility is what you're checking, that's just a waste of time! Also people here are mis-understanding what you're trying to do, what you need is to look through the array and match the string to the array and use it as the model ID. You also use GetPlayerVehicleID when you already have the ID stored in the id variable!

You need to specify vehicle as an array also since you're trying to use it as an array in sscanf.

pawn Код:
stock GetModelFromName(name[])
{
    for(new i; i < sizeof(VehicleNames); i++) if(strcmp(name, VehicleNames[i], true) == 0) return i;
    return -1;
}

CMD:car(playerid,params[])
{
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,red,"You are not authorized to use that command!");
    new vehicle[20],color1,color2;
    if(sscanf(params,"sdd",vehicle,color1,color2)) SendClientMessage(playerid,0xFFFFAAFF,"Correct Usage: /car[Vehicle Name] [Color 1][Color 2]");
    else
    {
        new model = GetModelFromName(vehicle);
        if(model == -1) return SendClientMessage(playerid, 0xFFFFAAFF, "Vehicle not found with that name");
        new Float:x, Float:y, Float:z,angle;
        GetPlayerPos(playerid,x,y,z);
        new id = CreateVehicle(model, x+3,y,z, angle, -1,-1,-1);
        PutPlayerInVehicle(playerid, id, 0 );
        ChangeVehicleColor(id, color1, color2);
    }
    return 1;
}
There's a quick example I made for you, you can edit it to suit your needs.


Re: a little problem - Davz*|*Criss - 05.09.2011

Not working, It just shows usage.


Re: a little problem - Wesley221 - 05.09.2011

Take a look at my FS, working vehicle spawner in there
https://sampforum.blast.hk/showthread.php?tid=273791


Re: a little problem - Davz*|*Criss - 05.09.2011

Alright, i will check it.