Advertisement
Guest User

Untitled

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