Advertisement
CreativityLacker

clFunctions Version 2.25

Nov 9th, 2012
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 19.63 KB | None | 0 0
  1. #include <a_samp>
  2. #include <Others/sscanf2>
  3.  
  4. // Functions
  5. /*
  6. native GetPlayersName(playerid)
  7. native SetPlayerPositionEx(playerid, Float:x, Float:y, Float:z, Float:angle, vworld, interior)
  8. native TeleportPlayerToPlayer(playerid, targetid)
  9. native TeleportCarToPlayer(vehicleid, playerid)
  10. native TeleportPlayerToCar(playerid, vehicleid)
  11. native GetPlayerIPAddress(playerid)
  12. native HealPlayer(playerid)
  13. native KillPlayer(playerid)
  14. native CrashPlayer(playerid)
  15. native GivePlayerHealth(playerid, Float:health)
  16. native TakePlayerHealth(playerid, Float:health)
  17. native BankruptPlayer(playerid)
  18. native SetPlayerCash(playerid)
  19. native GivePlayerScore(playerid, score)
  20. native TakePlayerScore(playerid, score)
  21. native SlapPlayer(playerid)
  22. native IsPlayerSwimming(playerid)
  23. native IsPlayerFalling(playerid)
  24. native IsPlayerInModdingShop(playerid)
  25. native GetVehicleType(modelid)
  26. stock GetPlayerVehicleSpeed(playerid)
  27. native ExplodePlayer(playerid)
  28. native IsPlayerAiming(playerid)
  29. native GetWeaponNameByID(weaponid)
  30. native GetWeaponSlotByID(weaponid)
  31. native GetPlayerArmedWeaponAmmo(playerid)
  32. native GetVehicleNameByModel(model)
  33. native GetWeatherName(weatherid)
  34. native LoadObjectsFromFile(const filename[])
  35. native LoadVehiclesFromFile(const filename[])
  36. native CreateLogEntry(log[], text[])
  37. native HealAll()
  38. native ArmourAll()
  39. native FreezeAll()
  40. native DisarmAll()
  41. native GiveWeaponToAll(weaponid, ammo)
  42. native GiveCashToAll(cash)
  43. native GiveScoreToAll(score)
  44. native UnfreezeAll()
  45. native GetOnlinePlayersCount()
  46. */
  47.  
  48.  
  49. #define TYPE_INVALID    -1
  50. #define TYPE_AIRPLANE   0
  51. #define TYPE_HELICOPTER 1
  52. #define TYPE_BIKE   2
  53. #define TYPE_CONVERTIBLE    3
  54. #define TYPE_INDUSTRIAL     4
  55. #define TYPE_LOWRIDER       5
  56. #define TYPE_OFFROAD        6
  57. #define TYPE_PUBLIC 7
  58. #define TYPE_SALOON         8
  59. #define TYPE_SPORT  9
  60. #define TYPE_STATION    10
  61. #define TYPE_BOAT   11
  62. #define TYPE_TRAILER    12
  63. #define TYPE_UNIQUE 13
  64. #define TYPE_RC 14
  65.  
  66. new VehicleNames[212][] = {
  67.         {"Landstalker"},
  68.         {"Bravura"},
  69.         {"Buffalo"},
  70.         {"Linerunner"},
  71.         {"Perrenial"},
  72.         {"Sentinel"},
  73.         {"Dumper"},
  74.         {"Firetruck"},
  75.         {"Trashmaster"},
  76.         {"Stretch"},
  77.         {"Manana"},
  78.         {"Infernus"},
  79.         {"Voodoo"},
  80.         {"Pony"},
  81.         {"Mule"},
  82.         {"Cheetah"},
  83.         {"Ambulance"},
  84.         {"Leviathan"},
  85.         {"Moonbeam"},
  86.         {"Esperanto"},
  87.         {"Taxi"},
  88.         {"Washington"},
  89.         {"Bobcat"},
  90.         {"Mr Whoopee"},
  91.         {"BF Injection"},
  92.         {"Hunter"},
  93.         {"Premier"},
  94.         {"Enforcer"},
  95.         {"Securicar"},
  96.         {"Banshee"},
  97.         {"Predator"},
  98.         {"Bus"},
  99.         {"Rhino"},
  100.         {"Barracks"},
  101.         {"Hotknife"},
  102.         {"Trailer 1"},
  103.         {"Previon"},
  104.         {"Coach"},
  105.         {"Cabbie"},
  106.         {"Stallion"},
  107.         {"Rumpo"},
  108.         {"RC Bandit"},
  109.         {"Romero"},
  110.         {"Packer"},
  111.         {"Monster"},
  112.         {"Admiral"},
  113.         {"Squalo"},
  114.         {"Seasparrow"},
  115.         {"Pizzaboy"},
  116.         {"Tram"},
  117.         {"Trailer 2"},
  118.         {"Turismo"},
  119.         {"Speeder"},
  120.         {"Reefer"},
  121.         {"Tropic"},
  122.         {"Flatbed"},
  123.         {"Yankee"},
  124.         {"Caddy"},
  125.         {"Solair"},
  126.         {"Berkley's RC Van"},
  127.         {"Skimmer"},
  128.         {"PCJ-600"},
  129.         {"Faggio"},
  130.         {"Freeway"},
  131.         {"RC Baron"},
  132.         {"RC Raider"},
  133.         {"Glendale"},
  134.         {"Oceanic"},
  135.         {"Sanchez"},
  136.         {"Sparrow"},
  137.         {"Patriot"},
  138.         {"Quad"},
  139.         {"Coastguard"},
  140.         {"Dinghy"},
  141.         {"Hermes"},
  142.         {"Sabre"},
  143.         {"Rustler"},
  144.         {"ZR-350"},
  145.         {"Walton"},
  146.         {"Regina"},
  147.         {"Comet"},
  148.         {"BMX"},
  149.         {"Burrito"},
  150.         {"Camper"},
  151.         {"Marquis"},
  152.         {"Baggage"},
  153.         {"Dozer"},
  154.         {"Maverick"},
  155.         {"News Chopper"},
  156.         {"Rancher"},
  157.         {"FBI Rancher"},
  158.         {"Virgo"},
  159.         {"Greenwood"},
  160.         {"Jetmax"},
  161.         {"Hotring"},
  162.         {"Sandking"},
  163.         {"Blista Compact"},
  164.         {"Police Maverick"},
  165.         {"Boxville"},
  166.         {"Benson"},
  167.         {"Mesa"},
  168.         {"RC Goblin"},
  169.         {"Hotring Racer A"},
  170.         {"Hotring Racer B"},
  171.         {"Bloodring Banger"},
  172.         {"Rancher"},
  173.         {"Super GT"},
  174.         {"Elegant"},
  175.         {"Journey"},
  176.         {"Bike"},
  177.         {"Mountain Bike"},
  178.         {"Beagle"},
  179.         {"Cropdust"},
  180.         {"Stunt"},
  181.         {"Tanker"},
  182.         {"Roadtrain"},
  183.         {"Nebula"},
  184.         {"Majestic"},
  185.         {"Buccaneer"},
  186.         {"Shamal"},
  187.         {"Hydra"},
  188.         {"FCR-900"},
  189.         {"NRG-500"},
  190.         {"HPV1000"},
  191.         {"Cement Truck"},
  192.         {"Tow Truck"},
  193.         {"Fortune"},
  194.         {"Cadrona"},
  195.         {"FBI Truck"},
  196.         {"Willard"},
  197.         {"Forklift"},
  198.         {"Tractor"},
  199.         {"Combine"},
  200.         {"Feltzer"},
  201.         {"Remington"},
  202.         {"Slamvan"},
  203.         {"Blade"},
  204.         {"Freight"},
  205.         {"Streak"},
  206.         {"Vortex"},
  207.         {"Vincent"},
  208.         {"Bullet"},
  209.         {"Clover"},
  210.         {"Sadler"},
  211.         {"Firetruck LA"},
  212.         {"Hustler"},
  213.         {"Intruder"},
  214.         {"Primo"},
  215.         {"Cargobob"},
  216.         {"Tampa"},
  217.         {"Sunrise"},
  218.         {"Merit"},
  219.         {"Utility"},
  220.         {"Nevada"},
  221.         {"Yosemite"},
  222.         {"Windsor"},
  223.         {"Monster A"},
  224.         {"Monster B"},
  225.         {"Uranus"},
  226.         {"Jester"},
  227.         {"Sultan"},
  228.         {"Stratum"},
  229.         {"Elegy"},
  230.         {"Raindance"},
  231.         {"RC Tiger"},
  232.         {"Flash"},
  233.         {"Tahoma"},
  234.         {"Savanna"},
  235.         {"Bandito"},
  236.         {"Freight Flat"},
  237.         {"Streak Carriage"},
  238.         {"Kart"},
  239.         {"Mower"},
  240.         {"Duneride"},
  241.         {"Sweeper"},
  242.         {"Broadway"},
  243.         {"Tornado"},
  244.         {"AT-400"},
  245.         {"DFT-30"},
  246.         {"Huntley"},
  247.         {"Stafford"},
  248.         {"BF-400"},
  249.         {"Newsvan"},
  250.         {"Tug"},
  251.         {"Trailer 3"},
  252.         {"Emperor"},
  253.         {"Wayfarer"},
  254.         {"Euros"},
  255.         {"Hotdog"},
  256.         {"Club"},
  257.         {"Freight Carriage"},
  258.         {"Trailer 3"},
  259.         {"Andromada"},
  260.         {"Dodo"},
  261.         {"RC Cam"},
  262.         {"Launch"},
  263.         {"Police Car (LSPD)"},
  264.         {"Police Car (SFPD)"},
  265.         {"Police Car (LVPD)"},
  266.         {"Police Ranger"},
  267.         {"Picador"},
  268.         {"S.W.A.T. Van"},
  269.         {"Alpha"},
  270.         {"Phoenix"},
  271.         {"Glendale"},
  272.         {"Sadler"},
  273.         {"Luggage Trailer A"},
  274.         {"Luggage Trailer B"},
  275.         {"Stair Trailer"},
  276.         {"Boxville"},
  277.         {"Farm Plow"},
  278.         {"Utility Trailer"}
  279. };
  280.  
  281.  
  282.  
  283. stock GetPlayersName(playerid)
  284. {
  285.     new name[MAX_PLAYER_NAME];
  286.     GetPlayerName(playerid, name, sizeof(name) );
  287.     return name;
  288. }
  289.  
  290. stock SetPlayerPositionEx(playerid, Float:x, Float:y, Float:z, Float:angle, vworld, interior)
  291. {
  292.     SetPlayerPos(playerid, x, y, z);
  293.     SetPlayerFacingAngle(playerid, angle);
  294.     SetPlayerVirtualWorld(playerid, vworld);
  295.     SetPlayerInterior(playerid, interior);
  296.     return 1;
  297. }
  298.  
  299. stock TeleportPlayerToPlayer(playerid, targetid)
  300. {
  301.     new Float:Pos[3];
  302.     if(playerid == INVALID_PLAYER_ID || targetid == INVALID_PLAYER_ID) return 0;
  303.     else
  304.     {
  305.         new Float:Pos[3];
  306.         GetPlayerPos(targetid, Pos[0], Pos[1], Pos[2]);
  307.         SetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
  308.         SetPlayerInterior(playerid, GetPlayerInterior(targetid) );
  309.         SetPlayerVirtualWorld(playerid, GetPlayerVirtualWorld(targetid) );
  310.     }
  311.     return 1;
  312. }
  313. stock TeleportCarToPlayer(vehicleid, playerid)
  314. {
  315.     if(vehicleid == INVALID_VEHICLE_ID || playerid == INVALID_PLAYER_ID) return 0;
  316.     else
  317.     {
  318.         new Float:PlayerPos[3];
  319.         GetPlayerPos(playerid, PlayerPos[0], PlayerPos[1], PlayerPos[2]);
  320.         SetVehiclePos(vehicleid, PlayerPos[0], PlayerPos[1], PlayerPos[2]);
  321.     }
  322.     return 1;
  323. }
  324.  
  325. stock TeleportPlayerToCar(playerid, vehicleid)
  326. {
  327.     if(vehicleid == INVALID_VEHICLE_ID || playerid == INVALID_PLAYER_ID) return 0;
  328.     else
  329.     {
  330.         new Float:CarPos[3];
  331.         GetVehiclePos(vehicleid, CarPos[0], CarPos[1], CarPos[2]);
  332.         SetVehiclePos(vehicleid, PlayerPos[0], PlayerPos[1], PlayerPos[2]);
  333.     }
  334.     return 1;
  335. }
  336.  
  337. stock GetPlayerIPAddress(playerid)
  338. {
  339.     new ip[20];
  340.     GetPlayerIp(playerid, ip, sizeof(ip) );
  341.     return ip;
  342. }
  343.  
  344. stock HealPlayer(playerid) return SetPlayerHealth(playerid, 100);
  345. stock KillPlayer(playerid) return SetPlayerHealth(playerid, -5);
  346.  
  347. stock GivePlayerHealth(playerid, Float:health)
  348. {
  349.     new Float:hp;
  350.     GetPlayerHealth(playerid, hp);
  351.     new calc = floatadd(hp, health);
  352.     SetPlayerHealth(playerid, calc);
  353.     return 1;
  354. }
  355.  
  356. stock TakePlayerHealth(playerid, Float:health)
  357. {
  358.     new Float:hp;
  359.     GetPlayerHealth(playerid, hp);
  360.     new calc = floatsub(hp, health);
  361.     SetPlayerHealth(playerid, calc);
  362.     return 1;
  363. }
  364.  
  365. stock BankruptPlayer(playerid) return ResetPlayerMoney(playerid)
  366.  
  367. stock SetPlayerCash(playerid, cash)
  368. {
  369.     ResetPlayerMoney(playerid);
  370.     GivePlayerMoney(playerid, cash);
  371. }
  372.  
  373. stock GivePlayerScore(playerid, score)
  374. {
  375.     new pscore = GetPlayerScore(playerid);
  376.     SetPlayerScore(playerid, pscore+score);
  377.     return 1;
  378. }
  379.  
  380. stock TakePlayerScore(playerid, score)
  381. {
  382.     new pscore = GetPlayerScore(playerid);
  383.     SetPlayerScore(playerid, pscore-score);
  384.     return 1;
  385. }
  386.  
  387. stock SlapPlayer(playerid)
  388. {
  389.     new Float:Pos[3];
  390.     GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2] );
  391.     SetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]+10);
  392.     return 1;
  393. }
  394.  
  395. stock ExplodePlayer(playerid)
  396. {
  397.     new Float:Pos[3];
  398.     GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2] );
  399.     CreateExplosion(Pos[0], Pos[1], Pos[2], 8, 5.0);
  400.     return 1;
  401. }
  402.  
  403. stock bool:IsPlayerAiming(playerid)
  404. {
  405.     new anim = GetPlayerAnimationIndex(playerid);
  406.     switch(anim)
  407.     {
  408.         case 1167, 1365, 1643, 1453, 220: return true;
  409.     }
  410.     return false;
  411. }
  412.  
  413. stock bool:IsPlayerFalling(playerid)
  414. {
  415.     new animlib[1], animname[32];
  416.     if(GetPlayerAnimationIndex(playerid))
  417.     {
  418.         GetAnimationName(GetPlayerAnimationIndex(playerid),animlib,0,animname,32);
  419.         if(!strcmp(animname, "FALL_FALL") || !strcmp(animname, "FALL_GLIDE")) return true;
  420.     }
  421.     return false;
  422. }
  423.  
  424. stock bool:IsPlayerInModdingShop(playerid)
  425. {
  426.     new mode = GetPlayerCameraMode(playerid);
  427.     if(mode == 15) return true;
  428.     return false;
  429. }
  430.  
  431. stock bool:IsPlayerSwimming(playerid)
  432. {
  433.     new animlib[1], animname[32];
  434.     if(GetPlayerAnimationIndex(playerid))
  435.     {
  436.         GetAnimationName(GetPlayerAnimationIndex(playerid),animlib,0,animname,32);
  437.         if(!strcmp(animname, "SWIM_CRAWL") || !strcmp(animname, "SWIM_BREAST") || !strcmp(animname, "SWIM_GLIDE") || !strcmp(animname, "SWIM_DIVE_UNDER") || !strcmp(animname, "SWIM_UNDER")) return true;
  438.     }
  439.     return false;
  440. }
  441.  
  442. stock GetPlayerVehicleSpeed(playerid)
  443. {
  444.     if(!IsPlayerInAnyVehicle(playerid) ) return 0;
  445.     else
  446.     {
  447.         new Float:Speed[3], Float:final_speed, final_speed_int;
  448.         new vehicleid = GetPlayerVehicleID(playerid);
  449.         GetVehicleVelocity(vehicleid,Speed[0],Speed[1],Speed[2]);
  450.         final_speed = floatsqroot(((Speed[0]*Speed[0])+(Speed[1]*Speed[1]))+(Speed[2]*Speed[2]))*250.666667;
  451.         final_speed_int = floatround(final_speed,floatround_round);
  452.         return final_speed_int;
  453.     }
  454. }
  455.  
  456. stock GetWeaponNameByID(weaponid)
  457. {
  458.     new gunname[32];
  459.     switch (weaponid)
  460.     {
  461.         case 1..17,22..43,46: GetWeaponName(weaponid,gunname,sizeof(gunname));
  462.         case 0: format(gunname,32,"%s","Fist");
  463.         case 18: format(gunname,32,"%s","Molotov");
  464.         case 44: format(gunname,32,"%s","Night Goggles");
  465.         case 45: format(gunname,32,"%s","Thermal Goggles");
  466.         default: format(gunname,32,"%s","Unknown weapon");
  467.     }
  468.     return gunname;
  469. }
  470.  
  471. stock GetWeaponSlot(weaponid)
  472. {
  473.     new slot;
  474.     switch(weaponid)
  475.     {
  476.         case 0,1: slot = 0;
  477.         case 2 .. 9: slot = 1;
  478.         case 10 .. 15: slot = 10;
  479.         case 16 .. 18, 39: slot = 8;
  480.         case 22 .. 24: slot =2;
  481.         case 25 .. 27: slot = 3;
  482.         case 28, 29, 32: slot = 4;
  483.         case 30, 31: slot = 5;
  484.         case 33, 34: slot = 6;
  485.         case 35 .. 38: slot = 7;
  486.         case 40: slot = 12;
  487.         case 41 .. 43: slot = 9;
  488.         case 44 .. 46: slot = 11;
  489.     }
  490.     return slot;
  491. }
  492.  
  493. stock GetPlayerAmmoEx(playerid)
  494. {
  495.     new weapon[3];
  496.     weapon[0] = GetWeaponSlot(GetPlayerWeapon(playerid) );
  497.     GetPlayerWeaponData(playerid, weapon[0], weapon[1], weapon[2]);
  498.     return weapon[2];
  499. }
  500.  
  501. stock GetVehicleNameByModel(model)
  502. {
  503.     new string[32];
  504.     format(string,sizeof string,"%s",VehicleNames[model -400]);
  505.     return string;
  506. }
  507.  
  508. stock GetVehicleSpeed(vehicleid)
  509. {
  510.     new Float:Speed[3];
  511.     GetVehicleVelocity(vehicleid, Speed[0], Speed[1], Speed[2]);
  512.     new calculate1 = floatsqroot((Speed[0]*Speed[0]+Speed[1]*Speed[1]));
  513.     return floatround(calculate1* 100.0 * 1.6);
  514. }
  515.  
  516. stock GetVehicleType(model)
  517. {
  518.     switch(model)
  519.     {
  520.         case 460, 476, 511, 512, 519, 520, 553, 577, 592, 593: return TYPE_AIRPLANE;
  521.         case 417, 425, 447, 469 ,487, 488, 497, 548, 563: return TYPE_HELICOPTER;
  522.         case 448, 461 .. 463, 468, 471, 481, 509, 510, 521 .. 523, 581, 586: return TYPE_BIKE;
  523.         case 439, 480, 533, 555: return TYPE_CONVERTIBLE;
  524.         case 403, 408, 413, 414, 422, 440, 443, 455, 456, 459, 478, 482, 498, 499, 514, 515, 524, 531, 543, 552, 554, 578, 582, 600, 605, 609: return TYPE_INDUSTRIAL;
  525.         case 412, 534 .. 536, 566, 567, 575, 576: return TYPE_LOWRIDER;
  526.         case 400, 424, 444, 470, 489, 495, 500, 505, 556, 557, 568, 573, 579: return TYPE_OFFROAD;
  527.         case 407, 416, 420, 427, 431, 432, 433, 437, 438, 490, 528, 544, 596 .. 599, 601: return TYPE_PUBLIC;
  528.         case 401, 405, 410, 419, 421, 426, 436, 445, 466, 491, 492, 504, 507, 516 ..518, 526, 527, 529, 542, 546, 547, 549, 550, 560, 551, 562, 580, 585, 604: return TYPE_SALOON;
  529.         case 402, 411, 415, 429, 451, 475, 477, 494, 496, 541, 502, 503, 506, 558, 559, 565, 587, 589, 602, 603: return TYPE_SPORT;
  530.         case 404, 418, 458, 479, 561: return TYPE_STATION;
  531.         case 430, 446, 452, 453, 454, 472, 473, 484, 493, 595: return TYPE_BOAT;
  532.         case 435, 450, 569, 570, 584, 590, 591, 606, 607, 608, 610, 611: return TYPE_TRAILER;
  533.         case 406, 409, 423, 428, 434, 442, 449, 457, 483, 485, 486, 508, 525, 530, 532, 537 .. 539, 545, 571, 572, 574, 583, 588: return TYPE_UNIQUE;
  534.         case 441, 464, 465, 501, 564, 594: return TYPE_RC;
  535.     }
  536.     return TYPE_INVALID;
  537. }
  538.  
  539. stock GetWeatherName(weatherid)
  540. {
  541.     new wName[80];
  542.     switch(weatherid)
  543.     {
  544.         case 0..7: wName = "Clear skies";
  545.         case 8: wName = "Stormy";
  546.         case 9: wName = "Cloudy";
  547.         case 10: wName = "Clear skies";
  548.         case 11: wName = "Heatwave";
  549.         case 12..15: wName = "Cloudy/Clear";
  550.         case 16: wName = "Cloudy/Rainy";
  551.         case 17, 18: wName = "Heatwave";
  552.         case 19: wName = "Sandstorm";
  553.         case 20: wName = "Foggy/Greenish";
  554.         case 21,22: wName = "Dark clouds";
  555.         case 23..26: wName = "Heatwave";
  556.         case 27..29: wName = "Clear skies";
  557.         case 30: wName = "Cloudy";
  558.         case default: wName = "Unknown";
  559.     }
  560.     return wName;
  561. }
  562.  
  563. stock WriteLogEntry(log[], string[])
  564. {
  565.     new lstring[180];
  566.     new File:Logger = fopen(log, io_append);
  567.     if(!fexist(log)) printf("[LOGS] The log %s doesn't exist! 'WriteLogEntry' function not completed ", log);
  568.     else
  569.     {
  570.         new date[3], time[3];
  571.         gettime(time[0], time[1], time[2]);
  572.         getdate(date[0], date[1], date[2]);
  573.         format(lstring, sizeof(lstring), "\r\n[%02d/%02d/%d] [%02d:%02d:%02d] %s ", date[0], date[1], date[2], time[0], time[1], time[2], string);
  574.         fwrite(Logger, lstring);
  575.         fclose(Logger);
  576.     }
  577.     return 1;
  578. }
  579. stock LoadObjectsFromFile(const filename[])
  580. {
  581.     new Objects_loaded;
  582.     if(!fexist(filename))
  583.     return printf("[Objects] Couldn't load objects from %s [Reason : File doesn't exist]", filename);
  584.  
  585.     new File:Handler = fopen(filename, io_read);
  586.     if(!Handler) return printf("[Objects] Couldn't load objects from %s [Reason : I/O Error]", filename);
  587.  
  588.     new Line[256], Index = -1, Model, Float:PosX, Float:PosY, Float:PosZ, Float:RotX, Float:RotY, Float:RotZ,Float:DrawDistance;
  589.     Objects_loaded = 0;
  590.     while(fread(Handler, Line))
  591.     {
  592.         Index++;
  593.         new EOL = strfind(Line, ";", false);
  594.         if(EOL != -1) strdel(Line, EOL - 1, sizeof Line - 1);
  595.         else
  596.         {
  597.             printf("[Objects] Error reading @LineIndex %i from %s (EOL not found)", Index, filename);
  598.             continue;
  599.         }
  600.         if(!sscanf(Line[13], "p<,>iffffffF(100)", Model, PosX, PosY, PosZ, RotX, RotY, RotZ, DrawDistance))
  601.         {
  602.             CreateObject(Model, PosX, PosY, PosZ, RotX, RotY, RotZ, DrawDistance);
  603.             Objects_loaded++;
  604.         }
  605.         else printf("[Objects] Error reading @LineIndex %i from %s (Invalid format)", Index, filename);
  606.      }
  607.     fclose(Handler);
  608.     printf("[Objects] Loaded %d objects from: %s", Objects_loaded, filename);
  609.     return true;
  610. }
  611.  
  612. stock LoadVehiclesFromFile(const filename[]) // Thanks to PLEO for doing most of it
  613. {
  614.     new count;
  615.     if(!fexist(filename)) return printf("[Vehicles] Couldn't load vehicles from %s [Reason : File doesn't exist] ", filename);
  616.     new File:Handler = fopen(filename, io_read);
  617.     if(!Handler) return printf("[Vehicles] Couldn't load vehicles from %s [Reason : I/O Error]", filename);
  618.     new Line[256], Index = -1, Model, Float:Pos[3], Float:Angle, col1, col2, respawn_delay;
  619.     while(fread(Handler, Line))
  620.         {
  621.         Index++;
  622.         new EOL = strfind(Line, ";", false);
  623.         if(EOL != -1) { strdel(Line, EOL - 1, sizeof Line - 1); }
  624.         else
  625.         {
  626.             printf("[Vehicles] Error reading @LineIndex %i from %s (EOL not found)", Index, filename);
  627.         }
  628.         if(!sscanf(Line[14], "p<,>iffffddd", Model, Pos[0], Pos[1], Pos[2], Angle, col1, col2, respawn_delay))
  629.         {
  630.             CreateVehicle(Model, Pos[0], Pos[1], Pos[2], Angle, col1, col2, respawn_delay);
  631.             count++;
  632.         }
  633.         else
  634.         if(!sscanf(Line[17], "p<,>iffffdd", Model, Pos[0], Pos[1], Pos[2], Angle, col1, col2))
  635.         {
  636.             AddStaticVehicle(Model, Pos[0], Pos[1], Pos[2], Angle, col1, col2);
  637.             count++;
  638.         }
  639.         else
  640.         if(!sscanf(Line, "p<,>iffffdd", Model, Pos[0], Pos[1], Pos[2], Angle, col1, col2))
  641.         {
  642.             CreateVehicle(Model, Pos[0], Pos[1], Pos[2], Angle, col1, col2, respawn_delay);
  643.             count++;
  644.         }
  645.         else printf("[Vehicles] Error reading @LineIndex %i from %s [Invalid format]", Index, filename);
  646.     }
  647.     fclose(Handler);
  648.     printf("[Vehicles] Loaded %d vehicles from %s", count, filename);
  649.     return true;
  650. }
  651.  
  652.  
  653. stock HealAll()
  654. {
  655.     for(new i; i < MAX_PLAYERS; i++) SetPlayerHealth(i, 100);
  656.     return 1;
  657. }
  658.  
  659. stock ArmourAll()
  660. {
  661.     for(new i; i < MAX_PLAYERS; i++) SetPlayerArmour(playerid, 100);
  662.     return 1;
  663. }
  664.  
  665. stock DisarmAll()
  666. {
  667.     for(new i; i < MAX_PLAYERS; i++) ResetPlayerWeapons(i);
  668.     return 1;
  669. }
  670.  
  671. stock GiveWeaponToAll(weaponid, ammo)
  672. {
  673.     if(weaponid > 46) return 0;
  674.     for(new i; i < MAX_PLAYERS; i++) GivePlayerWeapon(playerid, weaponid, ammo);
  675.     return 1;
  676. }
  677.  
  678. stock GiveCashToAll(cash)
  679. {
  680.     for(new i; i < MAX_PLAYERS; i++) GivePlayerMoney(i, cash);
  681.     return 1;
  682. }
  683.  
  684. stock GiveScoreToAll(score)
  685. {
  686.     for(new i; i < MAX_PLAYERS; i++)
  687.     {
  688.         new pscore = GetPlayerScore(i);
  689.         SetPlayerScore(i, pscore+score);
  690.     }
  691.     return 1;
  692. }
  693.  
  694. stock FreezeAll()
  695. {
  696.     for(new i; i < MAX_PLAYERS; i++) TogglePlayerControllable(i, false);
  697.     return 1;
  698. }
  699.  
  700. stock UnfreezeAll()
  701. {
  702.     for(new i; i < MAX_PLAYERS; i++) TogglePlayerControllable(i, true);
  703.     return 1;
  704. }
  705.  
  706. stock GetOnlinePlayersCount()
  707. {
  708.     new count;
  709.     for(new x=0; x< MAX_PLAYERS; x++)
  710.     {
  711.         if(IsPlayerConnected(x))
  712.         {
  713.             count++;
  714.         }
  715.     }
  716.     return count;
  717. }
  718.  
  719. stock GetValidObjectsCount()
  720. {
  721.     new count;
  722.     for(new x = 0; x < MAX_OBJECTS; x++)
  723.     {
  724.         if(IsValidObject(x))
  725.         {
  726.             count++;
  727.         }
  728.     }
  729.     return count;
  730. }
  731.  
  732. stock GetValidVehiclesCount()
  733. {
  734.     new count;
  735.     for(new x = 0; x < MAX_VEHICLES; x++)
  736.     {
  737.         if(x != INVALID_VEHICLE_ID)
  738.         {
  739.             count++;
  740.         }
  741.     }
  742.     return count;
  743. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement