Advertisement
Guest User

server

a guest
Apr 22nd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.44 KB | None | 0 0
  1. -- MADE BY BLOOPIS
  2. -- DATE : 04/11/2017
  3. -- ALL RIGHTS BELONG TO CREATOR
  4.  
  5. --====================================================================================
  6. -- PARAMETERS
  7. --====================================================================================
  8. local cfg = module("cfg/illness")
  9. local htmlEntities = module("lib/htmlEntities")
  10.  
  11. --====================================================================================
  12. -- UTILS
  13. --====================================================================================
  14. local player_symptoms = {}
  15. local symptoms_cooldowns = {}
  16.  
  17. function timeGreater(a, b)
  18. return ((a - b) > cfg.cd_symptoms)
  19. end
  20.  
  21. function vRP.getSymptoms(player)
  22. -- display aptitudes
  23. local user_id = vRP.getUserId(player)
  24. if user_id ~= nil then
  25. local show = true
  26. if symptoms_cooldowns[player] then
  27. show = timeGreater(os.time(), symptoms_cooldowns[player])
  28. end
  29.  
  30. if show then
  31. if player_symptoms[player] then -- hide
  32. player_symptoms[player] = nil
  33. vRPclient.removeDiv(player,{"user_symptoms"})
  34. end
  35. local content = "<h2>Symptômes :</h2><br />"
  36.  
  37. vRPclient.getUserSymptoms(player,{cfg.percent_symptoms},function(symptoms)
  38. for i,v in ipairs(symptoms) do
  39. content = content.." - "..v.."<br />"
  40. end
  41.  
  42. content = content.."<br /> 🔙 <small>".."APPUYEZ SUR [BACKSPACE] POUR FERMER".."</small><br />"
  43. player_symptoms[player] = true
  44. symptoms_cooldowns[player] = os.time()
  45. vRPclient.setDiv(player,{"user_symptoms",cfg.user_symptoms, content})
  46. end)
  47. else
  48. vRPclient.notify(player,{"~r~Il est trop tôt pour obtenir de nouveaux symptômes !! (3 minutes de cooldown)"})
  49. end
  50. end
  51. end
  52.  
  53. --====================================================================================
  54. -- MENU
  55. --====================================================================================
  56.  
  57. function vRP.ch_illness_book(player,choice)
  58.  
  59. local final_table = {}
  60. local _symptoms
  61. local _pills
  62. local _contagious
  63. for k,v in pairs(cfg.diseases) do
  64. _symptoms = ""
  65. _pills = ""
  66.  
  67. for i,sympt in ipairs(v.symptoms) do
  68. _symptoms = _symptoms..sympt.."&#13;&#10;"
  69. end
  70.  
  71. for i,pill in pairs(v.pills) do
  72. _pills = _pills..i.."&#13;&#10;"
  73. end
  74.  
  75. if v.contagious == true then
  76. _contagious = 'OUI'
  77. else
  78. _contagious = 'NON'
  79. end
  80.  
  81. table.insert(final_table, {name = v.name, contagious = _contagious, symptoms = _symptoms, pills = _pills})
  82. end
  83.  
  84. TriggerClientEvent("illness:activateMenu", player, final_table)
  85. end
  86.  
  87. function tvRP.GetMedic()
  88. local mediconline = 0
  89. for k,v in pairs(vRP.rusers) do
  90. data = vRP.getUserDataTable(k)
  91. if data then
  92. if data.groups then
  93. if not vRP.getModState(k) then
  94. if data.not_working == nil then
  95. -- only if player isn't in moderation mode and working
  96.  
  97. if data.groups["Ambulancier"] then
  98. -- health
  99. mediconline = mediconline+1
  100. end
  101. end
  102. end
  103.  
  104. end
  105. end
  106. end
  107. if mediconline >= 1 then
  108. return true
  109. else
  110. return false
  111. end
  112. end
  113.  
  114. --====================================================================================
  115. -- EVENT
  116. --====================================================================================
  117.  
  118. RegisterServerEvent('illness:removeDisease')
  119. AddEventHandler('illness:removeDisease', function(name)
  120. local _source = source
  121. local _name = name
  122. local user_id = vRP.getUserId(_source)
  123.  
  124. if user_id then
  125. local data = vRP.getUserDataTable(user_id)
  126. if data then
  127. if data.illness[_name] then
  128. data.illness[_name] = nil
  129. vRP.setUData(user_id,"vRP:datatable",json.encode(data))
  130. -- print("ILLNESS REMOVED ".._name)
  131. end
  132. end
  133. end
  134. end)
  135.  
  136. RegisterServerEvent('illness:addDisease')
  137. AddEventHandler('illness:addDisease', function(name)
  138. local _source = source
  139. local _name = name
  140. local user_id = vRP.getUserId(_source)
  141.  
  142. if user_id then
  143. local data = vRP.getUserDataTable(user_id)
  144. if data then
  145. data.illness[_name] = {true}
  146. vRP.setUData(user_id,"vRP:datatable",json.encode(data))
  147. -- print("ILLNESS ADDED ".._name)
  148. end
  149. end
  150. end)
  151.  
  152. RegisterServerEvent('illness:infectPlayer')
  153. AddEventHandler('illness:infectPlayer', function(name,target)
  154. local _source = source
  155. local _name = name
  156. local _target = target
  157.  
  158. if _target then
  159. local user_id = vRP.getUserId(_target)
  160.  
  161. vRPclient.wearingMedicMask(target,{cfg.medic_mask},function(mask_on)
  162. -- print("ILLNESS WEARING MASK "..tostring(mask_on))
  163. if not (vRP.hasGroup(user_id,"Ambulancier") and mask_on) then
  164. -- medics with a special mask can't be infected !
  165. local disease = cfg.diseases[_name]
  166. if disease ~= nil then
  167. TriggerClientEvent("illness:receiveDisease",_target, disease)
  168. -- print("ILLNESS INFECTED ".._name)
  169. end
  170. end
  171. end)
  172. end
  173. end)
  174.  
  175. RegisterServerEvent('illness:getDiseases')
  176. AddEventHandler('illness:getDiseases', function()
  177. local _source = source
  178. local user_id = vRP.getUserId(_source)
  179.  
  180. if user_id then
  181. local data = vRP.getUserDataTable(user_id)
  182. if data then
  183. local diseases = {}
  184. if data.illness == nil then
  185. -- init illness table
  186. data.illness = diseases
  187. vRP.setUData(user_id,"vRP:datatable",json.encode(data))
  188. -- print("ILLNESS FIRST INIT")
  189. else
  190. diseases = data.illness
  191. end
  192. TriggerClientEvent("illness:initDiseases",_source, cfg.diseases, diseases)
  193. -- print("ILLNESS INIT")
  194. end
  195. end
  196. end)
  197.  
  198. RegisterServerEvent('illness:setThirsty')
  199. AddEventHandler('illness:setThirsty', function()
  200. local _source = source
  201. local user_id = vRP.getUserId(_source)
  202.  
  203. if user_id then
  204. -- add exact amount ot be at 100 % without dealing damages
  205. local valueToAdd = 100.0 - vRP.getThirst(user_id)
  206. vRP.varyThirst(user_id,valueToAdd)
  207. -- print("ILLNESS THIRST "..valueToAdd)
  208. end
  209. end)
  210.  
  211. RegisterServerEvent('illness:setHungry')
  212. AddEventHandler('illness:setHungry', function()
  213. local _source = source
  214. local user_id = vRP.getUserId(_source)
  215.  
  216. if user_id then
  217. -- add exact amount ot be at 100 % without dealing damages
  218. local valueToAdd = 100.0 - vRP.getHunger(user_id)
  219. vRP.varyHunger(user_id,valueToAdd)
  220. -- print("ILLNESS HUNGER "..valueToAdd)
  221. end
  222. end)
  223.  
  224. RegisterServerEvent('illness:removeDiv')
  225. AddEventHandler('illness:removeDiv', function()
  226. local _source = source
  227. if player_symptoms[_source] then
  228. player_symptoms[_source] = nil
  229. vRPclient.removeDiv(_source,{"user_symptoms"})
  230. end
  231. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement