Advertisement
Kyance

SAMP - Melee Weapons BETA

Oct 13th, 2014
525
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 28.33 KB | None | 0 0
  1. #define FILTERSCRIPT
  2.  
  3. #include <a_samp>
  4. #include <foreach>
  5. #include <zcmd>
  6. #include <sscanf2>
  7.  
  8. #define DIALOG_INVENTORY 1337
  9. #define DIALOG_SELL_OR_TAKE 1338
  10.  
  11. #define MAX_EXPERIENCE_PICKUPS 50
  12.  
  13. new Float:RandomLvlSpawns[][113] = {
  14.     {1568.2250,-1693.5483,5.8906,177.0983},
  15.     {-1604.8442,732.9442,-5.2344,37.6041},
  16.     {2343.4553,2455.5994,14.9688,96.5022},
  17.     {1568.2250,-1693.5483,5.8906,177.0983},
  18.     {-1604.8442,732.9442,-5.2344,37.6041},
  19.     {1609.5922,1820.9641,10.8280,348.1614},
  20.     {2786.2183,-2436.7859,13.6340,82.3043},
  21.     {-1308.4493,504.9661,11.1953,132.5},
  22.     {272.6040,1989.7307,17.6406,268.3605},
  23.     {1751.1097,-2106.4529,13.5469,183.1979}, // El-Corona - Outside random house
  24.     {2652.6418,-1989.9175,13.9988,182.7107}, // Random house in willowfield - near playa de seville and stadium
  25.     {2489.5225,-1957.9258,13.5881,2.3440}, // Hotel in willowfield - near cluckin bell
  26.     {2689.5203,-1695.9354,10.0517,39.5312}, // Outside stadium - lots of cars
  27.     {2770.5393,-1628.3069,12.1775,4.9637}, // South in east beach - north of stadium - carparks nearby
  28.     {2807.9282,-1176.8883,25.3805,173.6018}, // North in east beach - near apartments
  29.     {2552.5417,-958.0850,82.6345,280.2542}, // Random house north of Las Colinas
  30.     {2232.1309,-1159.5679,25.8906,103.2939}, // Jefferson motel
  31.     {2388.1003,-1279.8933,25.1291,94.3321}, // House south of pig pen
  32.     {2481.1885,-1536.7186,24.1467,273.4944}, // East LS - near clucking bell and car wash
  33.     {2495.0720,-1687.5278,13.5150,359.6696}, // Outside CJ's house - lots of cars nearby
  34.     {2306.8252,-1675.4340,13.9221,2.6271}, // House in ganton - lots of cars nearby
  35.     {2191.8403,-1455.8251,25.5391,267.9925}, // House in south jefferson - lots of cars nearby
  36.     {1830.1359,-1092.1849,23.8656,94.0113}, // Mulholland intersection carpark
  37.     {2015.3630,-1717.2535,13.5547,93.3655}, // Idlewood house
  38.     {1654.7091,-1656.8516,22.5156,177.9729}, // Right next to PD
  39.     {1219.0851,-1812.8058,16.5938,190.0045}, // Conference Center
  40.     {1508.6849,-1059.0846,25.0625,1.8058}, // Across the street of BANK - lots of cars in intersection carpark
  41.     {1421.0819,-885.3383,50.6531,3.6516}, // Outside house in vinewood
  42.     {1133.8237,-1272.1558,13.5469,192.4113}, // Near hospital
  43.     {1235.2196,-1608.6111,13.5469,181.2655}, // Backalley west of mainstreet
  44.     {590.4648,-1252.2269,18.2116,25.0473}, // Outside "BAnk of San Andreas"
  45.     {842.5260,-1007.7679,28.4185,213.9953}, // North of Graveyard
  46.     {911.9332,-1232.6490,16.9766,5.2999}, // LS Film Studio
  47.     {477.6021,-1496.6207,20.4345,266.9252}, // Rodeo Place
  48.     {255.4621,-1366.3256,53.1094,312.0852}, // Outside propery in richman
  49.     {281.5446,-1261.4562,73.9319,305.0017}, // Another richman property
  50.     {790.1918,-839.8533,60.6328,191.9514}, // Mulholland house
  51.     {1299.1859,-801.4249,84.1406,269.5274}, // Maddoggs
  52.     {1240.3170,-2036.6886,59.9575,276.4659}, // Verdant Bluffs
  53.     {2215.5181,-2627.8174,13.5469,273.7786}, // Ocean docks 1
  54.     {2509.4346,-2637.6543,13.6453,358.3565}, // Ocean Docks spawn 2
  55.     {1435.8024,2662.3647,11.3926,1.1650}, //  Northern train station
  56.     {1457.4762,2773.4868,10.8203,272.2754}, //  Northern golf club
  57.     {1739.6390,2803.0569,14.2735,285.3929}, //  Northern housing estate 1
  58.     {1870.3096,2785.2471,14.2734,42.3102}, //  Northern housing estate 2
  59.     {1959.7142,2754.6863,10.8203,181.4731}, //  Northern house 1
  60.     {2314.2556,2759.4504,10.8203,93.2711}, //  Northern industrial estate 1
  61.     {2216.5674,2715.0334,10.8130,267.6540}, //  Northern industrial estate 2
  62.     {2101.4192,2678.7874,10.8130,92.0607}, //  Northern near railway line
  63.     {1951.1090,2660.3877,10.8203,180.8461}, //  Northern house 2
  64.     {1666.6949,2604.9861,10.8203,179.8495}, //  Northern house 3
  65.     {2808.3367,2421.5107,11.0625,136.2060}, //  Northern shopping centre
  66.     {2633.3203,2349.7061,10.6719,178.7175}, //  V-Rock
  67.     {2606.6348,2161.7490,10.8203,88.7508}, //  South V-Rock
  68.     {2616.5286,2100.6226,10.8158,177.7834}, //  North Ammunation 1
  69.     {2491.8816,2397.9370,10.8203,266.6003}, //  North carpark 1
  70.     {2531.7891,2530.3223,21.8750,91.6686}, //  North carpark 2
  71.     {2340.6677,2530.4324,10.8203,177.8630}, //  North Pizza Stack
  72.     {2097.6855,2491.3313,14.8390,181.8117}, //  Emerald Isle
  73.     {1893.1000,2423.2412,11.1782,269.4385}, //  Souvenir shop
  74.     {1698.9330,2241.8320,10.8203,357.8584}, //  Northern casino
  75.     {1479.4559,2249.0769,11.0234,306.3790}, //  Baseball stadium 1
  76.     {1298.1548,2083.4016,10.8127,256.7034}, //  Baseball stadium 2
  77.     {1117.8785,2304.1514,10.8203,81.5490}, //  North carparks
  78.     {1108.9878,1705.8639,10.8203,0.6785}, //  Dirtring racing 1
  79.     {1423.9780,1034.4188,10.8203,90.9590}, //  Sumo
  80.     {1537.4377,752.0641,11.0234,271.6893}, //  Church
  81.     {1917.9590,702.6984,11.1328,359.2682}, //  Southern housing estate
  82.     {2089.4785,658.0414,11.2707,357.3572}, //  Southern house 1
  83.     {2489.8286,928.3251,10.8280,67.2245}, //  Wedding chapel
  84.     {2697.4717,856.4916,9.8360,267.0983}, //  Southern construction site
  85.     {2845.6104,1288.1444,11.3906,3.6506}, //  Southern train station
  86.     {2437.9370,1293.1442,10.8203,86.3830}, //  Wedding chapel (near Pyramid)
  87.     {2299.5430,1451.4177,10.8203,269.1287}, //  Carpark (near Pyramid)
  88.     {2214.3008,2041.9165,10.8203,268.7626}, //  Central parking lot
  89.     {2005.9174,2152.0835,10.8203,270.1372}, //  Central motel
  90.     {2222.1042,1837.4220,10.8203,88.6461}, //  Clowns Pocket
  91.     {2025.6753,1916.4363,12.3382,272.5852}, //  The Visage
  92.     {2087.9902,1516.5336,10.8203,48.9300}, //  Royal Casino
  93.     {2172.1624,1398.7496,11.0625,91.3783}, //  Auto Bahn
  94.     {2139.1841,987.7975,10.8203,0.2315}, //  Come-a-lot
  95.     {1860.9672,1030.2910,10.8203,271.6988}, //  Behind 4 Dragons
  96.     {1673.2345,1316.1067,10.8203,177.7294}, //  Airport carpark
  97.     {1412.6187,2000.0596,14.7396,271.3568}, //  South baseball stadium houses
  98.     {-2723.4639,-314.8138,7.1839,43.5562},  // golf course spawn
  99.     {-2694.5344,64.5550,4.3359,95.0190},  // in front of a house
  100.     {-2458.2000,134.5419,35.1719,303.9446},  // hotel
  101.     {-2796.6589,219.5733,7.1875,88.8288},  // house
  102.     {-2706.5261,397.7129,4.3672,179.8611},  // park
  103.     {-2866.7683,691.9363,23.4989,286.3060},  // house
  104.     {-2764.9543,785.6434,52.7813,357.6817},  // donut shop
  105.     {-2660.9402,883.2115,79.7738,357.4440},  // house
  106.     {-2861.0796,1047.7109,33.6068,188.2750}, //  parking lot
  107.     {-2629.2009,1383.1367,7.1833,179.7006},  // parking lot at the bridge
  108.     {-2079.6802,1430.0189,7.1016,177.6486},  // pier
  109.     {-1660.2294,1382.6698,9.8047,136.2952}, //  pier 69
  110.     {-1674.1964,430.3246,7.1797,226.1357},  // gas station]
  111.     {-1954.9982,141.8080,27.1747,277.7342},  // train station
  112.     {-1956.1447,287.1091,35.4688,90.4465},  // car shop
  113.     {-1888.1117,615.7245,35.1719,128.4498},  // random
  114.     {-1922.5566,886.8939,35.3359,272.1293},  // random
  115.     {-1983.3458,1117.0645,53.1243,271.2390},  // church
  116.     {-2417.6458,970.1491,45.2969,269.3676},  // gas station
  117.     {-2108.0171,902.8030,76.5792,5.7139},  // house
  118.     {-2097.5664,658.0771,52.3672,270.4487},  // random
  119.     {-2263.6650,393.7423,34.7708,136.4152},  // random
  120.     {-2287.5027,149.1875,35.3125,266.3989},  // baseball parking lot
  121.     {-2039.3571,-97.7205,35.1641,7.4744},  // driving school
  122.     {-1867.5022,-141.9203,11.8984,22.4499},  // factory
  123.     {-1537.8992,116.0441,17.3226,120.8537},  // docks ship
  124.     {-1708.4763,7.0187,3.5489,319.3260},  // docks hangar
  125.     {-1427.0858,-288.9430,14.1484,137.0812},  // airport
  126.     {-2173.0654,-392.7444,35.3359,237.0159},  // stadium
  127.     {-2320.5286,-180.3870,35.3135,179.6980},  // burger shot
  128.     {-2930.0049,487.2518,4.9141,3.8258}  // harbor
  129. };
  130.  
  131. enum e_pInfo
  132. {
  133.     gID,
  134.     gExperience, gRExperience, gNeededExp, gLevel,
  135.     Slot[4] //Slot 0 - Fist, Slot 1 - Nightstick, Slot 2 - Pool Cue, Slot 3 - Katana!
  136. }
  137. enum e_lvlInfo
  138. {
  139.     bool:IsActive,
  140.     Float:X,
  141.     Float:Y,
  142.     Float:Z,
  143.     gExperienceB,
  144.     Text3D:Info
  145. }
  146. new gLevelInfo[MAX_EXPERIENCE_PICKUPS][e_lvlInfo];
  147. new gPlayerInfo[MAX_PLAYERS][e_pInfo];
  148. new
  149.     WorkingInventory[MAX_PLAYERS] = 0,
  150.     Text:Stats[MAX_PLAYERS],
  151.     TimerVar,
  152.     bool:JustConnected[ MAX_PLAYERS char ],
  153.     bool:Spawned[ MAX_PLAYERS char ]
  154. ;
  155. new DB:Katana;
  156.  
  157. #if defined FILTERSCRIPT
  158.  
  159. public OnFilterScriptInit()
  160. {
  161.     print("\n--------------------------------------");
  162.     print("Melee Weapons v1 by Kyance\n . . .\nStatus: loaded!");
  163.     print("--------------------------------------\n");
  164.     CreateExpPickups();
  165.     Katana = db_open("KatanaLvls.db");
  166.     db_query(Katana, "CREATE TABLE IF NOT EXISTS `USERS` (`ID`, `NAME`, `EXPERIENCE`, `REALEXPERIENCE`, `NEEDEDEXP`, `LEVEL`, `SLOT0`, `SLOT1`, `SLOT2`, `SLOT3`)");
  167.     foreach(Player, i) OnPlayerConnect(i);
  168.    
  169.     TimerVar = SetTimer("UpdateStats", 1800, true);
  170.     return 1;
  171. }
  172. public OnFilterScriptExit()
  173. {
  174.     print("\n--------------------------------------");
  175.     print("Melee Weapons v1 by Kyance\n . . .\nStatus: unloaded!");
  176.     print("--------------------------------------\n");
  177.     KillTimer(TimerVar);
  178.     DestroyExpPickups(); foreach(Player, i) SaveData(i), TextDrawDestroy(Stats[i]);
  179.     db_close(Katana);
  180.     return 1;
  181. }
  182.  
  183. #endif
  184. public OnPlayerConnect(playerid)
  185. {
  186.     new DBResult:result, Query[88];
  187.     format(Query, sizeof(Query), "SELECT `NAME` FROM `USERS` WHERE `NAME` = '%s'", DB_Escape(GetName(playerid)));
  188.     result = db_query(Katana, Query);
  189.     if(db_num_rows(result)) SendClientMessage(playerid, -1, "{64CC66}Loading Account..."), LoadData(playerid);
  190.     else SendClientMessage(playerid, -1, "{64CC66}Registering Account..."), RegisterData(playerid);
  191.     db_free_result(result);
  192.    
  193.     WorkingInventory[playerid] = 0;
  194.     JustConnected{ playerid } = true, Spawned{ playerid } = false, SetTimerEx("RemoveJC", 8200, false, "i", playerid);
  195.     SendClientMessage(playerid, -1, "{64CC66}Setting up HUD...");
  196.    
  197.    
  198.     Stats[playerid] = TextDrawCreate(142.500000,352.500000,"~y~Loading data. . .");
  199.     TextDrawAlignment(Stats[playerid],0);
  200.     TextDrawBackgroundColor(Stats[playerid],0x000000FF);
  201.     TextDrawFont(Stats[playerid],1);
  202.     TextDrawLetterSize(Stats[playerid],0.199999,1.000000);
  203.     TextDrawColor(Stats[playerid],0xffffffFF);
  204.     TextDrawSetOutline(Stats[playerid],1);
  205.     TextDrawSetProportional(Stats[playerid],1);
  206.     TextDrawSetShadow(Stats[playerid],1);
  207.     TextDrawHideForPlayer(playerid, Stats[playerid]);
  208.     return 1;
  209. }
  210. public OnPlayerDisconnect(playerid, reason)
  211. {
  212.     SaveData(playerid);
  213.     WorkingInventory[playerid] = 0, Spawned{ playerid } = false, JustConnected{ playerid } = true;
  214.     TextDrawDestroy(Stats[playerid]);
  215.     return 1;
  216. }
  217. public OnPlayerSpawn(playerid)
  218. {
  219.     TextDrawShowForPlayer(playerid, Stats[playerid]);
  220.     WorkingInventory[playerid] = 0, Spawned{ playerid } = true;
  221.     return 1;
  222. }
  223. public OnPlayerDeath(playerid, killerid, reason)
  224. {
  225.     Spawned{ playerid } = false;
  226.     TextDrawHideForPlayer(playerid, Stats[playerid]);
  227.     return 1;
  228. }
  229. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  230. {
  231.     if(newkeys & KEY_YES)
  232.     {
  233.         for(new i = 0; i<MAX_EXPERIENCE_PICKUPS;i++)
  234.         {
  235.             if(IsPlayerInRangeOfPoint(playerid, 5, gLevelInfo[i][X], gLevelInfo[i][Y], gLevelInfo[i][Z]))
  236.             {
  237.                 GiveExperience(playerid, 0, gLevelInfo[i][gExperienceB]);
  238.                 break;
  239.             }
  240.             else
  241.             {
  242.                 new Dialog[320]; //Slot 0 - Fist, Slot 1 - Nightstick, Slot 2 - Pool Cue, Slot 3 - Katana!
  243.                 if(gPlayerInfo[playerid][Slot][0]) format(Dialog, sizeof(Dialog), "Slot #0 - {64CC66}Fist");
  244.                 else format(Dialog, sizeof(Dialog), "Slot #0 - {FC4949}Fist");
  245.                 if(gPlayerInfo[playerid][Slot][1]) strcat(Dialog, "\nSlot #1 - {64CC66}Nitestick");
  246.                 else strcat(Dialog, "\nSlot #1 - {FC4949}Nitestick");
  247.                 if(gPlayerInfo[playerid][Slot][2]) strcat(Dialog, "\nSlot #2 - {64CC66}Pool Cue");
  248.                 else strcat(Dialog, "\nSlot #2 - {FC4949}Pool Cue");
  249.                 if(gPlayerInfo[playerid][Slot][3]) strcat(Dialog, "\nSlot #3 - {64CC66}Katana");
  250.                 else strcat(Dialog, "\nSlot #3 - {FC4949}Katana");
  251.                 strcat(Dialog, "\nClicking on a {64CC66}Green {FFFFFF}slot will give you the weapon");
  252.                 strcat(Dialog, "\nClicking on a {FC4949}Red {FFFFFF}slot will allow you to buy the weapon");
  253.                 strcat(Dialog, "\nIMPORTANT: Selecting 'FIST' will put all of your melee weapons in inventory!");
  254.                 ShowPlayerDialog(playerid, DIALOG_INVENTORY, DIALOG_STYLE_LIST, "Your inventory", Dialog, "Select", "Close");
  255.                 Dialog = "\0";
  256.                 break;
  257.             }
  258.             //else return SendClientMessage(playerid, -1, "{FC4949}You aren't near a 'Experience Box'!");
  259.         }
  260.         return 1;
  261.     }
  262.     else if(newkeys & KEY_NO && !IsPlayerInAnyVehicle(playerid))
  263.     {
  264.         if(gPlayerInfo[playerid][gLevel] == 50)
  265.         {
  266.             ApplyAnimation(playerid,"SWORD","sword_block",47.0,0,1,0,1,1);
  267.             SetTimerEx("AnimFixer", 700, false, "i", playerid);
  268.             SetTimerEx("OPResult", 3000, false, "i", playerid);
  269.         }
  270.         return 1;
  271.     }
  272.     return 1;
  273. }
  274. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  275. {
  276.     switch(dialogid)
  277.     {
  278.         case DIALOG_INVENTORY:
  279.         {
  280.             if(response)
  281.             {
  282.                 switch(listitem)
  283.                 {
  284.                     case 0:
  285.                     {
  286.                         if(gPlayerInfo[playerid][Slot][0])
  287.                         {
  288.                             if(gPlayerInfo[playerid][Slot][1]) SetPlayerAmmo(playerid, WEAPON_NITESTICK, 0);
  289.                             else if(gPlayerInfo[playerid][Slot][2]) SetPlayerAmmo(playerid, WEAPON_POOLSTICK, 0);
  290.                             else if(gPlayerInfo[playerid][Slot][3]) SetPlayerAmmo(playerid, WEAPON_KATANA, 0);
  291.                             SendClientMessage(playerid, -1, "All melee weapons have been put in your inventory!"), WorkingInventory[playerid] = 0;
  292.                         }
  293.                         else gPlayerInfo[playerid][Slot][0] = 1;
  294.                     }
  295.                     case 1:
  296.                     {
  297.                         if(gPlayerInfo[playerid][Slot][1]) ShowPlayerDialog(playerid, DIALOG_SELL_OR_TAKE, DIALOG_STYLE_MSGBOX, "Your inventory", "{FFFFFF}Do you want to {FC4949}sell{FFFFFF} or {FC4949}equip{FFFFFF} the Nitestick?", "Sell", "Equip"), WorkingInventory[playerid] = 1;
  298.                         else
  299.                         {
  300.                             if(gPlayerInfo[playerid][gRExperience] >= 50) SendClientMessage(playerid, -1, "Nitestick bought for 50 xp!"), TakeExperience(playerid, 50), gPlayerInfo[playerid][Slot][1] = 1;
  301.                             else SendClientMessage(playerid, -1, "Not enough xp!");
  302.                         }
  303.                     }
  304.                     case 2:
  305.                     {
  306.                         if(gPlayerInfo[playerid][Slot][2]) ShowPlayerDialog(playerid, DIALOG_SELL_OR_TAKE, DIALOG_STYLE_MSGBOX, "Your inventory", "{FFFFFF}Do you want to {FC4949}sell{FFFFFF} or {FC4949}equip{FFFFFF} the Pool Cue?", "Sell", "Equip"), WorkingInventory[playerid] = 2;
  307.                         else
  308.                         {
  309.                             if(gPlayerInfo[playerid][gRExperience] >= 75) SendClientMessage(playerid, -1, "Pool Cue bought for 75 xp!"), TakeExperience(playerid, 75), gPlayerInfo[playerid][Slot][2] = 1;
  310.                             else SendClientMessage(playerid, -1, "Not enough xp!");
  311.                         }
  312.                     }
  313.                     case 3:
  314.                     {
  315.                         if(gPlayerInfo[playerid][Slot][3]) ShowPlayerDialog(playerid, DIALOG_SELL_OR_TAKE, DIALOG_STYLE_MSGBOX, "Your inventory", "{FFFFFF}Do you want to {FC4949}sell{FFFFFF} or {FC4949}equip{FFFFFF} the Katana?", "Sell", "Equip"), WorkingInventory[playerid] = 3;
  316.                         else
  317.                         {
  318.                             if(gPlayerInfo[playerid][gRExperience] >= 150) SendClientMessage(playerid, -1, "Katana bought for 150 xp!"), TakeExperience(playerid, 150), gPlayerInfo[playerid][Slot][3] = 1;
  319.                             else SendClientMessage(playerid, -1, "Not enough xp!");
  320.                         }
  321.                     }
  322.                 }
  323.             }
  324.         }
  325.         case DIALOG_SELL_OR_TAKE:
  326.         {
  327.             if(response)
  328.             {
  329.                 new Text[70], XPAmount;
  330.                 if(WorkingInventory[playerid])
  331.                 {
  332.                     if(WorkingInventory[playerid] == 1)
  333.                     {
  334.                         XPAmount = random(50);
  335.                         format(Text, sizeof(Text), "Nitestick sold for %d experience!", XPAmount), SendClientMessage(playerid, -1, Text);
  336.                         GiveExperience(playerid, XPAmount), SetPlayerAmmo(playerid, WEAPON_NITESTICK, 0), gPlayerInfo[playerid][Slot][1] = 0;
  337.                     }
  338.                     else if(WorkingInventory[playerid] == 2)
  339.                     {
  340.                         XPAmount = random(75);
  341.                         format(Text, sizeof(Text), "Pool Cue sold for %d experience!", XPAmount), SendClientMessage(playerid, -1, Text);
  342.                         GiveExperience(playerid, XPAmount), SetPlayerAmmo(playerid, WEAPON_POOLSTICK, 0), gPlayerInfo[playerid][Slot][2] = 0;
  343.                     }
  344.                     else if(WorkingInventory[playerid] == 3)
  345.                     {
  346.                         XPAmount = random(120);
  347.                         format(Text, sizeof(Text), "Katana sold for %d experience!", XPAmount), SendClientMessage(playerid, -1, Text);
  348.                         GiveExperience(playerid, XPAmount), SetPlayerAmmo(playerid, WEAPON_KATANA, 0), gPlayerInfo[playerid][Slot][3] = 0;
  349.                     }
  350.                 }
  351.                 else SendClientMessage(playerid, -1, "{FC4949}Invalid Slot ID selected");
  352.             }
  353.             else
  354.             {
  355.                 if(WorkingInventory[playerid])
  356.                 {
  357.                     if(WorkingInventory[playerid] == 1) GivePlayerWeapon(playerid, WEAPON_NITESTICK, 1), SendClientMessage(playerid, -1, "Equipped the Nitestick!");
  358.                     else if(WorkingInventory[playerid] == 2) GivePlayerWeapon(playerid, WEAPON_POOLSTICK, 1), SendClientMessage(playerid, -1, "Equipped the Pool Cue!");
  359.                     else if(WorkingInventory[playerid] == 3) GivePlayerWeapon(playerid, WEAPON_KATANA, 1), SendClientMessage(playerid, -1, "Equipped the Katana!");
  360.                 }
  361.                 else SendClientMessage(playerid, -1, "{FC4949}Invalid Slot ID selected");
  362.             }
  363.         }
  364.     }
  365.     return 1;
  366. }
  367. public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid)
  368. {
  369.     if(issuerid != INVALID_PLAYER_ID)
  370.     {
  371.         new chance = random(10);
  372.         switch(chance)
  373.         {
  374.             case 4:
  375.             {
  376.                 if(gPlayerInfo[issuerid][gLevel] >= 10)
  377.                 {
  378.                     SendClientMessage(playerid, -1, "STRUCK WITH GREAT FORCE!"), SendClientMessage(issuerid, -1, "STRUCK WITH GREAT FORCE!");
  379.                     if(weaponid == WEAPON_NITESTICK || weaponid == WEAPON_KATANA)
  380.                     {
  381.                         new Float:x, Float:y, Float:z; GetPlayerPos(playerid, x, y, z);
  382.                         CreateExplosionForPlayer(playerid, x, y, z, 12, 5);
  383.                         GiveExperience(issuerid, 1+random(20));
  384.                     }
  385.                     else if(weaponid == WEAPON_POOLSTICK)
  386.                     {
  387.                         new Float:x, Float:y, Float:z, Float:angle; GetPlayerVelocity(playerid, x, y, z); GetPlayerFacingAngle(playerid, angle);
  388.                         x += (5.0 * floatsin(-angle, degrees));
  389.                         y += (5.0 * floatcos(-angle, degrees));
  390.                         SetPlayerVelocity(playerid, x, y, z);
  391.                     }
  392.                 }
  393.             }
  394.             case 3, 1:
  395.             {
  396.                 if(gPlayerInfo[issuerid][gLevel] >= 5)
  397.                 {
  398.                     if(weaponid == WEAPON_NITESTICK || weaponid == WEAPON_KATANA || weaponid == WEAPON_POOLSTICK)
  399.                     {
  400.                         SendClientMessage(playerid, -1, "CRITICAL HIT!"), SendClientMessage(issuerid, -1, "CRITICAL HIT!");
  401.                         new Float:hp; GetPlayerHealth(playerid, hp);
  402.                         SetPlayerHealth(playerid, hp-amount-random(10));
  403.                     }
  404.                 }
  405.             }
  406.         }
  407.     }
  408.     return 1;
  409. }
  410. CMD:giveexp(playerid, params[]) {
  411.     new id, amount;
  412.     if(!IsPlayerAdmin(playerid)) return 0;
  413.     if(sscanf(params, "ui", id, amount)) return SendClientMessage(playerid, -1, "/giveexp PLAYERID AMOUNT");
  414.     else if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, -1, "Invalid ID");
  415.     //else if(amount > gPlayerInfo[id][gNeededExp]) return SendClientMessage(playerid, -1, "ID doesn't need that much experience!");
  416.    
  417.     if(amount > 0) GiveExperience(id, amount);
  418.     else TakeExperience(id, amount);
  419.     return 1;
  420. }
  421. stock DestroyExpPickups()
  422. {
  423.     for(new i = 0; i<MAX_EXPERIENCE_PICKUPS;i++)
  424.     {
  425.         if(!gLevelInfo[i][IsActive]) continue;
  426.  
  427.         gLevelInfo[i][IsActive] = false;
  428.         gLevelInfo[i][gExperienceB] = 0, gLevelInfo[i][X] = 0, gLevelInfo[i][Y] = 0, gLevelInfo[i][Z] = 0;
  429.         Delete3DTextLabel(gLevelInfo[i][Info]);
  430.     }
  431. }
  432. stock CreateExpPickups()
  433. {
  434.     new
  435.         randspawn,
  436.         Text[72]
  437.     ;
  438.     for(new i = 0; i<MAX_EXPERIENCE_PICKUPS;i++)
  439.     {
  440.         if(gLevelInfo[i][IsActive]) continue;
  441.        
  442.         gLevelInfo[i][gExperienceB] = random(60);
  443.         format(Text, sizeof(Text), "{FFFFFF}'Experience Box', press 'Y' to interact\nYou get: {64CC66}%d experience!", gLevelInfo[i][gExperienceB]);
  444.         gLevelInfo[i][Info] = Create3DTextLabel(Text, -1, RandomLvlSpawns[randspawn][0], RandomLvlSpawns[randspawn][1], RandomLvlSpawns[randspawn][2], 25.5, 0, 1);
  445.         gLevelInfo[i][X] = RandomLvlSpawns[randspawn][0], gLevelInfo[i][Y] = RandomLvlSpawns[randspawn][1], gLevelInfo[i][Z] = RandomLvlSpawns[randspawn][2];
  446.         gLevelInfo[i][IsActive] = true;
  447.     }
  448.     Text = "\0";
  449. }
  450. stock DestroyExpPickup(pickupid)
  451. {
  452.     gLevelInfo[pickupid][IsActive] = false;
  453.     gLevelInfo[pickupid][gExperienceB] = 0, gLevelInfo[pickupid][X] = 0, gLevelInfo[pickupid][Y] = 0, gLevelInfo[pickupid][Z] = 0;
  454.     Delete3DTextLabel(gLevelInfo[pickupid][Info]);
  455. }
  456. stock GiveExperience(playerid, amount, pickupid = -1)
  457. {
  458.     new Text[86];
  459.     if(pickupid != -1)
  460.     {
  461.         format(Text, sizeof(Text), "You've received {64CC66}%d experience {FFFFFF}from an 'Experience Box'!", gLevelInfo[pickupid][gExperienceB]), SendClientMessage(playerid, -1, Text);
  462.         gPlayerInfo[playerid][gExperience] += gLevelInfo[pickupid][gExperienceB];
  463.         DestroyExpPickup(pickupid);
  464.     }
  465.     else
  466.     {
  467.         if(amount > 0)
  468.         {
  469.             format(Text, sizeof(Text), "You've received {64CC66}%d experience!", amount), SendClientMessage(playerid, -1, Text);
  470.             gPlayerInfo[playerid][gExperience] += amount;
  471.             gPlayerInfo[playerid][gRExperience] += amount;
  472.         }
  473.     }
  474.     if(gPlayerInfo[playerid][gExperience] >= gPlayerInfo[playerid][gNeededExp] && gPlayerInfo[playerid][gLevel] < 50)
  475.     {
  476.         gPlayerInfo[playerid][gLevel]++;
  477.         gPlayerInfo[playerid][gNeededExp] = gPlayerInfo[playerid][gNeededExp]*2;
  478.         format(Text, sizeof(Text), "Congrats! You've {64CC66}gained a level! {FFFFFF}Current level: {64CC66}%d", gPlayerInfo[playerid][gLevel]), SendClientMessage(playerid, -1, Text);
  479.         format(Text, sizeof(Text), "You now need {64CC66}%d experience{FFFFFF} to {64CC66}level up.", gPlayerInfo[playerid][gNeededExp]), SendClientMessage(playerid, -1, Text);
  480.     }
  481.     if(gPlayerInfo[playerid][gLevel] == 5) SendClientMessage(playerid, -1, "Since you're {64CC66}Level 5{FFFFFF}, you can deal Critical Hits!");
  482.     else if(gPlayerInfo[playerid][gLevel] == 10) SendClientMessage(playerid, -1, "Since you're {64CC66}Level 10{FFFFFF}, you have a chance of giving explosive Katana and Nitestick hits!");
  483.     else if(gPlayerInfo[playerid][gLevel] == 50) SendClientMessage(playerid, -1, "Since you're {64CC66}Level 50{FFFFFF}, you can press 'N' to use the most overpowered thing yet..");
  484.     Text = "\0";
  485. }
  486. stock TakeExperience(playerid, amount)
  487. {
  488.     new Text[86];
  489.     format(Text, sizeof(Text), "You've lost {FC4949}%d experience!", amount), SendClientMessage(playerid, -1, Text);
  490.     gPlayerInfo[playerid][gExperience] -= amount;
  491.     gPlayerInfo[playerid][gRExperience] -= amount;
  492.    
  493.     if(gPlayerInfo[playerid][gExperience] < 0 && gPlayerInfo[playerid][gLevel] >= 1)
  494.     {
  495.         gPlayerInfo[playerid][gLevel]--;
  496.         gPlayerInfo[playerid][gNeededExp] = gPlayerInfo[playerid][gNeededExp]/2;
  497.  
  498.         format(Text, sizeof(Text), "Oh no! You've {FC4949}lost a level! {FFFFFF}Current level: {FC4949}%d", gPlayerInfo[playerid][gLevel]), SendClientMessage(playerid, -1, Text);
  499.         format(Text, sizeof(Text), "You need {64CC66}%d experience{FFFFFF} to {64CC66}level up again.", gPlayerInfo[playerid][gNeededExp]), SendClientMessage(playerid, -1, Text);
  500.     }
  501.     Text = "\0";
  502. }
  503. forward UpdateStats();
  504. public UpdateStats()
  505. {
  506.     new Text[146];
  507.     foreach(Player, i)
  508.     {
  509.         if(JustConnected{ i } == true || Spawned{ i } == false) continue;
  510.        
  511.         format(Text, sizeof(Text), "~w~Experience Points: ~y~%d~w~/~y~%d~n~~w~Total Experience Points: ~y~%d~n~~w~Level: ~y~%d/50", gPlayerInfo[i][gExperience], gPlayerInfo[i][gNeededExp], gPlayerInfo[i][gRExperience], gPlayerInfo[i][gLevel]);
  512.         TextDrawSetString(Stats[i],Text);
  513.         TextDrawShowForPlayer(i,Stats[i]);
  514.  
  515.         if(gPlayerInfo[i][gNeededExp] == 0) gPlayerInfo[i][gNeededExp] = 100, gPlayerInfo[i][gExperience] = 0, gPlayerInfo[i][gLevel] = 0;
  516.     }
  517.     return 1;
  518. }
  519. forward RemoveJC(playerid);
  520. public RemoveJC(playerid)
  521. {
  522.     JustConnected{ playerid } = false;
  523.     SendClientMessage(playerid, -1, "{64CC66}HUD, Data and other information successfully initialized!");
  524.     return 1;
  525. }
  526. forward OPResult(playerid);
  527. public OPResult(playerid)
  528. {
  529.     SetPlayerHealth(playerid, 99);
  530.  
  531.     new Float:hp, Float:x, Float:y, Float:z; GetPlayerPos(playerid, x, y, z);
  532.     new RResult;
  533.     foreach(Player, i)
  534.     {
  535.         if(!IsPlayerInRangeOfPoint(i, 20, x, y, z)) continue;
  536.  
  537.         RResult = random(2);
  538.         switch(RResult)
  539.         {
  540.             case 0:
  541.             {
  542.                 hp = GetPlayerHealth(i, hp);
  543.                 SetPlayerHealth(i, hp/2);
  544.             }
  545.             case 1: OnPlayerDeath(i, playerid, 47), SendClientMessage(i, -1, "{FC4949}You got terminated!");
  546.         }
  547.     }
  548. }
  549. forward AnimFixer(playerid);
  550. public AnimFixer(playerid)
  551. {
  552.     ApplyAnimation(playerid,"SWORD","sword_block",43.0,0,1,0,1,1);
  553.     return 1;
  554. }
  555. stock DB_Escape(text[])
  556. {
  557.     new
  558.         ret[80 * 2],
  559.         ch,
  560.         i,
  561.         j
  562.     ;
  563.     while ((ch = text[i++]) && j < sizeof (ret))
  564.     {
  565.         if (ch == '\'')
  566.         {
  567.             if (j < sizeof (ret) - 2)
  568.             {
  569.                 ret[j++] = '\'';
  570.                 ret[j++] = '\'';
  571.             }
  572.         }
  573.         else if (j < sizeof (ret))
  574.         {
  575.             ret[j++] = ch;
  576.         }
  577.         else
  578.         {
  579.             j++;
  580.         }
  581.     }
  582.     ret[sizeof (ret) - 1] = '\0';
  583.     return ret;
  584. }
  585. stock GetName(playerid)
  586. {
  587.     new pnameid[24];
  588.     GetPlayerName(playerid,pnameid,sizeof(pnameid));
  589.     return pnameid;
  590. }
  591.  
  592. stock LoadData(playerid)
  593. {
  594.     new DBResult:result, Query[128];
  595.     format(Query, sizeof(Query), "SELECT * FROM `USERS` WHERE `NAME` = '%s'", DB_Escape(GetName(playerid)));
  596.     result = db_query(Katana, Query);
  597.     if(db_num_rows(result))
  598.     {
  599.         new Field[70];
  600.         db_get_field_assoc(result, "ID", Field, 11); gPlayerInfo[playerid][gID] = strval(Field);
  601.         db_get_field_assoc(result, "EXPERIENCE", Field, 15); gPlayerInfo[playerid][gExperience] = strval(Field);
  602.         db_get_field_assoc(result, "REALEXPERIENCE", Field, 15); gPlayerInfo[playerid][gRExperience] = strval(Field);
  603.         db_get_field_assoc(result, "NEEDEDEXP", Field, 15); gPlayerInfo[playerid][gNeededExp] = strval(Field);
  604.         db_get_field_assoc(result, "LEVEL", Field, 2); gPlayerInfo[playerid][gLevel] = strval(Field);
  605.         db_get_field_assoc(result, "SLOT0", Field, 1); gPlayerInfo[playerid][Slot][0] = strval(Field);
  606.         db_get_field_assoc(result, "SLOT1", Field, 1); gPlayerInfo[playerid][Slot][1] = strval(Field);
  607.         db_get_field_assoc(result, "SLOT2", Field, 1); gPlayerInfo[playerid][Slot][2] = strval(Field);
  608.         db_get_field_assoc(result, "SLOT3", Field, 1); gPlayerInfo[playerid][Slot][3] = strval(Field);
  609.            
  610.         if(result) printf("[sqlite][%s]: successfully loaded data", GetName(playerid)), SendClientMessage(playerid, -1, "{64CC66}Data Loaded!");
  611.         else printf("[sqlite][%s]: couldn't load data", GetName(playerid)), SendClientMessage(playerid, -1, "{FC4949}Failed to Load Data..");
  612.     }
  613.     else
  614.     {
  615.         RegisterData(playerid);
  616.     }
  617.     db_free_result(result);
  618. }
  619. stock RegisterData(playerid)
  620. {
  621.     new Query[240], DBResult:result, DBResult:count = db_query(Katana, "SELECT * FROM `USERS`");
  622.     format(Query, sizeof(Query), "INSERT INTO `USERS` (`ID`, `NAME`, `EXPERIENCE`, `REALEXPERIENCE`, `NEEDEDEXP`, `LEVEL`, `SLOT0`, `SLOT1`, `SLOT2`, `SLOT3`) VALUES ('%d', '%s', '0', '0', '0', '0', '1', '0', '0', '0')", db_num_rows(count)+1, DB_Escape(GetName(playerid)));
  623.     result = db_query(Katana, Query);
  624.     if(result) printf("[sqlite][%s]: successfully registered data", GetName(playerid)), SendClientMessage(playerid, -1, "{64CC66}Data Registered!");
  625.     else printf("[sqlite][%s]: couldn't register data", GetName(playerid)), SendClientMessage(playerid, -1, "{FC4949}Failed to Register Data..");
  626.     db_free_result(result);
  627. }
  628. stock SaveData(playerid)
  629. {
  630.     new DBResult:result, Query[240];
  631.     format(Query, sizeof(Query), "SELECT * FROM `USERS` WHERE `NAME` = '%s'", DB_Escape(GetName(playerid)));
  632.     result = db_query(Katana, Query);
  633.     if(db_num_rows(result))
  634.     {
  635.         format(Query, sizeof(Query), "UPDATE `USERS` SET `NAME` = '%s', `EXPERIENCE` = '%d', `REALEXPERIENCE` = '%d', `NEEDEDEXP` = '%d', `LEVEL` = '%d', `SLOT0` = '%d', `SLOT1` = '%d', `SLOT2` = '%d', `SLOT3` = '%d' WHERE `ID` = '%d'",
  636.         DB_Escape(GetName(playerid)), gPlayerInfo[playerid][gExperience], gPlayerInfo[playerid][gRExperience], gPlayerInfo[playerid][gNeededExp], gPlayerInfo[playerid][gLevel], gPlayerInfo[playerid][Slot][0], gPlayerInfo[playerid][Slot][1], gPlayerInfo[playerid][Slot][2], gPlayerInfo[playerid][Slot][3], gPlayerInfo[playerid][gID]);
  637.         result = db_query(Katana, Query);
  638.         if(result) printf("[sqlite][%s]: successfully saved data", GetName(playerid)), SendClientMessage(playerid, -1, "{64CC66}Data Saved!");
  639.         else printf("[sqlite][%s]: couldn't save data", GetName(playerid)), SendClientMessage(playerid, -1, "{FC4949}Failed to Save Data..");
  640.     }
  641.     else
  642.     {
  643.         RegisterData(playerid);
  644.     }
  645.     db_free_result(result);
  646. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement