Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- modo = nil
- DataGM = {}
- outputServerLog('saveMJ iniciado')
- addEventHandler('onResourceStart',root,function(recurso)
- if recurso == getThisResource() then
- for _,v in ipairs(getResources()) do
- if v.state == 'running' and v:getInfo('type') == 'gamemode' then
- modo = v.name
- break
- end
- end
- init()
- end
- if recurso:getInfo('type') ~= 'gamemode' then return end
- if recurso.state == 'running' then
- if not DataGM[modo] then
- DataGM[modo] = {}
- end
- SetDataGM(modo)
- modo = recurso.name
- if not DataGM[modo] then
- DataGM[modo] = {}
- end
- SetDataPlayer(modo)
- end
- end)
- function SetDataPlayer(gm)
- for k,player in ipairs (getElementsByType('player')) do
- if DataGM[gm][player] then
- player:setData('mj_victoria',DataGM[gm][player].victorias)
- player:setData('mj_derrotas',DataGM[gm][player].derrotas)
- else
- DataGM[gm][player] = {}
- DataGM[gm][player]['victorias'] = 0
- DataGM[gm][player]['derrotas'] = 0
- player:setData('mj_victoria',0)
- player:setData('mj_derrotas',0)
- end
- end
- end
- function SetDataGM(gm)
- for k,player in ipairs (getElementsByType('player')) do
- if not DataGM[gm][player] then
- DataGM[gm][player] = {}
- end
- DataGM[gm][player]['victorias'] = player:getData('mj_victoria') or 0
- DataGM[gm][player]['derrotas'] = player:getData('mj_derrotas') or 0
- end
- end
- function init()
- local qh = DB.Con:query( "SELECT * FROM statsmj ")
- local result = qh:poll(-1)
- if #result == 0 then
- for k,pj in ipairs(getElementsByType('player')) do
- local id = pj:getData('id_user')
- if id and modo then
- DB.InsertorUpdateStatsMJ(id,pj.name,modo,pj:getData('mj_victoria') or 0,pj:getData('mj_derrotas') or 0)
- end
- end
- else
- local jugadores = getElementsByType('player');
- if #jugadores == 0 then return end
- for k,l in ipairs(result) do
- local minijuego = l.minijuego
- if not DataGM[minijuego] then
- DataGM[minijuego] = {}
- end
- for k,pj in ipairs(jugadores) do
- local id = pj:getData('id_user')
- if id and tostring(id) == tostring(l.user_id) then
- DataGM[minijuego][pj]={}
- local victorias = l.victorias
- local derrotas = l.derrotas
- if modo == minijuego then
- if pj:getData('mj_victoria') and pj:getData('mj_victoria') > (tonumber(victorias) or 0) then
- victorias = pj:getData('mj_victoria')
- end
- if pj:getData('mj_derrotas') and pj:getData('mj_derrotas') > (tonumber(derrotas) or 0) then
- derrotas = pj:getData('mj_derrotas')
- end
- pj:setData('mj_victoria',victorias)
- pj:setData('mj_derrotas',derrotas)
- end
- DataGM[minijuego][pj]['victorias'] = victorias
- DataGM[minijuego][pj]['derrotas'] = derrotas
- end
- end
- end
- end
- end
- function Join()
- if not DataGM[modo] then DataGM[modo] = {} end
- DataGM[modo][source]={}
- DataGM[modo][source]['victorias'] = 0
- DataGM[modo][source]['derrotas'] = 0
- source:setData('mj_victoria',0)
- source:setData('mj_derrotas',0)
- end
- addEventHandler("onPlayerJoin", root, Join)
- function login(_,account)
- local cuenta = getAccountName(account)
- local result = nil
- local qh2 = DB.Con:query("SELECT id FROM dataPlayer where accountname = ?",cuenta)
- result = qh2:poll(-1)
- if #result == 0 then
- DB.RegisterUser(source.name,cuenta)
- local qh = DB.Con:query("SELECT id FROM dataPlayer where accountname = ?",cuenta)
- result = qh:poll(-1)
- end
- for k,l in ipairs(result) do
- source:setData('id_user',l.id)
- break
- end
- local id = source:getData('id_user');
- if not id then return end
- local qh = DB.Con:query("SELECT * FROM statsmj where user_id = "..id)
- local result = qh:poll(-1 )
- if result and #result ~= 0 then
- for k,l in ipairs(result) do
- local minijuego = l.minijuego
- if not DataGM[minijuego] then
- DataGM[minijuego] = {}
- end
- if not DataGM[minijuego][source] then
- DataGM[minijuego][source]={}
- end
- local victorias = l.victorias
- local derrotas = l.derrotas
- DataGM[minijuego][source]['victorias'] = victorias
- DataGM[minijuego][source]['derrotas'] = derrotas
- if modo == minijuego then
- source:setData('mj_victoria',victorias)
- source:setData('mj_derrotas',derrotas)
- end
- end
- end
- end
- addEventHandler('onPlayerLogin',root,login)
- function quitLogout()
- local id = source:getData('id_user');
- if not id then return end
- local victthis = source:getData('mj_victoria') or 0
- local derrthis = source:getData('mj_derrotas') or 0
- local name = source.name
- for k,data in pairs(DataGM) do
- if data[source] then
- local vict = data[source]['victorias'] or 0
- local derrotas = data[source]['derrotas'] or 0
- if tostring(k) == modo then
- vict = victthis
- derrotas = derrthis
- end
- DB.InsertorUpdateStatsMJ(id,name,tostring(k),vict or 0,derrotas or 0)
- end
- end
- outputDebugString('[MJ-System]Guardando datos de: '..name)
- outputServerLog('[MJ-System]Guardando datos de: '..name)
- source:removeData('mj_victoria')
- source:removeData('mj_derrotas')
- source:removeData('id_user')
- end
- addEventHandler('onPlayerQuit',root,quitLogout)
- addEventHandler('onPlayerLogout',root,quitLogout)
- function AgregarData(jugador,tipo)
- if tipo == 'victoria' then
- jugador:setData('mj_victoria', (jugador:getData('mj_victoria') or 0 ) + 1)
- elseif tipo == 'derrota' then
- jugador:setData('mj_derrotas', (jugador:getData('mj_derrotas') or 0 ) + 1)
- end
- end
- addEvent('WinOrLoser',true)
- addEventHandler('WinOrLoser',root,AgregarData)
- --srun getPlayerFromName('Dr.Chapatin'):setData('mj_victoria',10)
- --srun getPlayerFromName('Dr.Chapatin'):getData('mj_derrotas')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement