Advertisement
VADemon

Preview file| unrealsoftware.de/forum_posts.php?post=296563

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