Useful Functions

BlueG is G-Stylezz
Reply

Quote:
Originally Posted by RyDeR`
Посмотреть сообщение
@Lorenc_:

I meant something more like this:
pawn Код:
stock SetObjectFacePoint(iObjectID, Float: fX, Float: fY, Float: fOffset = 0.0)
{
    new
        Float: fOX,
        Float: fOY,
        Float: fRZ
    ;
    if(GetObjectPos(iObjectID, fOX, fOY, fRZ))
    {
        fRZ = atan2(fY - fOY, fX - fOX) - 90.0;
       
        GetObjectRot(iObjectID, fX, fY, fOX);
        SetObjectRot(iObjectID, fX, fY, fRZ + fOffset);
    }
}
Ah, an offset, sorry about that. I didn't check the thread nor I couldn't since my computer blocked the SA-MP forums url randomly :S

Thanks though for the correction
Reply

Quote:
Originally Posted by System64
Посмотреть сообщение
Why not?
I think that BlueG is G-Stylezz?
BlueG is G-sTyLeZzZ, yes.
Escaping names is not necessary as they cannot contain characters or formations which would cause special behavior by MySQL.
Reply

Quote:
Originally Posted by AndreT
Посмотреть сообщение
BlueG is G-sTyLeZzZ, yes.
Escaping names is not necessary as they cannot contain characters or formations which would cause special behavior by MySQL.
What if they do in the future? You might as well do it right. Personally, I escape ANY string going into a query just so I'm sure it's cool.
Reply

I don't see why you wouldn't escape any string that could possibly be customised by a player.
Reply

I didn't know about the possibility with SetPlayerName, but I already use one of your functions to validate all sorts of name input. I suppose it is better to be safe than sorry.
Reply

GivePlayerDamage(playerid, Float:damage);
pawn Код:
stock GivePlayerDamage(playerid, Float:damage)
{
    new Float:pHealth,
        Float:pArmour,
        Float:pDif
    ;
    GetPlayerHealth(playerid, pHealth);
    GetPlayerArmour(playerid, pArmour);
   
    if(pArmour <= 0) SetPlayerHealth(playerid, pHealth - damage);
    else
    {
        pDif = damage - pArmour;
        if(pDif <= 0) SetPlayerArmour(playerid, pArmour - damage);
        else
        {
            SetPlayerArmour(playerid, 0);
            SetPlayerHealth(playerid, pHealth - pDif);
        }
    }
    return 1;
}
For example, the player has 100 health and 100 armour. You run this command with 20 damage untill he's dead (so you repeat it). You have to run it 10 times: First it'll destroy all the armour. Then the normal lives. If damage = 20 and armour = 10, it'll also take 10 HP.
Notice: I've tested it, and it worked fine for me. Please tell me if you have another experiences
Reply

pawn Код:
stock GetVehicleName(modelid)
{
    static _szModelName[17];
    _szModelName[0] = EOS;
    switch(modelid)
    {
        case 400: strcat(_szModelName, "Landstalker");
        case 401: strcat(_szModelName, "Bravura");
        case 402: strcat(_szModelName, "Buffalo");
        case 403: strcat(_szModelName, "Linerunner");
        case 404: strcat(_szModelName, "Perenniel");
        case 405: strcat(_szModelName, "Sentinel");
        case 406: strcat(_szModelName, "Big Dumper");
        case 407: strcat(_szModelName, "Firetruck");
        case 408: strcat(_szModelName, "Trashmaster");
        case 409: strcat(_szModelName, "Stretch");
        case 410: strcat(_szModelName, "Manana");
        case 411: strcat(_szModelName, "Shitfernub");
        case 412: strcat(_szModelName, "Voodoo");
        case 413: strcat(_szModelName, "Pony");
        case 414: strcat(_szModelName, "Mule");
        case 415: strcat(_szModelName, "Cheetah");
        case 416: strcat(_szModelName, "Ambulance");
        case 417: strcat(_szModelName, "Leviathan");
        case 418: strcat(_szModelName, "Moonbeam");
        case 419: strcat(_szModelName, "Esperanto");
        case 420: strcat(_szModelName, "Taxi");
        case 421: strcat(_szModelName, "Washington");
        case 422: strcat(_szModelName, "Bobcat");
        case 423: strcat(_szModelName, "Mr. Whoopee");
        case 424: strcat(_szModelName, "BF Injection");
        case 425: strcat(_szModelName, "Hunter");
        case 426: strcat(_szModelName, "Premier");
        case 427: strcat(_szModelName, "Enforcer");
        case 428: strcat(_szModelName, "Securicar");
        case 429: strcat(_szModelName, "Banshee");
        case 430: strcat(_szModelName, "Predator");
        case 431: strcat(_szModelName, "Bus");
        case 432: strcat(_szModelName, "Rhino");
        case 433: strcat(_szModelName, "Barracks");
        case 434: strcat(_szModelName, "Hotknife");
        case 435: strcat(_szModelName, "Box Trailer 1");
        case 436: strcat(_szModelName, "Previon");
        case 437: strcat(_szModelName, "Coach");
        case 438: strcat(_szModelName, "Cabbie");
        case 439: strcat(_szModelName, "Stallion");
        case 440: strcat(_szModelName, "Rumpo");
        case 441: strcat(_szModelName, "RC Bandit");
        case 442: strcat(_szModelName, "Romero");
        case 443: strcat(_szModelName, "Packer");
        case 444: strcat(_szModelName, "Monster");
        case 445: strcat(_szModelName, "Admiral");
        case 446: strcat(_szModelName, "Squallo");
        case 447: strcat(_szModelName, "Sea Sparrow");
        case 448: strcat(_szModelName, "Pizza Boy");
        case 449: strcat(_szModelName, "Tram");
        case 450: strcat(_szModelName, "Dumper Trailer");
        case 451: strcat(_szModelName, "Turismo");
        case 452: strcat(_szModelName, "Speeder");
        case 453: strcat(_szModelName, "Reefer");
        case 454: strcat(_szModelName, "Tropic");
        case 455: strcat(_szModelName, "Flatbed");
        case 456: strcat(_szModelName, "Yankee");
        case 457: strcat(_szModelName, "Caddy");
        case 458: strcat(_szModelName, "Solair");
        case 459: strcat(_szModelName, "Berkley's RC Van");
        case 460: strcat(_szModelName, "Skimmer");
        case 461: strcat(_szModelName, "PCJ-600");
        case 462: strcat(_szModelName, "Faggio");
        case 463: strcat(_szModelName, "Freeway");
        case 464: strcat(_szModelName, "RC Baron");
        case 465: strcat(_szModelName, "RC Raider");
        case 466: strcat(_szModelName, "Glendale");
        case 467: strcat(_szModelName, "Oceanic");
        case 468: strcat(_szModelName, "Sanchez");
        case 469: strcat(_szModelName, "Sparrow");
        case 470: strcat(_szModelName, "Patriot");
        case 471: strcat(_szModelName, "Quad");
        case 472: strcat(_szModelName, "Coastguard");
        case 473: strcat(_szModelName, "Dinghy");
        case 474: strcat(_szModelName, "Hermes");
        case 475: strcat(_szModelName, "Sabre");
        case 476: strcat(_szModelName, "Rustler");
        case 477: strcat(_szModelName, "ZR-350");
        case 478: strcat(_szModelName, "Walton");
        case 479: strcat(_szModelName, "Regina");
        case 480: strcat(_szModelName, "Comet");
        case 481: strcat(_szModelName, "BMX");
        case 482: strcat(_szModelName, "Burrito");
        case 483: strcat(_szModelName, "Camper");
        case 484: strcat(_szModelName, "Marquis");
        case 485: strcat(_szModelName, "Baggage");
        case 486: strcat(_szModelName, "Dozer");
        case 487: strcat(_szModelName, "Maverick");
        case 488: strcat(_szModelName, "SAN News Maverick");
        case 489: strcat(_szModelName, "Rancher");
        case 490: strcat(_szModelName, "FBI Rancher");
        case 491: strcat(_szModelName, "Virgo");
        case 492: strcat(_szModelName, "Greenwood");
        case 493: strcat(_szModelName, "Jetmax");
        case 494: strcat(_szModelName, "Hotring");
        case 495: strcat(_szModelName, "Sandking");
        case 496: strcat(_szModelName, "Blista Compact");
        case 497: strcat(_szModelName, "Police Maverick");
        case 498: strcat(_szModelName, "Boxville");
        case 499: strcat(_szModelName, "Benson");
        case 500: strcat(_szModelName, "Mesa");
        case 501: strcat(_szModelName, "RC Goblin");
        case 502: strcat(_szModelName, "Hotring A");
        case 503: strcat(_szModelName, "Hotring B");
        case 504: strcat(_szModelName, "Bloodring Banger");
        case 505: strcat(_szModelName, "Rancher");
        case 506: strcat(_szModelName, "Super GT");
        case 507: strcat(_szModelName, "Elegant");
        case 508: strcat(_szModelName, "Journey");
        case 509: strcat(_szModelName, "Bike");
        case 510: strcat(_szModelName, "Mountain Bike");
        case 511: strcat(_szModelName, "Beagle");
        case 512: strcat(_szModelName, "Cropduster");
        case 513: strcat(_szModelName, "Stuntplane");
        case 514: strcat(_szModelName, "Petrol");
        case 515: strcat(_szModelName, "Road Train");
        case 516: strcat(_szModelName, "Nebula");
        case 517: strcat(_szModelName, "Majestic");
        case 518: strcat(_szModelName, "Buccaneer");
        case 519: strcat(_szModelName, "Shamal");
        case 520: strcat(_szModelName, "Hydra");
        case 521: strcat(_szModelName, "FCR-900");
        case 522: strcat(_szModelName, "NRG-500");
        case 523: strcat(_szModelName, "HPV-1000");
        case 524: strcat(_szModelName, "Cement Truck");
        case 525: strcat(_szModelName, "Towtruck");
        case 526: strcat(_szModelName, "Fortune");
        case 527: strcat(_szModelName, "Cadrona");
        case 528: strcat(_szModelName, "FBI Truck");
        case 529: strcat(_szModelName, "Willard");
        case 530: strcat(_szModelName, "Forklift");
        case 531: strcat(_szModelName, "Tractor");
        case 532: strcat(_szModelName, "Combine Harvester");
        case 533: strcat(_szModelName, "Feltzer");
        case 534: strcat(_szModelName, "Remington");
        case 535: strcat(_szModelName, "Slamvan");
        case 536: strcat(_szModelName, "Blade");
        case 537: strcat(_szModelName, "Freight");
        case 538: strcat(_szModelName, "Brownstreak");
        case 539: strcat(_szModelName, "Vortex");
        case 540: strcat(_szModelName, "Vincent");
        case 541: strcat(_szModelName, "Bullet");
        case 542: strcat(_szModelName, "Clover");
        case 543: strcat(_szModelName, "Sadler");
        case 544: strcat(_szModelName, "Firetruck LA");
        case 545: strcat(_szModelName, "Hustler");
        case 546: strcat(_szModelName, "Intruder");
        case 547: strcat(_szModelName, "Primo");
        case 548: strcat(_szModelName, "Cargobob");
        case 549: strcat(_szModelName, "Tampa");
        case 550: strcat(_szModelName, "Sunrise");
        case 551: strcat(_szModelName, "Merit");
        case 552: strcat(_szModelName, "Utility Van");
        case 553: strcat(_szModelName, "Nevada");
        case 554: strcat(_szModelName, "Yosemite");
        case 555: strcat(_szModelName, "Windsor");
        case 556: strcat(_szModelName, "Monster A");
        case 557: strcat(_szModelName, "Monster B");
        case 558: strcat(_szModelName, "Uranus");
        case 559: strcat(_szModelName, "Jester");
        case 560: strcat(_szModelName, "Sultan");
        case 561: strcat(_szModelName, "Stratum");
        case 562: strcat(_szModelName, "Elegy");
        case 563: strcat(_szModelName, "Raindance");
        case 564: strcat(_szModelName, "RC Tiger");
        case 565: strcat(_szModelName, "Flash");
        case 566: strcat(_szModelName, "Tahoma");
        case 567: strcat(_szModelName, "Savanna");
        case 568: strcat(_szModelName, "Bandito");
        case 569: strcat(_szModelName, "Freight Flat");
        case 570: strcat(_szModelName, "Streak");
        case 571: strcat(_szModelName, "Kart");
        case 572: strcat(_szModelName, "Mower");
        case 573: strcat(_szModelName, "Duneride");
        case 574: strcat(_szModelName, "Sweeper");
        case 575: strcat(_szModelName, "Broadway");
        case 576: strcat(_szModelName, "Tornado");
        case 577: strcat(_szModelName, "AT-400");
        case 578: strcat(_szModelName, "DFT-30");
        case 579: strcat(_szModelName, "Huntley");
        case 580: strcat(_szModelName, "Stafford");
        case 581: strcat(_szModelName, "BF-400");
        case 582: strcat(_szModelName, "Newsvan");
        case 583: strcat(_szModelName, "Tug");
        case 584: strcat(_szModelName, "Petrol Trailer");
        case 585: strcat(_szModelName, "Emporor");
        case 586: strcat(_szModelName, "Wayfarer");
        case 587: strcat(_szModelName, "Euros");
        case 588: strcat(_szModelName, "Hotdog");
        case 589: strcat(_szModelName, "Club");
        case 590: strcat(_szModelName, "Freight Box");
        case 591: strcat(_szModelName, "Box Trailer 3");
        case 592: strcat(_szModelName, "Andromada");
        case 593: strcat(_szModelName, "Dodo");
        case 594: strcat(_szModelName, "RC Cam");
        case 595: strcat(_szModelName, "Launch");
        case 596: strcat(_szModelName, "Cop Car LS");
        case 597: strcat(_szModelName, "Cop Car SF");
        case 598: strcat(_szModelName, "Cop Car LV");
        case 599: strcat(_szModelName, "Police Ranger");
        case 600: strcat(_szModelName, "Picador");
        case 601: strcat(_szModelName, "S.W.A.T");
        case 602: strcat(_szModelName, "Alpha");
        case 603: strcat(_szModelName, "Phoenix");
        case 604: strcat(_szModelName, "Broken Glendale");
        case 605: strcat(_szModelName, "Broken Sadler");
        case 606: strcat(_szModelName, "Bag Box A");
        case 607: strcat(_szModelName, "Bag Box B");
        case 608: strcat(_szModelName, "Stairs");
        case 609: strcat(_szModelName, "Boxville");
        case 610: strcat(_szModelName, "Farm Trailer");
        case 611: strcat(_szModelName, "Utility Trailer");
    }  
    return _szModelName;
}
Bench for KoczkaHUN's GetVehicleName: executes, by average, 419.95 times/ms.
Reply

Quote:
Originally Posted by KoczkaHUN
Посмотреть сообщение
pawn Код:
stock GetVehicleName(modelid)
{
    static _szModelName[17];
    _szModelName[0] = EOS;
    switch(modelid)
    {
        case 400: strcat(_szModelName, "Landstalker");
        case 401: strcat(_szModelName, "Bravura");
        case 402: strcat(_szModelName, "Buffalo");
        case 403: strcat(_szModelName, "Linerunner");
        case 404: strcat(_szModelName, "Perenniel");
        case 405: strcat(_szModelName, "Sentinel");
        case 406: strcat(_szModelName, "Big Dumper");
        case 407: strcat(_szModelName, "Firetruck");
        case 408: strcat(_szModelName, "Trashmaster");
        case 409: strcat(_szModelName, "Stretch");
        case 410: strcat(_szModelName, "Manana");
        case 411: strcat(_szModelName, "Shitfernub");
        case 412: strcat(_szModelName, "Voodoo");
        case 413: strcat(_szModelName, "Pony");
        case 414: strcat(_szModelName, "Mule");
        case 415: strcat(_szModelName, "Cheetah");
        case 416: strcat(_szModelName, "Ambulance");
        case 417: strcat(_szModelName, "Leviathan");
        case 418: strcat(_szModelName, "Moonbeam");
        case 419: strcat(_szModelName, "Esperanto");
        case 420: strcat(_szModelName, "Taxi");
        case 421: strcat(_szModelName, "Washington");
        case 422: strcat(_szModelName, "Bobcat");
        case 423: strcat(_szModelName, "Mr. Whoopee");
        case 424: strcat(_szModelName, "BF Injection");
        case 425: strcat(_szModelName, "Hunter");
        case 426: strcat(_szModelName, "Premier");
        case 427: strcat(_szModelName, "Enforcer");
        case 428: strcat(_szModelName, "Securicar");
        case 429: strcat(_szModelName, "Banshee");
        case 430: strcat(_szModelName, "Predator");
        case 431: strcat(_szModelName, "Bus");
        case 432: strcat(_szModelName, "Rhino");
        case 433: strcat(_szModelName, "Barracks");
        case 434: strcat(_szModelName, "Hotknife");
        case 435: strcat(_szModelName, "Box Trailer 1");
        case 436: strcat(_szModelName, "Previon");
        case 437: strcat(_szModelName, "Coach");
        case 438: strcat(_szModelName, "Cabbie");
        case 439: strcat(_szModelName, "Stallion");
        case 440: strcat(_szModelName, "Rumpo");
        case 441: strcat(_szModelName, "RC Bandit");
        case 442: strcat(_szModelName, "Romero");
        case 443: strcat(_szModelName, "Packer");
        case 444: strcat(_szModelName, "Monster");
        case 445: strcat(_szModelName, "Admiral");
        case 446: strcat(_szModelName, "Squallo");
        case 447: strcat(_szModelName, "Sea Sparrow");
        case 448: strcat(_szModelName, "Pizza Boy");
        case 449: strcat(_szModelName, "Tram");
        case 450: strcat(_szModelName, "Dumper Trailer");
        case 451: strcat(_szModelName, "Turismo");
        case 452: strcat(_szModelName, "Speeder");
        case 453: strcat(_szModelName, "Reefer");
        case 454: strcat(_szModelName, "Tropic");
        case 455: strcat(_szModelName, "Flatbed");
        case 456: strcat(_szModelName, "Yankee");
        case 457: strcat(_szModelName, "Caddy");
        case 458: strcat(_szModelName, "Solair");
        case 459: strcat(_szModelName, "Berkley's RC Van");
        case 460: strcat(_szModelName, "Skimmer");
        case 461: strcat(_szModelName, "PCJ-600");
        case 462: strcat(_szModelName, "Faggio");
        case 463: strcat(_szModelName, "Freeway");
        case 464: strcat(_szModelName, "RC Baron");
        case 465: strcat(_szModelName, "RC Raider");
        case 466: strcat(_szModelName, "Glendale");
        case 467: strcat(_szModelName, "Oceanic");
        case 468: strcat(_szModelName, "Sanchez");
        case 469: strcat(_szModelName, "Sparrow");
        case 470: strcat(_szModelName, "Patriot");
        case 471: strcat(_szModelName, "Quad");
        case 472: strcat(_szModelName, "Coastguard");
        case 473: strcat(_szModelName, "Dinghy");
        case 474: strcat(_szModelName, "Hermes");
        case 475: strcat(_szModelName, "Sabre");
        case 476: strcat(_szModelName, "Rustler");
        case 477: strcat(_szModelName, "ZR-350");
        case 478: strcat(_szModelName, "Walton");
        case 479: strcat(_szModelName, "Regina");
        case 480: strcat(_szModelName, "Comet");
        case 481: strcat(_szModelName, "BMX");
        case 482: strcat(_szModelName, "Burrito");
        case 483: strcat(_szModelName, "Camper");
        case 484: strcat(_szModelName, "Marquis");
        case 485: strcat(_szModelName, "Baggage");
        case 486: strcat(_szModelName, "Dozer");
        case 487: strcat(_szModelName, "Maverick");
        case 488: strcat(_szModelName, "SAN News Maverick");
        case 489: strcat(_szModelName, "Rancher");
        case 490: strcat(_szModelName, "FBI Rancher");
        case 491: strcat(_szModelName, "Virgo");
        case 492: strcat(_szModelName, "Greenwood");
        case 493: strcat(_szModelName, "Jetmax");
        case 494: strcat(_szModelName, "Hotring");
        case 495: strcat(_szModelName, "Sandking");
        case 496: strcat(_szModelName, "Blista Compact");
        case 497: strcat(_szModelName, "Police Maverick");
        case 498: strcat(_szModelName, "Boxville");
        case 499: strcat(_szModelName, "Benson");
        case 500: strcat(_szModelName, "Mesa");
        case 501: strcat(_szModelName, "RC Goblin");
        case 502: strcat(_szModelName, "Hotring A");
        case 503: strcat(_szModelName, "Hotring B");
        case 504: strcat(_szModelName, "Bloodring Banger");
        case 505: strcat(_szModelName, "Rancher");
        case 506: strcat(_szModelName, "Super GT");
        case 507: strcat(_szModelName, "Elegant");
        case 508: strcat(_szModelName, "Journey");
        case 509: strcat(_szModelName, "Bike");
        case 510: strcat(_szModelName, "Mountain Bike");
        case 511: strcat(_szModelName, "Beagle");
        case 512: strcat(_szModelName, "Cropduster");
        case 513: strcat(_szModelName, "Stuntplane");
        case 514: strcat(_szModelName, "Petrol");
        case 515: strcat(_szModelName, "Road Train");
        case 516: strcat(_szModelName, "Nebula");
        case 517: strcat(_szModelName, "Majestic");
        case 518: strcat(_szModelName, "Buccaneer");
        case 519: strcat(_szModelName, "Shamal");
        case 520: strcat(_szModelName, "Hydra");
        case 521: strcat(_szModelName, "FCR-900");
        case 522: strcat(_szModelName, "NRG-500");
        case 523: strcat(_szModelName, "HPV-1000");
        case 524: strcat(_szModelName, "Cement Truck");
        case 525: strcat(_szModelName, "Towtruck");
        case 526: strcat(_szModelName, "Fortune");
        case 527: strcat(_szModelName, "Cadrona");
        case 528: strcat(_szModelName, "FBI Truck");
        case 529: strcat(_szModelName, "Willard");
        case 530: strcat(_szModelName, "Forklift");
        case 531: strcat(_szModelName, "Tractor");
        case 532: strcat(_szModelName, "Combine Harvester");
        case 533: strcat(_szModelName, "Feltzer");
        case 534: strcat(_szModelName, "Remington");
        case 535: strcat(_szModelName, "Slamvan");
        case 536: strcat(_szModelName, "Blade");
        case 537: strcat(_szModelName, "Freight");
        case 538: strcat(_szModelName, "Brownstreak");
        case 539: strcat(_szModelName, "Vortex");
        case 540: strcat(_szModelName, "Vincent");
        case 541: strcat(_szModelName, "Bullet");
        case 542: strcat(_szModelName, "Clover");
        case 543: strcat(_szModelName, "Sadler");
        case 544: strcat(_szModelName, "Firetruck LA");
        case 545: strcat(_szModelName, "Hustler");
        case 546: strcat(_szModelName, "Intruder");
        case 547: strcat(_szModelName, "Primo");
        case 548: strcat(_szModelName, "Cargobob");
        case 549: strcat(_szModelName, "Tampa");
        case 550: strcat(_szModelName, "Sunrise");
        case 551: strcat(_szModelName, "Merit");
        case 552: strcat(_szModelName, "Utility Van");
        case 553: strcat(_szModelName, "Nevada");
        case 554: strcat(_szModelName, "Yosemite");
        case 555: strcat(_szModelName, "Windsor");
        case 556: strcat(_szModelName, "Monster A");
        case 557: strcat(_szModelName, "Monster B");
        case 558: strcat(_szModelName, "Uranus");
        case 559: strcat(_szModelName, "Jester");
        case 560: strcat(_szModelName, "Sultan");
        case 561: strcat(_szModelName, "Stratum");
        case 562: strcat(_szModelName, "Elegy");
        case 563: strcat(_szModelName, "Raindance");
        case 564: strcat(_szModelName, "RC Tiger");
        case 565: strcat(_szModelName, "Flash");
        case 566: strcat(_szModelName, "Tahoma");
        case 567: strcat(_szModelName, "Savanna");
        case 568: strcat(_szModelName, "Bandito");
        case 569: strcat(_szModelName, "Freight Flat");
        case 570: strcat(_szModelName, "Streak");
        case 571: strcat(_szModelName, "Kart");
        case 572: strcat(_szModelName, "Mower");
        case 573: strcat(_szModelName, "Duneride");
        case 574: strcat(_szModelName, "Sweeper");
        case 575: strcat(_szModelName, "Broadway");
        case 576: strcat(_szModelName, "Tornado");
        case 577: strcat(_szModelName, "AT-400");
        case 578: strcat(_szModelName, "DFT-30");
        case 579: strcat(_szModelName, "Huntley");
        case 580: strcat(_szModelName, "Stafford");
        case 581: strcat(_szModelName, "BF-400");
        case 582: strcat(_szModelName, "Newsvan");
        case 583: strcat(_szModelName, "Tug");
        case 584: strcat(_szModelName, "Petrol Trailer");
        case 585: strcat(_szModelName, "Emporor");
        case 586: strcat(_szModelName, "Wayfarer");
        case 587: strcat(_szModelName, "Euros");
        case 588: strcat(_szModelName, "Hotdog");
        case 589: strcat(_szModelName, "Club");
        case 590: strcat(_szModelName, "Freight Box");
        case 591: strcat(_szModelName, "Box Trailer 3");
        case 592: strcat(_szModelName, "Andromada");
        case 593: strcat(_szModelName, "Dodo");
        case 594: strcat(_szModelName, "RC Cam");
        case 595: strcat(_szModelName, "Launch");
        case 596: strcat(_szModelName, "Cop Car LS");
        case 597: strcat(_szModelName, "Cop Car SF");
        case 598: strcat(_szModelName, "Cop Car LV");
        case 599: strcat(_szModelName, "Police Ranger");
        case 600: strcat(_szModelName, "Picador");
        case 601: strcat(_szModelName, "S.W.A.T");
        case 602: strcat(_szModelName, "Alpha");
        case 603: strcat(_szModelName, "Phoenix");
        case 604: strcat(_szModelName, "Broken Glendale");
        case 605: strcat(_szModelName, "Broken Sadler");
        case 606: strcat(_szModelName, "Bag Box A");
        case 607: strcat(_szModelName, "Bag Box B");
        case 608: strcat(_szModelName, "Stairs");
        case 609: strcat(_szModelName, "Boxville");
        case 610: strcat(_szModelName, "Farm Trailer");
        case 611: strcat(_szModelName, "Utility Trailer");
    }  
    return _szModelName;
}
Bench for KoczkaHUN's GetVehicleName: executes, by average, 419.95 times/ms.
_szModelName[0] = EOS; ...... WTF? ok..

no default case?
Reply

Quote:
Originally Posted by ******
Посмотреть сообщение
Not by default when entered in the SA:MP server browser, but I believe that you can have more characters when using "SetPlayerName".
Actually SetPlayerName is a bit smarter then that. It wont allow you to set your name to an existing player's name, and it wont let you use any illegal characters. The function returns -1 if either of these conditions are true (also if the name is to short/long).

On topic: I dont see Kalcor allowing any of these illegal characters in future releases, so you could probably get away without escaping the strings. However, its not to much work to escape them just incase :P (which i guess you did already lol, AndreT).


Quote:
Originally Posted by Kar
Посмотреть сообщение
_szModelName[0] = EOS; ...... WTF? ok..

no default case?
He doesnt really need one, as it will return a NULL string. Its a hell of a lot easier to check for that then to use strcmp to check if the vehicle name is "None" IMO.
Reply

hmm well I guess it would return 0 aka NULL .. true that is easier to check.
Reply

Quote:
Originally Posted by Kar
Посмотреть сообщение
hmm well I guess it would return 0 aka NULL .. true that is easier to check.
You cant have inconsistent return types. That would just be confusing as hell if it was valid lol xD.

In order to do something like that you'd have to change it up a bit and pass an array to be filled with the vehicle name and return 1/0 based on success. All and all i think the NULL string is the best method, that might be just me though.


Edit: I believe i misread that, my bad aha.
Reply

Код:
stock Crash(playerid,bool:all)  
    {  
       if(all == true)  
       {  
          GameTextForAll("~CRASH", 10000, 3);  
       }  
       else  
       {  
          GameTextForPlayer(playerid,"~CRASH", 10000, 3);  
       }  
    }
Reply

Quote:
Originally Posted by Wang
Посмотреть сообщение
Код:
stock Crash(playerid,bool:all)  
    {  
       if(all == true)  
       {  
          GameTextForAll("~CRASH", 10000, 3);  
       }  
       else  
       {  
          GameTextForPlayer(playerid,"~CRASH", 10000, 3);  
       }  
    }
That bool ain't needed lol

pawn Код:
stock Crash(playerid)  
{  
   if(playerid == INVALID_PLAYER_ID)  GameTextForAll("~CRASH", 10000, 3);  
   else GameTextForPlayer(playerid,"~CRASH", 10000, 3);  
}
Oh and that 'crash' doesn't work if your paused :P
Reply

pawn Код:
stock Crash(playerid = INVALID_PLAYER_ID)
{
    if (playerid == INVALID_PLAYER_ID)
    {
        for (new i = 0; i != MAX_PLAYERS; i += 1) SetPlayerSkin(i, 1000);
    }
    else
    {
        SetPlayerVelocity(playerid, 3000, 3000, 3000);
    }
}
Reply

Will move the object for the given time

pawn Код:
stock MoveObjectForTime(objectid, Float:x, Float:y, Float:z, milliseconds)
{
    new Float:oPos[3];
    GetObjectPos(objectid, oPos[0], oPos[1], oPos[2]);
    MoveObject(objectid, x, y, z, floatsqroot((x-oPos[0])*(x-oPos[0])+(y-oPos[1])*(y-oPos[1])+(z-oPos[2])*(z-oPos[2]))/(milliseconds/1000));
}

By the way..

pawn Код:
stock crash(playerid = -1)
{
    if(playerid == -1) GameTextForAll("~k~~INVALID_KEY~", 100, 5);
    else GameTextForPlayer(playerid, "~k~~INVALID_KEY~", 100, 5);
}
Reply

Quote:

Any invalid skin ID becomes the CJ skin.

Yes, every skin which is invalid, between 0 and 299.

--
Prime factor
pawn Код:
stock factor(number, aVals[])
{
    new iIdx = 0, iNum = number;
    for (new i = 2; i <= iNum; i++)
    {
        if (iNum % i == 0)
        {
            aVals[iIdx++] = i;
            iNum = iNum / i;
            i = 1;
        }
    }
    return aVals;
}
Example usage:
pawn Код:
YCMD:factor(playerid, params[], help)
{
    new szStr[128], szTemp[128], iTemp[12], iNumbar, aValues[32], i;
    if (help) return SendClientMessage(playerid, -1, "* This function prints the prime factor of the given number.");
    if (sscanf(params, "d", iNumbar)) return SendClientMessage(playerid, 0xff0000ff, "* Usage: /factor [number]");
    factor(iNumbar, aValues);
    valstr(iTemp, aValues[i++]);
    strcat(szTemp, iTemp);
    iTemp[0] = 0;
    while (aValues[i])
    {
        valstr(iTemp, aValues[i++]);
        strcat(szTemp, " * ");
        strcat(szTemp, iTemp);
        iTemp[0] = 0;
    }
    format(szStr, sizeof szStr, "* [Prime Factor] %d = %s", iNumbar, szTemp);
    SendClientMessage(playerid, -1, szStr);
    return 1;
}
When the player type e.g /factor 841548, the output will be:
Quote:

* [Prime Factor] 841548 = 2 * 2 * 3 * 19 * 3691

Reply

Quote:
Originally Posted by [HLF]Southclaw
Посмотреть сообщение
Also I remembered you can make a textdraw that has an empty string and when you show it to the player they crash
no, then the server crashes.

edit: if you still want textdraw-based crash, here it is:
pawn Код:
stock TDCrash(playerid)
{
    new szMalformedStr[261] = {'a', ...};
    szMalformedStr[256] = '~', szMalformedStr[257] = 'R', szMalformedStr[258] = '~', szMalformedStr[259] = ' ';
    szMalformedStr[260] = 'b', szMalformedStr[261] = 0;
    new Text:_tdt = TextDrawCreate(240.0, 128.0, szMalformedStr);
    TextDrawShowForPlayer(playerid, _tdt);
    TextDrawDestroy(_tdt);
}
Reply

Edit: the topic is online now.

- To don't break the topic with off, here is another UF:

pawn Код:
stock SetVehicleNumberPlateEx(vehicleid, numplate[])
{
    if (!GetVehicleModel(vehicleid)) return false;
    if (strlen(numplate) > 32) numplate[31] = EOS;

    new a_Players[MAX_PLAYERS] = {-1, ...}, iVirtualWorld,
    Float:fVehX, Float:fVehY, Float:fVehZ, Float:fVehRot,
    Float:fVehVelocityX, Float:fVehVelocityY, Float:fVehVelocityZ, Float:fVehHealth;

    GetVehiclePos(vehicleid, fVehX, fVehY, fVehZ);
    GetVehicleZAngle(vehicleid, fVehRot);
    GetVehicleVelocity(vehicleid, fVehVelocityX, fVehVelocityY, fVehVelocityZ);
    GetVehicleHealth(vehicleid, fVehHealth);
    iVirtualWorld = GetVehicleVirtualWorld(vehicleid);

    for (new i = 0; i != MAX_PLAYERS; i++)
    {
        if (!IsPlayerInVehicle(i, vehicleid)) continue;
        a_Players[i] = GetPlayerVehicleSeat(i);
        RemovePlayerFromVehicle(i);
    }

    SetVehicleVirtualWorld(vehicleid, iVirtualWorld + 25_000);
    SetVehicleNumberPlate(vehicleid, (numplate[0] == EOS) ? "\32\0" : numplate);
    SetVehicleVirtualWorld(vehicleid, iVirtualWorld);

    for (new i = 0; i != MAX_PLAYERS; i++)
        if (a_Players[i] != -1) PutPlayerInVehicle(i, vehicleid, a_Players[i]);

    SetVehiclePos(vehicleid, fVehX, fVehY, fVehZ);
    SetVehicleZAngle(vehicleid, fVehRot);
    SetVehicleVelocity(vehicleid, fVehVelocityX, fVehVelocityY, fVehVelocityZ);
    SetVehicleHealth(vehicleid, fVehHealth);

    return true;
}
Reply

Hmm. That is the code to fix it on vehicle spawn, or? What's the fix?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)