Advertisement
Guest User

Untitled

a guest
Jul 30th, 2015
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.01 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. This should teleport all players to a new random town in intervals and add them into a team.
  5. </description>
  6. <config name="config"><![CDATA[
  7. t = {
  8. main = {
  9. positions = {
  10. paintball_spawn_area = {
  11. top_left = {x = 970, y = 1040, z = 4}, --Top left pos of spawning area
  12. bottom_right = {x = 975, y = 1046, z = 7}--bottom right pos of spawning area
  13. },
  14. tp_to_paintball = {x = 985, y = 1052, z = 7}, --pos where the tp will be created
  15. event_ending_pos = {x = 985, y = 1052, z = 7} --pos players will be sent after event ending
  16. },
  17. storages = {
  18. exhaust = 2455,
  19. is_in_event = 2460,
  20. score = 2465
  21. },
  22. misc = {
  23. status = 'on'
  24. },
  25. messages = {
  26. event_started = "Paintball event has started! there's a teleport near Thais temple!",--Message that will be broadcasted after the event has started
  27. event_ended = "Paintball event has ended!" --same but when event ends
  28. },
  29. event_config = {
  30. event_duration = 0, --minutes, 0 if it's an always-open event
  31. infinite_ammo = false,
  32. winner_gets_item = true,
  33. prize_item_id = 3051,
  34. decrease_score_on_death = true,
  35. points_per_kill = 1,
  36. randomize_player_start_pos = true,
  37. ammo_per_point = 100,
  38. reset_bullets_on_death = true,
  39. min_bullets_on_spawn = 100
  40. }
  41. },
  42. onShoot = {
  43. storages = {
  44. ammo = 2400
  45. },
  46. misc = {
  47. walls_id = {1115,1111,1112,5258,1385,1113},
  48. bullets_exhaust = 500, --in ms
  49. bullet_speed = 150
  50. },
  51. vars = {
  52. shootdir = 0
  53. }
  54. }
  55. }
  56. ]]></config>
  57. <movevent type="StepIn" actionid ="2880" event="script"><![CDATA[
  58. domodlib('config')
  59. local t_l = t.main.positions.paintball_spawn_area.top_left
  60. local b_r = t.main.positions.paintball_spawn_area.bottom_right
  61. function onStepIn(cid, item, pos)
  62. 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)})
  63. doPlayerSetStorageValue(cid, t.main.storages.is_in_event,1)
  64. doPlayerSetStorageValue(cid, t.onShoot.storages.ammo, t.main.event_config.min_bullets_on_spawn)
  65. doPlayerSetStorageValue(cid, t.main.storages.score, 0)
  66. 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.")
  67. end
  68. ]]></movevent>
  69. <talkaction words="!shoot" event="script"><![CDATA[
  70. domodlib('config')
  71. function onSay(cid, words, param, channel)
  72. local k = string.explode(param, ",")
  73. if(k[1] ~= nil) then
  74. if(string.upper(k[1]) == 'END') and getPlayerGroupId(cid) >= 3 then
  75. endPaintball()
  76. end
  77. if(string.upper(k[1]) == 'START') and getPlayerGroupId(cid) >= 3 then
  78. doBroadcastMessage(t.main.messages.event_started, MESSAGE_STATUS_WARNING)
  79. doSetItemActionId(doCreateItem(1387, t.main.positions.tp_to_paintball), 2880)
  80. if(t.main.event_config.event_duration > 0) then
  81. addEvent(endPaintball, t.main.event_config.event_duration*1000*60)
  82. end
  83.  
  84. end
  85. if(string.upper(k[1]) == 'INFO') then
  86. local score = {}
  87. 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"
  88. for _, pid in ipairs(getPlayersOnline()) do
  89. if getPlayerStorageValue(pid, t.main.storages.is_in_event) then
  90. table.insert(score, {getCreatureName(pid), getPlayerStorageValue(pid, t.main.storages.score)})
  91. end
  92. end
  93. local lx = table.getn(score)
  94. if(lx > 3) then lx = 3 end
  95. table.sort(score, function(a, b) return a[2] > b[2] end)
  96. for k = 1,lx do
  97. output = output .. k..". "..score[k][1] .." [".. score[k][2] .."].\n"
  98. end
  99. doPlayerPopupFYI(cid, output)
  100. end
  101. if (string.upper(k[1]) == 'AMMO') then
  102. if(t.main.event_config.infinite_ammo) then
  103. doPlayerSendTextMessage(cid, 27, "Ammo is infinite, there's no need to buy more.")
  104. else
  105. if getPlayerStorageValue(cid, t.main.storages.score) > 0 then
  106. doPlayerSetStorageValue(cid, t.main.storages.score, getPlayerStorageValue(cid, t.main.storages.score)-1)
  107. doPlayerSetStorageValue(cid, t.onShoot.storages.ammo, getPlayerStorageValue(cid,t.onShoot.storages.ammo)+t.main.event_config.ammo_per_point)
  108. doPlayerSendTextMessage(cid, 27, "You have received " .. t.main.event_config.ammo_per_point .. " bullets and you have lost 1 score point.")
  109. doSendMagicEffect(getCreaturePosition(cid),4)
  110. else
  111. doPlayerSendTextMessage(cid, 27, "You do not have enough score points to buy ammo, you need ".. 1-(getPlayerStorageValue(cid, t.main.storages.score)).. " more.")
  112. end
  113. end
  114. end
  115. if (string.upper(k[1]) == 'BULLET') then
  116. if(getPlayerStorageValue(cid, t.main.storages.is_in_event) == 1) then
  117. if getPlayerStorageValue(cid, t.main.storages.exhaust) <= 1 then
  118. if(getPlayerStorageValue(cid, t.onShoot.storages.ammo) > 0) then
  119. if t.main.misc.status == 'on' then
  120. if(t.main.event_config.infinite_ammo == false) then
  121. doPlayerSetStorageValue(cid, t.onShoot.storages.ammo, getPlayerStorageValue(cid, t.onShoot.storages.ammo)-1)
  122. end
  123. doPlayerSetStorageValue(cid, t.main.storages.exhaust, 2)
  124. lineAnimation(getPlayerLookDirection(cid),getCreaturePosition(cid),12,cid,1,0,1,0,0,0,1,0)
  125. addEvent(doPlayerSetStorageValue,t.onShoot.misc.bullets_exhaust, cid, t.main.storages.exhaust,1)
  126. else
  127. return false
  128. end
  129. else
  130. doPlayerSendCancel(cid, "You're out of ammo, exchange ammo for points with !shoot ammo or get killed for a recharge.")
  131. doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
  132. end
  133. else
  134. doPlayerSendCancel(cid, "Gun is on cooldown")
  135. doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
  136. end
  137. else
  138. doPlayerSendCancel(cid, "You need to be in the event.")
  139. doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
  140. end
  141. end
  142. end
  143. return true
  144. end
  145.  
  146.  
  147. function lineAnimation(lookDir,playerPos,effect,cid,fvar,fpos,ffound,fposV,fcheck,fvcid,floopCounter,fvpid, name)
  148. local var = fvar
  149. local pos = fpos
  150. local found = ffound
  151. local posV = fposV
  152. local check = fcheck
  153. local vcid = fvcid
  154. local loopCounter = floopCounter
  155. local vpid = fvpid
  156. local storage = t.main.storages.exhaust
  157. if var < 2 then
  158. vcid = cid
  159. end
  160. pos = playerPos
  161. 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
  162. doSendDistanceShoot(pos, convert(lookDir,pos),effect)
  163. pos = convert(lookDir,pos)
  164. var=var+1
  165. posV = convertV(lookDir,playerPos)
  166. for _, pid in ipairs(getPlayersOnline()) do
  167. if (getCreaturePosition(pid).x == pos.x and getCreaturePosition(pid).y == pos.y and getCreaturePosition(pid).z == pos.z) then
  168. --if loopCounter > 2 then
  169. vpid = pid
  170. --end
  171. if (vpid ~= vcid) then
  172. if var > 2 then
  173. if (getCreaturePosition(pid).x == posV.x and getCreaturePosition(pid).y == posV.y and getCreaturePosition(pid).z == posV.z) then
  174. killPlayer(pid,pos,getCreatureName(vcid))
  175. if (lookDir == 0) or (lookDir == 2) then
  176. var = 6
  177. else
  178. var = 8
  179. end
  180. end
  181. end
  182. killPlayer(pid,pos,vcid)
  183. if (lookDir == 0) or (lookDir == 2) then
  184. var = 6
  185. else
  186. var = 8
  187. end
  188. end
  189. end
  190. loopCounter = loopCounter +1
  191. end
  192. if (lookDir == 0) or (lookDir == 2) then
  193. if var ~= 6 then
  194. addEvent(lineAnimation, t.onShoot.misc.bullet_speed, lookDir,pos,effect,nil,var,pos,found,posV,check,vcid,loopCounter,vpid)
  195. else
  196. var = 1
  197. end
  198. else
  199. if var ~= 8 then
  200. addEvent(lineAnimation, t.onShoot.misc.bullet_speed, lookDir,pos,effect,nil,var,pos,found,posV,check,vcid,loopCounter,vpid)
  201. else
  202. var = 1
  203. end
  204. end
  205. else
  206. doSendMagicEffect(convert(lookDir,pos),2)
  207. var = 1
  208. end
  209. end
  210.  
  211. local ret = {}
  212. function convert(lookDir,pos)
  213. local positions = {
  214. [0] = {x = pos.x, y = pos.y-1, z = pos.z},
  215. [1] = {x = pos.x+1, y = pos.y, z = pos.z},
  216. [2] = {x = pos.x, y = pos.y+1, z = pos.z},
  217. [3] = {x = pos.x-1, y = pos.y, z = pos.z}
  218. }
  219. ret = positions[lookDir]
  220. return ret
  221. end
  222.  
  223.  
  224. local ret = {}
  225. function convertV(lookDir,pos)
  226. local positions = {
  227. [0] = {x = pos.x, y = pos.y+1, z = pos.z},
  228. [1] = {x = pos.x-1, y = pos.y, z = pos.z},
  229. [2] = {x = pos.x, y = pos.y-1, z = pos.z},
  230. [3] = {x = pos.x+1, y = pos.y, z = pos.z}
  231. }
  232. ret = positions[lookDir]
  233. return ret
  234. end
  235.  
  236. function killPlayer(cid,pos, killer)
  237. local t_l = t.main.positions.paintball_spawn_area.top_left
  238. local b_r = t.main.positions.paintball_spawn_area.bottom_right
  239. 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)})
  240. doSendMagicEffect(pos,2)
  241. doPlayerSendTextMessage(cid, 27, "You've been killed by "..getCreatureName(killer)..".")
  242. doPlayerSetStorageValue(killer, t.main.storages.score, getPlayerStorageValue(killer, t.main.storages.score)+t.main.event_config.points_per_kill)
  243. doPlayerSendTextMessage(killer, 27, "You've killed "..getCreatureName(cid)..".")
  244. doBroadcastMessage("[Event] Paintball: "..getCreatureName(killer).." has killed "..getCreatureName(cid)..".", MESSAGE_STATUS_WARNING)
  245. if t.main.event_config.decrease_score_on_death then
  246. doPlayerSetStorageValue(cid, t.main.storages.score, getPlayerStorageValue(cid, t.main.storages.score)-1)
  247. end
  248. if t.main.event_config.reset_bullets_on_death then
  249. doPlayerSetStorageValue(cid, t.onShoot.storages.ammo, t.main.event_config.min_bullets_on_spawn)
  250. end
  251. end
  252.  
  253. function isInWallArray(pos)
  254. for k = 0, table.getn(t.onShoot.misc.walls_id) do
  255. 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
  256. return true
  257. end
  258. end
  259. return false
  260. end
  261.  
  262. function endPaintball()
  263. local score = {}
  264. doRemoveItem(getTileItemById(t.main.positions.tp_to_paintball,1387).uid)
  265. for _, pid in ipairs(getPlayersOnline()) do
  266. if getPlayerStorageValue(pid, t.main.storages.is_in_event) > 0 then
  267. table.insert(score, {getCreatureName(pid), getPlayerStorageValue(pid, t.main.storages.score)})
  268. doPlayerSetStorageValue(pid, t.main.storages.is_in_event, 0)
  269. doPlayerSetStorageValue(pid, t.main.storages.score, 0)
  270. doPlayerSetStorageValue(pid, t.onShoot.storages.ammo, 0)
  271. doTeleportThing(pid, t.main.positions.event_ending_pos)
  272. end
  273. end
  274. table.sort(score, function(a, b) return a[2] > b[2] end)
  275. if table.getn(score) > 0 then
  276. if t.main.event_config.winner_gets_item then
  277. for _, pid in ipairs(getPlayersOnline()) do
  278. if getCreatureName(pid) == score[1][1] then
  279. doPlayerAddItem(pid, t.main.event_config.prize_item_id)
  280. break
  281. end
  282. end
  283. end
  284. doBroadcastMessage("Painball event has ended, "..score[1][1].." won paintball event with "..score[1][2].." points", MESSAGE_STATUS_WARNING)
  285. end
  286. end
  287. ]]></talkaction>
  288. </mod>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement