Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- MADE BY BLOOPIS
- -- DATE : 04/11/2017
- -- ALL RIGHTS BELONG TO CREATOR
- --====================================================================================
- -- PARAMETERS
- --====================================================================================
- local cfg = module("cfg/illness")
- local htmlEntities = module("lib/htmlEntities")
- --====================================================================================
- -- UTILS
- --====================================================================================
- local player_symptoms = {}
- local symptoms_cooldowns = {}
- function timeGreater(a, b)
- return ((a - b) > cfg.cd_symptoms)
- end
- function vRP.getSymptoms(player)
- -- display aptitudes
- local user_id = vRP.getUserId(player)
- if user_id ~= nil then
- local show = true
- if symptoms_cooldowns[player] then
- show = timeGreater(os.time(), symptoms_cooldowns[player])
- end
- if show then
- if player_symptoms[player] then -- hide
- player_symptoms[player] = nil
- vRPclient.removeDiv(player,{"user_symptoms"})
- end
- local content = "<h2>Symptômes :</h2><br />"
- vRPclient.getUserSymptoms(player,{cfg.percent_symptoms},function(symptoms)
- for i,v in ipairs(symptoms) do
- content = content.." - "..v.."<br />"
- end
- content = content.."<br /> 🔙 <small>".."APPUYEZ SUR [BACKSPACE] POUR FERMER".."</small><br />"
- player_symptoms[player] = true
- symptoms_cooldowns[player] = os.time()
- vRPclient.setDiv(player,{"user_symptoms",cfg.user_symptoms, content})
- end)
- else
- vRPclient.notify(player,{"~r~Il est trop tôt pour obtenir de nouveaux symptômes !! (3 minutes de cooldown)"})
- end
- end
- end
- --====================================================================================
- -- MENU
- --====================================================================================
- function vRP.ch_illness_book(player,choice)
- local final_table = {}
- local _symptoms
- local _pills
- local _contagious
- for k,v in pairs(cfg.diseases) do
- _symptoms = ""
- _pills = ""
- for i,sympt in ipairs(v.symptoms) do
- _symptoms = _symptoms..sympt.." "
- end
- for i,pill in pairs(v.pills) do
- _pills = _pills..i.." "
- end
- if v.contagious == true then
- _contagious = 'OUI'
- else
- _contagious = 'NON'
- end
- table.insert(final_table, {name = v.name, contagious = _contagious, symptoms = _symptoms, pills = _pills})
- end
- TriggerClientEvent("illness:activateMenu", player, final_table)
- end
- function tvRP.GetMedic()
- local mediconline = 0
- for k,v in pairs(vRP.rusers) do
- data = vRP.getUserDataTable(k)
- if data then
- if data.groups then
- if not vRP.getModState(k) then
- if data.not_working == nil then
- -- only if player isn't in moderation mode and working
- if data.groups["Ambulancier"] then
- -- health
- mediconline = mediconline+1
- end
- end
- end
- end
- end
- end
- if mediconline >= 1 then
- return true
- else
- return false
- end
- end
- --====================================================================================
- -- EVENT
- --====================================================================================
- RegisterServerEvent('illness:removeDisease')
- AddEventHandler('illness:removeDisease', function(name)
- local _source = source
- local _name = name
- local user_id = vRP.getUserId(_source)
- if user_id then
- local data = vRP.getUserDataTable(user_id)
- if data then
- if data.illness[_name] then
- data.illness[_name] = nil
- vRP.setUData(user_id,"vRP:datatable",json.encode(data))
- -- print("ILLNESS REMOVED ".._name)
- end
- end
- end
- end)
- RegisterServerEvent('illness:addDisease')
- AddEventHandler('illness:addDisease', function(name)
- local _source = source
- local _name = name
- local user_id = vRP.getUserId(_source)
- if user_id then
- local data = vRP.getUserDataTable(user_id)
- if data then
- data.illness[_name] = {true}
- vRP.setUData(user_id,"vRP:datatable",json.encode(data))
- -- print("ILLNESS ADDED ".._name)
- end
- end
- end)
- RegisterServerEvent('illness:infectPlayer')
- AddEventHandler('illness:infectPlayer', function(name,target)
- local _source = source
- local _name = name
- local _target = target
- if _target then
- local user_id = vRP.getUserId(_target)
- vRPclient.wearingMedicMask(target,{cfg.medic_mask},function(mask_on)
- -- print("ILLNESS WEARING MASK "..tostring(mask_on))
- if not (vRP.hasGroup(user_id,"Ambulancier") and mask_on) then
- -- medics with a special mask can't be infected !
- local disease = cfg.diseases[_name]
- if disease ~= nil then
- TriggerClientEvent("illness:receiveDisease",_target, disease)
- -- print("ILLNESS INFECTED ".._name)
- end
- end
- end)
- end
- end)
- RegisterServerEvent('illness:getDiseases')
- AddEventHandler('illness:getDiseases', function()
- local _source = source
- local user_id = vRP.getUserId(_source)
- if user_id then
- local data = vRP.getUserDataTable(user_id)
- if data then
- local diseases = {}
- if data.illness == nil then
- -- init illness table
- data.illness = diseases
- vRP.setUData(user_id,"vRP:datatable",json.encode(data))
- -- print("ILLNESS FIRST INIT")
- else
- diseases = data.illness
- end
- TriggerClientEvent("illness:initDiseases",_source, cfg.diseases, diseases)
- -- print("ILLNESS INIT")
- end
- end
- end)
- RegisterServerEvent('illness:setThirsty')
- AddEventHandler('illness:setThirsty', function()
- local _source = source
- local user_id = vRP.getUserId(_source)
- if user_id then
- -- add exact amount ot be at 100 % without dealing damages
- local valueToAdd = 100.0 - vRP.getThirst(user_id)
- vRP.varyThirst(user_id,valueToAdd)
- -- print("ILLNESS THIRST "..valueToAdd)
- end
- end)
- RegisterServerEvent('illness:setHungry')
- AddEventHandler('illness:setHungry', function()
- local _source = source
- local user_id = vRP.getUserId(_source)
- if user_id then
- -- add exact amount ot be at 100 % without dealing damages
- local valueToAdd = 100.0 - vRP.getHunger(user_id)
- vRP.varyHunger(user_id,valueToAdd)
- -- print("ILLNESS HUNGER "..valueToAdd)
- end
- end)
- RegisterServerEvent('illness:removeDiv')
- AddEventHandler('illness:removeDiv', function()
- local _source = source
- if player_symptoms[_source] then
- player_symptoms[_source] = nil
- vRPclient.removeDiv(_source,{"user_symptoms"})
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement