Advertisement
VADemon

Original File|unrealsoftware.de/forum_posts.php?post=296563

Mar 13th, 2015
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 14.44 KB | None | 0 0
  1. if TMW then print("©255000000[Warning] TooManyWeapons was loaded before!") end
  2. TMW = {}
  3.  
  4. -- reqcld2 by EnderCrypt :: http://unrealsoftware.de/files_show.php?file=15156
  5. TMW.reqcld3_data = {}
  6. TMW.reqcld3_data.requests = {}
  7. -- VADemon > Updated 18.11.2014 to support reqcld optional parameters
  8. function TMW.reqcld3(id, mode, reqcld_parameter, func, custom_parameter) -- custom_parameter is optional, func gets called with that parameter
  9.     if not (type(func) == "function") then
  10.         msg("©255000000error in TMW.reqcld3: MISSING ARGUMENT: callback function (TMW.reqcld3(id, mode, reqcld data parameter, func [,custom parameter]))")
  11.         return 1
  12.     end
  13.  
  14.     TMW.reqcld3_data.requests[#TMW.reqcld3_data.requests+1] = {
  15.         ["id"]   = id,
  16.         ["mode"] = mode,
  17.         ["func"] = func,
  18.         ["reqcld_parameter"] = reqcld_parameter,
  19.         ["custom_parameter"] = custom_parameter
  20.     }
  21.    
  22.     reqcld(id, mode, reqcld_parameter)
  23. end
  24.  
  25. function TMW.reqcld3_data.clientdata(id,mode,x,y)
  26.     i = 0
  27.     while (i < #TMW.reqcld3_data.requests) do
  28.         i = i + 1
  29.         if (id == TMW.reqcld3_data.requests[i].id) and (mode == TMW.reqcld3_data.requests[i].mode) then
  30.             TMW.reqcld3_data.requests[i].func(id,x,y,TMW.reqcld3_data.requests[i].custom_parameter)
  31.             TMW.reqcld3_data.requests[i] = TMW.reqcld3_data.requests[#TMW.reqcld3_data.requests]
  32.             TMW.reqcld3_data.requests[#TMW.reqcld3_data.requests] = nil
  33.             break
  34.         end
  35.     end
  36. end
  37. --- END
  38.  
  39. -- TooManyWeapons
  40. addhook("say", "TMW.say")
  41. addhook("sayteam", "TMW.say")
  42. addhook("startround_prespawn", "TMW.startround_prespawn")
  43. -- See TMW.enableHooks() which are only enabled when needed
  44.  
  45. TMW.wpnList = {}
  46. TMW.unequipable =   {-- items that can't be given via equip command
  47. --  [item ID] = unequipable?
  48. }
  49.  
  50. TMW.highlightImageRes = "gfx/sprites/block.bmp"
  51. TMW.wpnListImageRes = "gfx/toomanyweapons/weaponlist.png"
  52.  
  53. TMW.WPNLIST_X1 = 1
  54. TMW.WPNLIST_Y1 = 2
  55. TMW.WPNLIST_X2 = 3
  56. TMW.WPNLIST_Y2 = 4
  57. TMW.WPNLIST_NAME = 5
  58. TMW.WPNLIST_ENABLED = 6
  59. TMW.WPNLIST_ITEMS = 7
  60.  
  61. do
  62.     local list = {}
  63.             --  x1,y1   x2,y2   name    enabled     {equip IDs}
  64.     list[1] = { 2, 4, 126, 22,  "Pistols",  true, {1, 2, 3, 4, 5, 6}}
  65.     list[2] = { 20, 28, 113, 41,    "USP",  true, {1}}
  66.     list[3] = { 20, 42, 113, 56,    "Glock",    true, {2}}
  67.     list[4] = { 20, 57, 113, 69,    "Deagle",   true, {3}}
  68.     list[5] = { 20, 70, 113, 82,    "P228",     true, {4}}
  69.     list[6] = { 20, 83, 113, 96,    "Elite",    true, {5}}
  70.     list[7] = { 20, 97, 113, 110,   "Five-Seven",   true, {6}}
  71.    
  72.     list[8] = { 2, 120, 126, 139,   "Rifles",   true, {30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 91}}
  73.     list[9] = { 7, 145, 120, 158,   "AK-47",    true, {30}}
  74.     list[10] = { 7, 159, 120, 172,  "SG552",    true, {31}}
  75.     list[11] = { 7, 173, 120, 186,  "M4A1",     true, {32}}
  76.     list[12] = { 7, 187, 120, 200,  "AUG",      true, {33}}
  77.     list[13] = { 7, 201, 120, 214,  "Scout",    true, {34}}
  78.     list[14] = { 2, 215, 120, 228,  "AWP",      true, {35}}
  79.     list[15] = { 7, 229, 120, 242,  "G3SG1",    true, {36}}
  80.     list[16] = { 7, 243, 120, 256,  "SG550",    true, {37}}
  81.     list[17] = { 7, 257, 120, 270,  "Galil",    true, {38}}
  82.     list[18] = { 7, 271, 120, 284,  "Famas",    true, {39}}
  83.     list[19] = { 7, 285, 120, 300,  "FN F2000", true, {40}}
  84.    
  85.     list[20] = { 145, 5, 271, 24,   "Shotguns", true, {10, 11}}
  86.     list[21] = { 142, 28, 255, 41,  "M3",       true, {10}}
  87.     list[22] = { 142, 42, 255, 55,  "XM1014",   true, {11}}
  88.    
  89.     list[23] = { 152, 62, 271, 80,  "Submachine Guns",  true, {20, 21, 22, 23}}
  90.     list[24] = { 149, 82, 245, 97,  "MP5",  true,   {20}}
  91.     list[25] = { 149, 98, 245, 111, "TMP",  true,   {21}}
  92.     list[26] = { 149, 112, 245, 125,    "P90",  true,   {22}}
  93.     list[27] = { 149, 126, 245, 139,    "MAC-10",   true,   {23}}
  94.    
  95.     list[28] = { 157, 147, 271, 168,    "Explosives",   true,   {51, 52, 53, 54, 72, 73, 75, 76, 77, 86, 87, 89}}
  96.     list[29] = { 161, 170, 274, 184,    "HE",   true, {51}}
  97.     list[30] = { 161, 185, 274, 198,    "Flashbang",    true, {52}}
  98.     list[31] = { 161, 199, 283, 212,    "Smoke Grenade",    true, {53}}
  99.     list[32] = { 161, 213, 267, 225,    "Flare",    true, {54}}
  100.     list[33] = { 161, 226, 267, 239,    "Gas Grenade",  true, {72}}
  101.     list[34] = { 156, 240, 283, 256,    "Molotov Cocktail", true, {73}}
  102.     list[35] = { 161, 257, 272, 270,    "Snowball", true, {75}}
  103.     list[36] = { 161, 271, 272, 284,    "Air Strike",   true, {76}}
  104.     list[37] = { 161, 285, 272, 298,    "Mine", true, {77}}
  105.     list[38] = { 161, 299, 272, 312,    "Gut Bomb", true, {86}}
  106.     list[39] = { 155, 313, 272, 326,    "Laser Mine",   true, {87}}
  107.     list[40] = { 157, 327, 272, 347,    "Satchel Charge",   true, {89}}
  108.    
  109.    
  110.     list[41] = { 305, 4, 443, 23,   "Equipment",    true,   {41, 56, 59, 60, 61, 62}}
  111.     list[42] = { 305, 24, 438, 48,  "Tactical Shield",  true, {41}}
  112.     list[43] = { 315, 50, 438, 63,  "Defuse Kit",   true,   {56}}
  113.     list[44] = { 305, 64, 438, 77,  "Night Vision", true,   {59}}
  114.     list[45] = { 305, 76, 438, 94,  "Gas Mask", true,   {60}}
  115.     list[46] = { 305, 95, 445, 108, "Primary Ammo", true,   {61}}
  116.     list[47] = { 305, 109, 451, 122,    "Secondary Ammo",   true,   {62}}
  117.    
  118.     list[48] = { 309, 133, 443, 151,    "Melee",    true,   {50, 69, 74, 78, 85}}
  119.     list[49] = { 315, 155, 417, 168,    "Knife",    true,   {50}}
  120.     list[50] = { 315, 169, 417, 185,    "Machete",  true,   {69}}
  121.     list[51] = { 315, 186, 417, 201,    "Wrench",   true,   {74}}
  122.     list[52] = { 315, 202, 417, 220,    "Claw", true,   {78}}
  123.     list[53] = { 307, 221, 417, 238,    "Chainsaw", true,   {85}}
  124.    
  125.     list[54] = { 303, 250, 443, 270,    "Heavy",    true,   {40, 45, 46, 47, 48, 49, 88, 90}}
  126.     list[55] = { 301, 271, 417, 288,    "M249", true,   {40}}
  127.     list[56] = { 303, 289, 417, 303,    "Laser",    true,   {45}}
  128.     list[57] = { 303, 304, 431, 328,    "Flamethrower", true,   {46}}
  129.     list[58] = { 283, 329, 431, 345,    "RPG Launcher", true,   {47}}
  130.     list[59] = { 303, 345, 442, 360,    "Rocket Launcher",  true,   {48}}
  131.     list[60] = { 303, 361, 451, 375,    "Grenade Launcher", true,   {49}}
  132.     list[61] = { 303, 376, 435, 394,    "Portal Gun",   true,   {88}}
  133.     list[62] = { 291, 395, 435, 411,    "M134", true,   {90}}
  134.    
  135.     list[63] = { 480, 3, 608, 22,   "Miscellaneous",    true,   {--[[55, 63,]] 64, 65, 66, 67, 68, --[[70, 71]] }}
  136.     list[64] = { 474, 23, 605, 43,  "Bomb", false,  {55}}
  137.     list[65] = { 474, 44, 610, 62,  "Planted Bomb", false,  {63}}   -- cannot be equipped under any circumstances!
  138.     list[66] = { 474, 64, 605, 83,  "Medikit",  true,   {64}}
  139.     list[67] = { 474, 84, 605, 102, "Bandage",  true,   {65}}
  140.     list[68] = { 474, 103, 605, 121,    "Coins",    true,   {66}}
  141.     list[69] = { 474, 122, 605, 139,    "Money",    true,   {67}}
  142.     list[70] = { 474, 140, 605, 156,    "Gold", true,   {68}}
  143.     list[71] = { 474, 157, 595, 172,    "Red Flag", false,  {70}}
  144.     list[72] = { 474, 173, 595, 188,    "Blue Flag",    false,  {71}}
  145.    
  146.     list[73] = { 480 , 198, 591, 217,   "Armor",    false, {57, 58, 79, 80, 81, 82, 83, 84}}
  147.     list[74] = { 474, 218, 605, 238,    "Kevlar",   true,   {57}}
  148.     list[75] = { 474, 239, 605, 262,    "Kevlar & Helm",    true, {58}}
  149.     list[76] = { 474, 263, 605, 283,    "Light Armor",  true, {79}}
  150.     list[77] = { 474, 284, 605, 305,    "Armor",    true,   {80}}
  151.     list[78] = { 474, 306, 605, 329,    "Heavy Armor",  true,   {81}}
  152.     list[79] = { 474, 330, 605, 352,    "Medic Armor",  true,   {82}}
  153.     list[80] = { 474, 353, 605, 377,    "Super Armor",  true,   {83}}
  154.     list[81] = { 474, 378, 605, 401,    "Stealth Suit", true,   {84}}
  155.    
  156.    
  157.     TMW.wpnList = list
  158.    
  159.     TMW.unequipable[56] = true
  160.     TMW.unequipable[59] = true
  161.     TMW.unequipable[60] = true
  162.     TMW.unequipable[63] = true
  163.     TMW.unequipable[70] = true
  164.     TMW.unequipable[71] = true
  165.    
  166. end
  167.  
  168. function TMW.INIT_tables()
  169.     TMW.enabledPlayersCount = 0
  170.     TMW.enabledPlayers = {
  171.         -- [k] = bool
  172.     }
  173.    
  174.     TMW.selectedAction = {
  175.         -- [id] = number    | -1 = exit, >0 = give item
  176.     }
  177.    
  178.     TMW.images = {
  179.         highlight = {
  180.             -- [id] = imageID
  181.         },
  182.         wpnList = {},
  183.         close = {}
  184.     }
  185. end
  186. TMW.INIT_tables()
  187.  
  188. if permissions then -- Permissions plugin installed?
  189.     TMW.permission_check = function (id, wpnListNumber, hidePermissionDeniedMessage)
  190.         if wpnListNumber == -1 then -- check general TMW permission
  191.             return permissions.check(id, "toomanyweapons.menu")
  192.         end
  193.         --print("Checking for ", "toomanyweapons.weapon." .. string.lower(TMW.wpnList[wpnListNumber][5]))
  194.         return permissions.check(id, "toomanyweapons.weapon." .. string.lower( TMW.wpnList[wpnListNumber][5]:gsub("%s", "_") ), hidePermissionDeniedMessage)
  195.     end
  196. else
  197.     TMW.permission_check = function (id, wpnListNumber)
  198.         local adminList = {1, 7844}     -- ADD YOUR ADMIN USGN HERE
  199.        
  200.         for _, usgn in pairs(adminList) do
  201.             if player(id, "usgn") == usgn then
  202.                 return true
  203.             end
  204.         end
  205.        
  206.         msg2(id, "©255255255[TooManyWeapons] You aren't allowed either to use TMW or equip this item!")
  207.         return false
  208.     end
  209. end
  210.  
  211. function TMW.enablePlayer(id)
  212.     if not TMW.enabledPlayers[ id ] then    -- is GUI for this player disabled?
  213.    
  214.         TMW.enabledPlayersCount = TMW.enabledPlayersCount + 1
  215.         TMW.enabledPlayers[ id ] = true
  216.        
  217.         if TMW.enabledPlayersCount == 1 then    -- enable only once; once there's at least 1 player
  218.             TMW.enableHooks()
  219.         end
  220.        
  221.         return true
  222.     end
  223. end
  224.  
  225. function TMW.disablePlayer(id)
  226.     if TMW.enabledPlayers[ id ] then    -- is GUI for this player enabled?
  227.        
  228.         TMW.enabledPlayersCount = TMW.enabledPlayersCount - 1
  229.         TMW.enabledPlayers[ id ] = nil
  230.        
  231.         if TMW.enabledPlayersCount == 0 then
  232.             TMW.disableHooks()
  233.         end
  234.        
  235.         return true
  236.     end
  237. end
  238.  
  239. function TMW.enableHooks()
  240.     addhook("ms100", "TMW.GUI_update")
  241.     addhook("attack", "TMW.execute")
  242.     addhook("leave", "TMW.leave")
  243.     addhook("clientdata","TMW.reqcld3_data.clientdata")
  244. end
  245.  
  246. function TMW.disableHooks()
  247.     freehook("ms100", "TMW.GUI_update")
  248.     freehook("attack", "TMW.execute")
  249.     freehook("leave", "TMW.leave")
  250.     freehook("clientdata","TMW.reqcld3_data.clientdata")
  251. end
  252.  
  253. function TMW.GUI_open(id)
  254.     if not TMW.enablePlayer(id) then return end
  255.    
  256.     TMW.images.wpnList[ id ] = image(TMW.wpnListImageRes, 320, 240, 2, id)
  257.     TMW.selectedAction[ id ] = 0
  258. end
  259.  
  260. function TMW.GUI_close(id)
  261.  
  262.     if not TMW.disablePlayer(id) then return end
  263.     TMW.selectedAction[ id ] = 0
  264.    
  265.     if TMW.images.wpnList[ id ] then
  266.         freeimage(TMW.images.wpnList[ id ])
  267.         TMW.images.wpnList[ id ] = nil
  268.     end
  269.        
  270.     if TMW.images.highlight[ id ] then
  271.         freeimage(TMW.images.highlight[ id ])
  272.         TMW.images.highlight[ id ] = nil
  273.     end
  274.    
  275.     if TMW.images.close[ id ] then
  276.         freeimage(TMW.images.close[ id ])
  277.         TMW.images.close[ id ] = nil
  278.     end
  279. end
  280.  
  281. function TMW.GUI_update()
  282.     for id, _ in pairs(TMW.enabledPlayers) do
  283.         TMW.reqcld3(id, 0, "", TMW.GUI)
  284.     end
  285. end
  286.  
  287. function TMW.GUI(id, mouseX, mouseY)
  288.  
  289.     if mouseX >= 624 and mouseY <= 16 and TMW.images.close[ id ] == nil then
  290.         --print("mouse at close")
  291.         TMW.images.close[ id ] = image(TMW.highlightImageRes, 632, 8, 2, id)
  292.             imagescale(TMW.images.close[ id ], 0.5, 0.5)
  293.             imagealpha(TMW.images.close[ id ], 0.3)
  294.         --print("Close image ID:", TMW.images.close[ id ])
  295.         TMW.selectedAction[ id ] = -1
  296.        
  297.     elseif (mouseX < 624 or mouseY > 16) and TMW.images.close[ id ] then
  298.         --print("mouse outside close")
  299.         freeimage(TMW.images.close[ id ])
  300.             TMW.images.close[ id ] = nil
  301.        
  302.     end
  303.    
  304.     local list = TMW.wpnList
  305.     local selectionFound = false
  306.     for i = 1, #list do
  307.         if (mouseX >= list[i][1] and mouseX <= list[i][3]) and (mouseY >= list[i][2] and mouseY <= list[i][4]) then
  308.        
  309.             if TMW.selectedAction[ id ] == i then
  310.                 return -- same selection, nothing changed
  311.             end
  312.            
  313.             if TMW.images.highlight[id] then
  314.                 --print("Removing previous Highlight image")
  315.                 freeimage(TMW.images.highlight[id])
  316.             end
  317.            
  318.             -- highlight selected weapon
  319.             TMW.images.highlight[ id ] = image(TMW.highlightImageRes, list[i][1] + (list[i][3] - list[i][1]) / 2, list[i][2] + (list[i][4] - list[i][2]) / 2, 2, id)
  320.             TMW.selectedAction[ id ] = i
  321.             --print("Highlight image ID:", TMW.images.highlight[ id ])
  322.            
  323.             --  (x2 - x1) / highlightImageWidth = scale
  324.             imagescale(TMW.images.highlight[id], (list[i][3] - list[i][1]) / 32, (list[i][4] - list[i][2]) / 32)
  325.             imagealpha(TMW.images.highlight[id], 0.3)
  326.            
  327.             if list[ i ][ 6 ] == false or TMW.permission_check(id, i, true) == false then   -- unavailable to the player
  328.                 imagecolor(TMW.images.highlight[id], 255, 64, 64)
  329.             end
  330.            
  331.             selectionFound = true
  332.             break
  333.         end
  334.     end
  335.    
  336.     -- nothing found
  337.     -- !> remove the highlight image
  338.     if selectionFound == false and TMW.images.highlight[ id ] then
  339.         --print("Removing previous Highlight image, no highlighting")
  340.         --print("Highlight ID:", TMW.images.highlight[ id ])
  341.         freeimage(TMW.images.highlight[id])
  342.         TMW.images.highlight[ id ] = nil
  343.         if TMW.selectedAction[ id ] ~= -1 then
  344.             TMW.selectedAction[ id ] = 0
  345.         end
  346.     end
  347.     --parse("hudtxt 1 \"" .. TMW.selectedAction[ id ] .. "\" 320 240 0")
  348. end
  349.  
  350. function TMW.startround_prespawn()
  351.     TMW.INIT_tables()
  352.     TMW.disableHooks()
  353. end
  354.  
  355. function TMW.leave(id, reason)
  356.     TMW.GUI_close(id)
  357. end
  358.  
  359. function TMW.say(id, text)
  360.     if string.lower(text) == "!tmw" and TMW.permission_check(id, -1) then
  361.         if player(id, "health") ~= 0 then
  362.             TMW.GUI_open(id)
  363.         else
  364.             msg2(id,"©255255255[TooManyWeapons] You can't equip yourself, you're D E A D!")
  365.             return 1
  366.         end
  367.     end
  368.    
  369.     return 1
  370. end
  371.  
  372. function TMW.execute(id)
  373.     if TMW.enabledPlayers[ id ] and TMW.selectedAction[ id ] then
  374.        
  375.         if TMW.selectedAction[ id ] == -1 then
  376.             TMW.GUI_close(id)
  377.            
  378.         elseif TMW.selectedAction[ id ] > 0 then
  379.             TMW.equipList(id, TMW.selectedAction[ id ])
  380.         end
  381.        
  382.     end
  383. end
  384.  
  385. function TMW.equipList(id, listNumber)
  386.     if TMW.wpnList[listNumber][6] == false then
  387.         msg2(id, "©255255255[TooManyWeapons] This item is disabled!")
  388.         return false
  389.     end
  390.    
  391.     if TMW.permission_check(id, listNumber) == false then
  392.         return false    -- no permission
  393.     end
  394.    
  395.     for i = 1, #TMW.wpnList[listNumber][ 7 ] do
  396.         TMW.equip(id, TMW.wpnList[listNumber][ 7 ][ i ])
  397.     end
  398.     msg2(id, "©255255255[TooManyWeapons] Equipped you with " ..TMW.wpnList[listNumber][ 5 ])
  399.     print("[TMW] Equipped ID ".. id ..", #".. player(id, "usgn") .." with item " ..TMW.wpnList[listNumber][ 5 ])
  400.    
  401.     return true
  402. end
  403.  
  404. function TMW.equip(id, itemID)
  405.     if not TMW.unequipable[itemID] then
  406.         parse("equip " .. id .. " " ..itemID)
  407.     else
  408.         TMW.equipUnequipable(id, itemID)
  409.     end
  410. end
  411.  
  412. function TMW.equipUnequipable(id, itemID)
  413.     playerTileX, playerTileY = player(id, "tilex"), player(id, "tiley")
  414.     parse("spawnitem ".. itemID .." ".. playerTileX .." ".. playerTileY)
  415.    
  416.     local minX, maxX = -1, 1
  417.     local minY, maxY = -1, 1
  418.    
  419.     repeat
  420.         for x = minX, maxX, 1 do
  421.             for y = minY, maxY, 1 do
  422.                 if tile(x, y, "deadly") == false and (x ~= playerTileY and y ~= playerTileY) then
  423.                     --tp
  424.                     parse("setpos ".. id .." ".. (playerTileX + x) * 32 + 16 .." ".. (playerTileY + y) * 32 + 16)
  425.                     parse("setpos ".. id .." ".. (playerTileX) * 32 + 16 .." ".. (playerTileY) * 32 + 16)
  426.                    
  427.                     return true
  428.                 end
  429.             end
  430.         end
  431.        
  432.         minX, maxX = minX - 1, maxX - 1
  433.         mixY, maxY = minY - 1, maxY - 1
  434.     until maxX >= 10
  435.    
  436.     return false
  437. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement