Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 31.00 KB | None | 0 0
  1. My bad, with linking I should of probably pasted the whole script. Its a mod.
  2. [code=Lua]<?xml version="1.0" encoding="UTF-8"?>
  3. <mod name="Paintball event" version="1.0" author="Bogart" contact="otland.net" enabled="yes">
  4. <description>
  5.  
  6. </description>
  7. <config name="config"><![CDATA[
  8. t = {
  9. main = {
  10. tfs_version = "0.3", --0.3 or 0.4
  11. positions = {
  12. paintball_spawn_area = {
  13. top_left = {x = 556, y = 2849, z = 5}, --Top left pos of spawning area
  14. bottom_right = {x = 621, y = 2890, z = 5}--bottom right pos of spawning area
  15. },
  16. waiting_room_area = {
  17. top_left = {x = 662, y = 2860, z = 5}, --Top left pos of the waiting room
  18. bottom_right = {x = 666, y = 2869, z = 5}--bottom right pos of the waiting room
  19. },
  20. tp_to_paintball = {x = 1451, y = 1828, z = 7}, --pos where the tp will be created
  21. event_ending_pos = {x = 1000, y = 1000, z = 7} --pos players will be sent after event ending
  22. },
  23. storages = {
  24. exhaust = 2455,
  25. is_in_event = 2460,
  26. score = 2465
  27. },
  28. misc = {
  29. status = 'on'
  30. },
  31. messages = {
  32. event_started = "Paintball event has started! There's a teleport in event room you have 3 minutes!",--Message that will be broadcasted after the event has started
  33. event_ended = "Paintball event has finished! It will open again in 4 hours " --same but when event ends
  34. },
  35. event_config = {
  36. event_duration = 10, --minutes, 0 if it's an always-open event
  37. infinite_ammo = false,
  38. winner_gets_item = true,
  39. prize_item_id = 10141,
  40. decrease_score_on_death = true,
  41. points_per_kill = 1,
  42. randomize_player_start_pos = true,
  43. ammo_per_point = 100,
  44. reset_bullets_on_death = true,
  45. min_bullets_on_spawn = 100,
  46. start_automatically = true,
  47. use_waiting_room = true,
  48. waiting_time = 3 --minutes
  49. }
  50. },
  51. onShoot = {
  52. storages = {
  53. ammo = 2400
  54. },
  55. misc = {
  56. walls_id = {1937,3361,1515,1546,1385,1933,3362},
  57. bullets_exhaust = 500, --in ms
  58. bullet_speed = 150
  59. },
  60. vars = {
  61. shootdir = 0
  62. }
  63. }
  64. }
  65. ]]></config>
  66. <movevent type="StepIn" actionid ="2880" event="script"><![CDATA[
  67. domodlib('config')
  68. function onStepIn(cid, item, pos)
  69. local t_l = t.main.positions.paintball_spawn_area.top_left
  70. local b_r = t.main.positions.paintball_spawn_area.bottom_right
  71. doTeleportThing(cid, {x=math.random(t_l.x,b_r.x), y=math.random(t_l.y, b_r.y), z=math.random(t_l.z, b_r.z)})
  72. doPlayerSetStorageValue(cid, t.main.storages.is_in_event,1)
  73. doPlayerSetStorageValue(cid, t.onShoot.storages.ammo, t.main.event_config.min_bullets_on_spawn)
  74. doPlayerSetStorageValue(cid, t.main.storages.score, 0)
  75. doPlayerSendTextMessage(cid,MESSAGE_STATUS_CONSOLE_BLUE,"Welcome to paintball, here are the commands:\n!shoot bullet --This will shot a bullet.\n!shoot ammo --This will give you "..t.main.event_config.ammo_per_point.." bullets and take 1 point from your current score (you need at least 1 point to use this command).\n!shoot info --This will show you your current score and ammo, it'll also show the current high score of the event.\nIt is strongly recommended that you bind these commands to your hotkeys.")
  76. end
  77. ]]></movevent>
  78. <movevent type="StepIn" actionid ="2881" event="script"><![CDATA[
  79. domodlib('config')
  80. function onStepIn(cid, item, pos)
  81. doTeleportThing(cid, t.main.positions.waiting_room_area.top_left)
  82. doPlayerSendTextMessage(cid,MESSAGE_STATUS_CONSOLE_BLUE,"Welcome to paintball, here are the commands:\n!shoot bullet --This will shot a bullet.\n!shoot ammo --This will give you "..t.main.event_config.ammo_per_point.." bullets and take 1 point from your current score (you need at least 1 point to use this command).\n!shoot info --This will show you your current score and ammo, it'll also show the current high score of the event.\nIt is strongly recommended that you bind these commands to your hotkeys.")
  83. end
  84. ]]></movevent>
  85. <globalevent name="StartPaintBall2" time="02:08" event="script"><![CDATA[
  86.  
  87. domodlib('config')
  88. function onTimer()
  89. if t.main.event_config.start_automatically then
  90. doBroadcastMessage(t.main.messages.event_started, MESSAGE_STATUS_WARNING)
  91. if t.main.event_config.use_waiting_room then
  92. addEvent(moveToEvent, t.main.event_config.waiting_time*1000*60)
  93. addEvent(waitMsg, (t.main.event_config.waiting_time - 1)*1000*60)
  94. doItemSetAttribute(doCreateItem(1387, t.main.positions.tp_to_paintball), "aid", 2881)
  95. --doCreateTeleport(1387,t.main.positions.waiting_room_area.top_left, t.main.positions.tp_to_paintball)
  96. else
  97. if t.main.tfs_version == "0.3" then
  98. doItemSetAttribute(doCreateItem(1387, t.main.positions.tp_to_paintball), "aid", 2880)
  99. else
  100. doSetItemActionId(doCreateItem(1387, t.main.positions.tp_to_paintball),2880)
  101. end
  102. if(t.main.event_config.event_duration > 0) then
  103. addEvent(endPaintball, t.main.event_config.event_duration*1000*60)
  104. end
  105. end
  106. end
  107. return true
  108. end
  109.  
  110. function endPaintball()
  111. local score = {}
  112. if not t.main.event_config.use_waiting_room then
  113. doRemoveItem(getTileItemById(t.main.positions.tp_to_paintball,1387).uid)
  114. end
  115. for _, pid in ipairs(getPlayersOnline()) do
  116. if getPlayerStorageValue(pid, t.main.storages.is_in_event) > 0 then
  117. table.insert(score, {getCreatureName(pid), getPlayerStorageValue(pid, t.main.storages.score)})
  118. doPlayerSetStorageValue(pid, t.main.storages.is_in_event, 0)
  119. doPlayerSetStorageValue(pid, t.main.storages.score, 0)
  120. doPlayerSetStorageValue(pid, t.onShoot.storages.ammo, 0)
  121. doTeleportThing(pid, t.main.positions.event_ending_pos)
  122. end
  123. end
  124. table.sort(score, function(a, b) return a[2] > b[2] end)
  125. if table.getn(score) > 0 then
  126. if t.main.event_config.winner_gets_item then
  127. for _, pid in ipairs(getPlayersOnline()) do
  128. if getCreatureName(pid) == score[1][1] then
  129. doPlayerAddItem(pid, t.main.event_config.prize_item_id)
  130. break
  131. end
  132. end
  133. end
  134. doBroadcastMessage("Paintball event has ended, "..score[1][1].." won paintball event with "..score[1][2].." points", MESSAGE_STATUS_WARNING)
  135. end
  136. end
  137. local t_l = t.main.positions.paintball_spawn_area.top_left
  138. local b_r = t.main.positions.paintball_spawn_area.bottom_right
  139. function waitMsg()
  140. for _, pid in ipairs(getPlayersOnline()) do
  141. if isInRange(getCreaturePosition(pid), t.main.positions.waiting_room_area.top_left, t.main.positions.waiting_room_area.bottom_right) then
  142. doPlayerSendTextMessage(pid,MESSAGE_STATUS_CONSOLE_ORANGE,"You have 1 more minute untill the paintball event start!")
  143. end
  144. end
  145. end
  146. function moveToEvent()
  147. for _, pid in ipairs(getPlayersOnline()) do
  148. if isInRange(getCreaturePosition(pid), t.main.positions.waiting_room_area.top_left, t.main.positions.waiting_room_area.bottom_right) then
  149. doTeleportThing(pid, {x=math.random(t_l.x,b_r.x), y=math.random(t_l.y, b_r.y), z=math.random(t_l.z, b_r.z)})
  150. doPlayerSetStorageValue(pid, t.main.storages.is_in_event,1)
  151. doPlayerSetStorageValue(pid, t.onShoot.storages.ammo, t.main.event_config.min_bullets_on_spawn)
  152. doPlayerSetStorageValue(pid, t.main.storages.score, 0)
  153. doPlayerSendTextMessage(pid,27,"Welcome to paintball, here are the commands:\n!shoot bullet --This will shot a bullet.\n!shoot ammo --This will give you "..t.main.event_config.ammo_per_point.." bullets and take 1 point from your current score (you need at least 1 point to use this command).\n!shoot info --This will show you your current score and ammo, it'll also show the current high score of the event.\nIt is strongly recommended that you bind these commands to your hotkeys.")
  154. end
  155. end
  156. doRemoveItem(getTileItemById(t.main.positions.tp_to_paintball,1387).uid)
  157. addEvent(endPaintball, t.main.event_config.event_duration*1000*60)
  158. end
  159. ]]></globalevent>
  160. <talkaction words="!shoot" event="script"><![CDATA[
  161. domodlib('config')
  162. function onSay(cid, words, param, channel)
  163. local k = string.explode(param, ",")
  164. if(k[1] ~= nil) then
  165. if(string.upper(k[1]) == 'END') and getPlayerGroupId(cid) >= 3 then
  166. endPaintball()
  167. end
  168. if(string.upper(k[1]) == 'START') and getPlayerGroupId(cid) >= 3 then
  169. doBroadcastMessage(t.main.messages.event_started, MESSAGE_STATUS_WARNING)
  170. if t.main.event_config.use_waiting_room then
  171. addEvent(moveToEvent, t.main.event_config.waiting_time*1000*60)
  172. addEvent(waitMsg, (t.main.event_config.waiting_time - 1)*1000*60)
  173. doItemSetAttribute(doCreateItem(1387, t.main.positions.tp_to_paintball), "aid", 2881)
  174. --doCreateTeleport(1387,t.main.positions.waiting_room_area.top_left, t.main.positions.tp_to_paintball)
  175. else
  176. if t.main.tfs_version == "0.3" then
  177. doItemSetAttribute(doCreateItem(1387, t.main.positions.tp_to_paintball), "aid", 2880)
  178. else
  179. doSetItemActionId(doCreateItem(1387, t.main.positions.tp_to_paintball),2880)
  180. end
  181. if(t.main.event_config.event_duration > 0) then
  182. addEvent(endPaintball, t.main.event_config.event_duration*1000*60)
  183. end
  184. end
  185. end
  186. if(string.upper(k[1]) == 'INFO') then
  187. local score = {}
  188. local output = "You have " .. getPlayerStorageValue(cid, t.main.storages.score) .. " points.\nYou have "..getPlayerStorageValue(cid, t.onShoot.storages.ammo).." ammo left.\n------------------\nThe current high score in paintball is:\n"
  189. for _, pid in ipairs(getPlayersOnline()) do
  190. if getPlayerStorageValue(pid, t.main.storages.is_in_event) then
  191. table.insert(score, {getCreatureName(pid), getPlayerStorageValue(pid, t.main.storages.score)})
  192. end
  193. end
  194. local lx = table.getn(score)
  195. if(lx > 3) then lx = 3 end
  196. table.sort(score, function(a, b) return a[2] > b[2] end)
  197. for k = 1,lx do
  198. output = output .. k..". "..score[k][1] .." [".. score[k][2] .."].\n"
  199. end
  200. doPlayerPopupFYI(cid, output)
  201. end
  202. if (string.upper(k[1]) == 'AMMO') then
  203. if(t.main.event_config.infinite_ammo) then
  204. doPlayerSendTextMessage(cid, 27, "Ammo is infinite, there's no need to buy more.")
  205. else
  206. if getPlayerStorageValue(cid, t.main.storages.score) > 0 then
  207. doPlayerSetStorageValue(cid, t.main.storages.score, getPlayerStorageValue(cid, t.main.storages.score)-1)
  208. doPlayerSetStorageValue(cid, t.onShoot.storages.ammo, getPlayerStorageValue(cid,t.onShoot.storages.ammo)+t.main.event_config.ammo_per_point)
  209. doPlayerSendTextMessage(cid, 27, "You have received " .. t.main.event_config.ammo_per_point .. " bullets and you have lost 1 score point.")
  210. doSendMagicEffect(getCreaturePosition(cid),4)
  211. else
  212. doPlayerSendTextMessage(cid, 27, "You do not have enough score points to buy ammo, you need ".. 1-(getPlayerStorageValue(cid, t.main.storages.score)).. " more.")
  213. end
  214. end
  215. end
  216. if (string.upper(k[1]) == 'BULLET') then
  217. if(getPlayerStorageValue(cid, t.main.storages.is_in_event) == 1) then
  218. if getPlayerStorageValue(cid, t.main.storages.exhaust) <= 1 then
  219. if(getPlayerStorageValue(cid, t.onShoot.storages.ammo) > 0) then
  220. if t.main.misc.status == 'on' then
  221. if(t.main.event_config.infinite_ammo == false) then
  222. doPlayerSetStorageValue(cid, t.onShoot.storages.ammo, getPlayerStorageValue(cid, t.onShoot.storages.ammo)-1)
  223. end
  224. doPlayerSetStorageValue(cid, t.main.storages.exhaust, 2)
  225. lineAnimation(getPlayerLookDirection(cid),getCreaturePosition(cid),12,cid,1,0,1,0,0,0,1,0)
  226. addEvent(doPlayerSetStorageValue,t.onShoot.misc.bullets_exhaust, cid, t.main.storages.exhaust,1)
  227. end
  228. else
  229. doPlayerSendCancel(cid, "You're out of ammo, exchange ammo for points with !shoot ammo or get killed for a recharge.")
  230. doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
  231. end
  232. else
  233. doPlayerSendCancel(cid, "Gun is on cooldown")
  234. doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
  235. end
  236. else
  237. doPlayerSendCancel(cid, "You need to be in the event.")
  238. doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
  239. end
  240. end
  241. end
  242. return true
  243. end
  244. function lineAnimation(lookDir,playerPos,effect,cid,fvar,fpos,ffound,fposV,fcheck,fvcid,floopCounter,fvpid, name)
  245. local var = fvar
  246. local pos = fpos
  247. local found = ffound
  248. local posV = fposV
  249. local check = fcheck
  250. local vcid = fvcid
  251. local loopCounter = floopCounter
  252. local vpid = fvpid
  253. local storage = t.main.storages.exhaust
  254. if var < 2 then
  255. vcid = cid
  256. end
  257. pos = playerPos
  258. if not isInWallArray(convert(lookDir,pos)) then--isInWallArray({x=convert(lookDir,pos).x, y=convert(lookDir,pos).y,z=convert(lookDir,pos).z}) then --isInArray(t.onShoot.misc.walls_id, getThingfromPos({x=convert(lookDir,pos).x, y=convert(lookDir,pos).y,z=convert(lookDir,pos).z, stackpos=0}).itemid) then
  259. doSendDistanceShoot(pos, convert(lookDir,pos),effect)
  260. pos = convert(lookDir,pos)
  261. var=var+1
  262. posV = convertV(lookDir,playerPos)
  263. for _, pid in ipairs(getPlayersOnline()) do
  264. if (getCreaturePosition(pid).x == pos.x and getCreaturePosition(pid).y == pos.y and getCreaturePosition(pid).z == pos.z) then
  265. --if loopCounter > 2 then
  266. vpid = pid
  267. --end
  268. if (vpid ~= vcid) then
  269. if var > 2 then
  270. if (getCreaturePosition(pid).x == posV.x and getCreaturePosition(pid).y == posV.y and getCreaturePosition(pid).z == posV.z) then
  271. killPlayer(pid,pos,getCreatureName(vcid))
  272. if (lookDir == 0) or (lookDir == 2) then
  273. var = 6
  274. else
  275. var = 8
  276. end
  277. end
  278. end
  279. killPlayer(pid,pos,vcid)
  280. if (lookDir == 0) or (lookDir == 2) then
  281. var = 6
  282. else
  283. var = 8
  284. end
  285. end
  286. end
  287. loopCounter = loopCounter +1
  288. end
  289. if (lookDir == 0) or (lookDir == 2) then
  290. if var ~= 6 then
  291. addEvent(lineAnimation, t.onShoot.misc.bullet_speed, lookDir,pos,effect,nil,var,pos,found,posV,check,vcid,loopCounter,vpid)
  292. else
  293. var = 1
  294. end
  295. else
  296. if var ~= 8 then
  297. addEvent(lineAnimation, t.onShoot.misc.bullet_speed, lookDir,pos,effect,nil,var,pos,found,posV,check,vcid,loopCounter,vpid)
  298. else
  299. var = 1
  300. end
  301. end
  302. else
  303. doSendMagicEffect(convert(lookDir,pos),2)
  304. var = 1
  305. end
  306. end
  307. local ret = {}
  308. function convert(lookDir,pos)
  309. local positions = {
  310. [0] = {x = pos.x, y = pos.y-1, z = pos.z},
  311. [1] = {x = pos.x+1, y = pos.y, z = pos.z},
  312. [2] = {x = pos.x, y = pos.y+1, z = pos.z},
  313. [3] = {x = pos.x-1, y = pos.y, z = pos.z}
  314. }
  315. ret = positions[lookDir]
  316. return ret
  317. end
  318. local ret = {}
  319. function convertV(lookDir,pos)
  320. local positions = {
  321. [0] = {x = pos.x, y = pos.y+1, z = pos.z},
  322. [1] = {x = pos.x-1, y = pos.y, z = pos.z},
  323. [2] = {x = pos.x, y = pos.y-1, z = pos.z},
  324. [3] = {x = pos.x+1, y = pos.y, z = pos.z}
  325. }
  326. ret = positions[lookDir]
  327. return ret
  328. end
  329.  
  330. function killPlayer(cid,pos, killer)
  331. local t_l = t.main.positions.paintball_spawn_area.top_left
  332. local b_r = t.main.positions.paintball_spawn_area.bottom_right
  333. doTeleportThing(cid, {x=math.random(t_l.x,b_r.x), y=math.random(t_l.y, b_r.y), z=math.random(t_l.z, b_r.z)})
  334. doSendMagicEffect(pos,2)
  335. doPlayerSendTextMessage(cid, 27, "You've been killed by "..getCreatureName(killer)..".")
  336. doPlayerSetStorageValue(killer, t.main.storages.score, getPlayerStorageValue(killer, t.main.storages.score)+t.main.event_config.points_per_kill)
  337. doPlayerSendTextMessage(killer, 27, "You've killed "..getCreatureName(cid)..".")
  338. doBroadcastMessage("[Event] Paintball: "..getCreatureName(killer).." has killed "..getCreatureName(cid)..".", MESSAGE_STATUS_WARNING)
  339. if t.main.event_config.decrease_score_on_death then
  340. doPlayerSetStorageValue(cid, t.main.storages.score, getPlayerStorageValue(cid, t.main.storages.score)-1)
  341. end
  342. if t.main.event_config.reset_bullets_on_death then
  343. doPlayerSetStorageValue(cid, t.onShoot.storages.ammo, t.main.event_config.min_bullets_on_spawn)
  344. end
  345. end
  346.  
  347. function isInWallArray(pos)
  348. for k = 0, table.getn(t.onShoot.misc.walls_id) do
  349. if getTileItemById(pos, t.onShoot.misc.walls_id[k]).itemid == t.onShoot.misc.walls_id[k] then --this doesn't even make sense but tried other ways and it gave errors, so meh 2lazy2search
  350. return true
  351. end
  352. end
  353. return false
  354. end
  355. function endPaintball()
  356. local score = {}
  357. if not t.main.event_config.use_waiting_room then
  358. doRemoveItem(getTileItemById(t.main.positions.tp_to_paintball,1387).uid)
  359. end
  360. for _, pid in ipairs(getPlayersOnline()) do
  361. if getPlayerStorageValue(pid, t.main.storages.is_in_event) > 0 then
  362. table.insert(score, {getCreatureName(pid), getPlayerStorageValue(pid, t.main.storages.score)})
  363. doPlayerSetStorageValue(pid, t.main.storages.is_in_event, 0)
  364. doPlayerSetStorageValue(pid, t.main.storages.score, 0)
  365. doPlayerSetStorageValue(pid, t.onShoot.storages.ammo, 0)
  366. doTeleportThing(pid, t.main.positions.event_ending_pos)
  367. end
  368. end
  369. table.sort(score, function(a, b) return a[2] > b[2] end)
  370. if table.getn(score) > 0 then
  371. if t.main.event_config.winner_gets_item then
  372. for _, pid in ipairs(getPlayersOnline()) do
  373. if getCreatureName(pid) == score[1][1] then
  374. doPlayerAddItem(pid, t.main.event_config.prize_item_id)
  375. break
  376. end
  377. end
  378. end
  379. doBroadcastMessage("Painball event has ended, "..score[1][1].." won paintball event with "..score[1][2].." points", MESSAGE_STATUS_WARNING)
  380. end
  381. end
  382. local t_l = t.main.positions.paintball_spawn_area.top_left
  383. local b_r = t.main.positions.paintball_spawn_area.bottom_right
  384. function waitMsg()
  385. for _, pid in ipairs(getPlayersOnline()) do
  386. if isInRange(getCreaturePosition(pid), t.main.positions.waiting_room_area.top_left, t.main.positions.waiting_room_area.bottom_right) then
  387. doPlayerSendTextMessage(pid,MESSAGE_STATUS_CONSOLE_ORANGE,"You have 1 more minute untill the paintball event start!")
  388. end
  389. end
  390. end
  391. function moveToEvent()
  392. for _, pid in ipairs(getPlayersOnline()) do
  393. if isInRange(getCreaturePosition(pid), t.main.positions.waiting_room_area.top_left, t.main.positions.waiting_room_area.bottom_right) then
  394. doTeleportThing(pid, {x=math.random(t_l.x,b_r.x), y=math.random(t_l.y, b_r.y), z=math.random(t_l.z, b_r.z)})
  395. doPlayerSetStorageValue(pid, t.main.storages.is_in_event,1)
  396. doPlayerSetStorageValue(pid, t.onShoot.storages.ammo, t.main.event_config.min_bullets_on_spawn)
  397. doPlayerSetStorageValue(pid, t.main.storages.score, 0)
  398. doPlayerSendTextMessage(pid,27,"Welcome to paintball, here are the commands:\n!shoot bullet --This will shot a bullet.\n!shoot ammo --This will give you "..t.main.event_config.ammo_per_point.." bullets and take 1 point from your current score (you need at least 1 point to use this command).\n!shoot info --This will show you your current score and ammo, it'll also show the current high score of the event.\nIt is strongly recommended that you bind these commands to your hotkeys.")
  399. end
  400. end
  401. doRemoveItem(getTileItemById(t.main.positions.tp_to_paintball,1387).uid)
  402. addEvent(endPaintball, t.main.event_config.event_duration*1000*60)
  403. end
  404. ]]></talkaction>
  405. </mod>[/code]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement