Need Help Making /vehid with ZCMD
#1

Hey! I am trying to make a command to show vehicle IDs by class. I have:

Код:
CMD:vehid(playerid, params[])
{
	new sel;
	if(sscanf(params, "u", sel)) return SendClientMessage(playerid, -1, "USAGE: /vehid [vehiclename/class]");
	{
	    //Allowable syntax
		SendClientMessage(playerid, -1, "Air | Bikes | Convertibles | Industrial | Lowriders | OffRoad | PublicService");
		SendClientMessage(playerid, -1, "Saloons | Sport | StationWagons | Sea | Trailers | Unique | RC");
		return 1;
	}
	if(sscanf(params, "Air", sel))
	{
	    SendClientMessage(playerid, -1, "Sparrow 469 | Seasparrow 447 | Raindance 563 | Police Maverick 497 | News Maverick 488 | Maverick 487");
	    SendClientMessage(playerid, -1, "Leviathan 417 | Hunter 425 | Cargobob 548 | Stuntplane 513 | Skimmer 460 | Shamal 519 | Rustler 476");
	    SendClientMessage(playerid, -1, "Nevada 553 | Hydra 520 | Dodo 593 | Cropduster 512 | Beagle 511 | AT400 577 | Andromada 592");
		return 1;
	}
	else if(sscanf(params, "Bikes", sel))
	{
	    SendClientMessage(playerid, -1, "Bike 509 | BMX 481 | Mountain Bike 510 | Faggio 462 | Pizzaboy 448 | BF-400 581 | NRG-500 522");
	    SendClientMessage(playerid, -1, "PCJ-600 461 | FCR-900 521 | HPV-1000 523 | Freeway 463 | Wayfarer 586 | Sanchez 468 | Quad 471");
		return 1;
	}
	else if(sscanf(params, "Convertibles", sel))
	{
	    SendClientMessage(playerid, -1, "Comet 480 | Feltzer 533 | Stallion 439 | Windsor 555");
		return 1;
	}
	else if(sscanf(params, "Industrial", sel))
	{
	    SendClientMessage(playerid, -1, "Benson 499 | Bobcat 422 | Burrito 482 | Boxville 498 | Boxburg 609 | Cement Truck 524 | DFT-30 578 | Flatbed 455");
	    SendClientMessage(playerid, -1, "Linerunner 403 | Mule 414 | Newsvan 582 | Packer 443 | Petrol Tanker 514 | Picador 600 | Pony 413 | Roadtrain 515");
	    SendClientMessage(playerid, -1, "Rumpo 440 | Sadler 543 | Sadler Shit 605 | Topfun 459 | Tractor 531 | Trashmaster 408 | Utility Van 552 | Walton 478");
	    SendClientMessage(playerid, -1, "Yankee 456 | Yosemite 554");
		return 1;
	}
	else if(sscanf(params, "Lowriders", sel))
	{
	    SendClientMessage(playerid, -1, "Blade 536 | Broadway 575 | Remington 534 | Savanna 567 | Slamvan 535 | Tahoma 566 | Tornado 576 | Voodoo 412");
	    return 1;
	}
	else if(sscanf(params, "OffRoad", sel))
	{
	    SendClientMessage(playerid, -1, "Bandito 568 | BFInjection 424 | Dune 573 | Huntley 579 | Landstalker 400 | Mesa 500 | Monster 444 | MonsterA 556 | MonsterB 557");
	    SendClientMessage(playerid, -1, "Patriot 470 | Rancher 489 | Rancher 505 | Sandking 465");
		return 1;
	}
	else if(sscanf(params, "PublicService", sel))
	{
	    SendClientMessage(playerid, -1, "Ambulance 416 | Barracks 433 | Bus 431 | Cabbie 438 | Coach 437 | HPV-1000 523 | Enforcer 427 | FBIRancher 490 | FBITruck 490");
	    SendClientMessage(playerid, -1, "Firetruck 407 | FiretruckLA 544 | LSPD 596 | SFPD 597 | LVPD 598 | Ranger 599 | Rhino 432 | SWAT 601 | Taxi 420");
	    return 1;
	}
	else if(sscanf(params, "Saloon", sel))
	{
	    SendClientMessage(playerid, -1, "Admiral 445 | Bloodring Banger 504 | Bravura 401 | Buccaneer 518 | Cadrona 527 | Clover 542 | Elegant 507 | Elegy 562 | Emperor 585");
	    SendClientMessage(playerid, -1, "Esperanto 419 | Fortune 526 | Glendale Shit 604 | Glendale 466 | Greenwood 462 | Hermes 474 | Intruder 546 | Majestic 517 | Manana 410");
	    SendClientMessage(playerid, -1, "Merit 551 | Nebula 516 | Oceanic 467 | Premier 426 | Previon 436 | Primo 547 | Sentinel 405 | Stafford 580 | Sultan 560 | Sunrise 550");
	    SendClientMessage(playerid, -1, "Tampa 549 | Vincent 540 | Virgo 491 | Willard 529 | Washington 521");
	    return 1;
	}
	else if(sscanf(params, "Sport", sel))
	{
	    SendClientMessage(playerid, -1, "Alpha 602 | Banshee 529 | Blista Compact 496 | Buffalo 402 | Bullet 541 | Cheetah 415 | Club 589 | Euros 587 | Flash 565 | Hotring Racer 494");
	    SendClientMessage(playerid, -1, "Hotring Racer 502 | Hotring Racer 503 | Infernus 544 | Jester 559 | Pheonix 603 | Sabre 475 | Super GT 506 | Turismo 451 | Uranus 558 | ZR-350 477");
	    return 1;
	}
	else if(sscanf(params, "StationWagons", sel))
	{
	    SendClientMessage(playerid, -1, "Moonbeam 418 | Perenniel 404 | Regina 479 | Solair 458 | Stratum 561");
	    return 1;
	}
	else if(sscanf(params, "Sea", sel))
	{
	    SendClientMessage(playerid, -1, "Coastguard 472 | Dinghy 473 | Jetmax 493 | Launch 595 | Marquis 484 | Predator 430 | Reefer 453 | Speeder 452 | Squallo 446 | Tropic 454");
	    return 1;
	}
	else if(sscanf(params, "Trailers", sel))
	{
	    SendClientMessage(playerid, -1, "Article Trailer 435 | Article Trailer2 450 | Petrol Trailer 584 | Article Trailer3 591 | Baggage A 606 | Baggage B 607 | StairsTrailer 608");
	    SendClientMessage(playerid, -1, "Farm Trailer 610 | Utility Trailer 611");
	    return 1;
	}
	else if(sscanf(params, "Unique", sel))
	{
	    SendClientMessage(playerid, -1, "Baggage 485 | Caddy 457 | Camper 483 | Combine Harvester 532 | Dozer 486 | Dumper 406 | Forklift 530 | Hotknife 434 | Hustler 545 | Hotdog 588");
	    SendClientMessage(playerid, -1, "Journey 508 | Kart 571 | Mower 572 | Mr.Whoopee 423 | Romero 442 | Securicar 428 | Stretch 409 | Sweeper 574 | Towtruck 525 | Tug 583 | Vortex 539");
	    return 1;
	}
	else if(sscanf(params, "RC", sel))
	{
	    SendClientMessage(playerid, -1, "RC Bandit 441 | RC Baron 464 | RC Radier 465 | RC Goblin 501 | RC Tiger 564 | RC Cam 594");
	    return 1;
	}
	return 1;
}
For some reason when I type in a class name, such as "/vehid Air", it only displays the "Allowable Syntax". My server log shows no error messages so I am down to the assumption that I messed up in the code. This is one of my few commands made and I put this one together by using other commands I have made. Could someone enlighten me to my problem and perhaps offer a solution? I would like to keep this commands to where you have to type in certain class and displayed in the chat window. Thank you in advance!
Reply
#2

I am not very experienced with ******'s version of sscanf plugin, but I will try to assist you best I can.

Firstly, sscanf() is not a function for comparing. It is used for extracting data (un-formatting) from a string into multiple variables as you specify. The method you should take for this command is to retrieve the data from params[] and compare it, using strcmp(), to the names you would like to check for. If none of them match any of the names specified, then return an error. There are a few errors with your sscanf code as well in that you are always extracting data into a variable of type integer, despite trying to retrieve a string. The "u" specifier is also fro players, not strings. You should read more thoroughly the sscanf documentation here: https://sampforum.blast.hk/showthread.php?tid=120356

It is also worth mentioning that you do not even need sscanf for this command. You can read from the params[] directly, and as you are expecting no more than one input string from the player, there is no need to parse it up (unformat it/use sscanf). Here is an example of how you could accomplish this:
pawn Код:
CMD:vehid(playerid, params[])
{
    if(!strcmp(params, "Air", true))
    {
        // Air vehicle messages
    }
    else if(!strcmp(params, "Industrial", true))
    {
        // Industrial vehicle messages
    }
    // etc
    else
    {
        // Return error, as they didn't type a "class" that you were expecting
    }
    return 1;
}
If you are unfamilar with the strcmp function, you may check it out here: https://sampwiki.blast.hk/wiki/strcmp
Reply
#3

Two ways you can do this..

#1 :

pawn Код:
CMD:vehid(playerid, params[])
{
    new sel[64];
    if(sscanf(params, "s[64]", sel)) return SendClientMessage(playerid, -1, "USAGE: /vehid [vehiclename/class]");
    {
       
        SendClientMessage(playerid, -1, "Air | Bikes | Convertibles | Industrial | Lowriders | OffRoad | PublicService");
        SendClientMessage(playerid, -1, "Saloons | Sport | StationWagons | Sea | Trailers | Unique | RC");
    }
    if(sscanf(params, "Air", sel))
    {
   
    }
    return 1;
}
#2:

pawn Код:
CMD:vehid(playerid, params[])
{
    new sel[64];
    if(sscanf(params, "s[64]", sel)) return SendClientMessage(playerid, -1, "USAGE: /vehid [vehiclename/class]");
    {
       
        SendClientMessage(playerid, -1, "Air | Bikes | Convertibles | Industrial | Lowriders | OffRoad | PublicService");
        SendClientMessage(playerid, -1, "Saloons | Sport | StationWagons | Sea | Trailers | Unique | RC");
    }
    if(strcmp("Air", "sel"))
    {
        // air stuff
    }
    if(strcmp("Bikes", "sel"))
    {
        //bikes stuff
    }
    return 1;
}
Reply
#4

Wow! Thank you! I must have missed the part on strcmp in the wiki. Thank you so much! And a very well put explanation of sscanf(). Again, thank you.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)