BonSay~^ Posted August 21, 2015 Share Posted August 21, 2015 Pessoal alguem pode me falar se esses dois codigos que eu axei na net de dar donator para servers race por comando e com tempo pode ser editado para quando digitar o comando de dar donator ir pra acl vip e colocar no painel vip o tempo que o jogador tem de vip Client Side ------------------------------------------------------------------------------------ -- RIGHTS: All rights reserved by developers -- PURPOSE: Donate part client -- DEVELOPERS: Sebbe (Smart) ------------------------------------------------------------------------------------ local sx, sy = guiGetScreenSize() function makeGUI() vipGUI = guiCreateWindow((sx / 2) - (694 / 2), (sy / 2) - (526 / 2), 694, 526, "VIPs", false) guiWindowSetSizable(vipGUI , false) guiSetAlpha(vipGUI , 1.00) guiSetVisible(vipGUI, false) nameEdit = guiCreateEdit(9, 22, 152, 30, "", false, vipGUI) list = guiCreateGridList(9, 61, 670, 408, false, vipGUI) guiSetEnabled(nameEdit, false) guiGridListAddColumn(list, "Account", 0.7) guiGridListAddColumn(list, "Time", 0.1) closeBttn = guiCreateButton(11, 483, 668, 33, "Close This Window", false, vipGUI) addEventHandler("onClientGUIClick", closeBttn, function() guiSetVisible(vipGUI, false) showCursor(false) end, false) end addEventHandler("onClientResourceStart", resourceRoot, makeGUI) function showDonateMembers(d) guiSetVisible(vipGUI, true) showCursor(true) guiGridListClear(list) local online = 0 local online = 0 for ind, data in pairs(d) do online = online + 1 local row = guiGridListAddRow(list) local nTime = data - 1 if (nTime > 1) then data = nTime end guiGridListSetItemText(list, row, 1, tostring(ind), false, false) guiGridListSetItemText(list, row, 2, tostring(data), false, false) end guiSetText(nameEdit, "VIP Online: "..online) end addEvent("donate.showDonateMembers", true) addEventHandler("donate.showDonateMembers", root, showDonateMembers) ServerSide ------------------------------------------------------------------------------------ -- RIGHTS: All rights reserved by developers -- PURPOSE: Donate stuff server -- DEVELOPERS: Sebbe (Smart) ------------------------------------------------------------------------------------ local donate = {} local allTimeDonate = {} local con = dbConnect("sqlite", "db/donate.db") dbExec(con, "CREATE TABLE IF NOT EXISTS donators (account TEXT, time TEXT)") function loadUsers(query) local data = dbPoll(query, 0) if (data) then for ind, d in ipairs(data) do allTimeDonate[d.account] = d.time if (d.account and getAccount(d.account) and getAccountPlayer(getAccount(d.account))) then donate[d.account] = tonumber(d.time) end end end end dbQuery(loadUsers, con, "SELECT * FROM donators") function isPlayerDonator(player) local account = getAccountName(getPlayerAccount(player)) return donate[account] end function addDonatorToDB(player, cmd, account, hours) if (not (hasObjectPermissionTo(player, "function.banPlayer", false))) then return end if (account and hours) then if (not getAccount(account)) then outputChatBox("No account with "..account.." as username", player, 2500, 0, 0) return end if (not tonumber(hours) or tonumber(hours) < 0) then outputChatBox(tostring(hours).." is an invalid hour specific", player, 2500, 0, 0) return end local plr = getAccountPlayer(getAccount(account)) if (not allTimeDonate[getAccount(account)]) then dbExec(con, "INSERT INTO donators (account, time) VALUES (?, ?)", tostring(account), tostring(hours)) donate[account] = tonumber(hours) if (tonumber(hours) == 0) then hours = "infinite" end outputDebugString(getPlayerName(player).. " added "..hours.." VIP hours to "..account) outputChatBox("Added "..hours.." VIP hours to "..account, player, 255, 150, 0) if (plr) then outputChatBox(getPlayerName(player).." added "..hours.." VIP hours to your account ("..account..")", plr, 0, 2500, 0) end end end end addCommandHandler("addvip", addDonatorToDB) function removeOfflineVIP(player, cmd, account) if (not (hasObjectPermissionTo(player, "function.kickPlayer", false))) then return end if (account) then if (not getAccount(account)) then outputChatBox("No account with "..account.." as username", player, 2500, 0, 0) return end if (donate[account]) then donate[account] = nil end if (allTimeDonate[account]) then allTimeDonate[account] = nil end dbExec(con, "DELETE FROM donators WHERE account=?", tostring(account)) outputDebugString(getPlayerName(player).. " removed account "..account.." from database") end end addCommandHandler("removevip", removeOfflineVIP) function makeDonateTick() for ind, d in pairs(donate) do if (ind and getAccount(ind)) then if (getAccountPlayer(getAccount(ind))) then if (donate[ind] and donate[ind] < 1 and donate[ind] ~= 0) then donate[ind] = nil allTimeDonate[ind] = nil dbExec(con, "DELETE FROM donators WHERE account=?", tostring(ind)) outputDebugString("Remove account "..ind.." from database because time ran out", root, 255, 255, 0) elseif (donate[ind] and donate[ind] > 1 and donate[ind] ~= 0) then donate[ind] = donate[ind] - 1 dbExec(con, "UPDATE donators SET time=? WHERE account=?", tostring(donate[ind]), tostring(ind)) outputDebugString("Account "..ind.." VIP Time set to "..donate[ind].." Hours") elseif (donate[ind]) then outputDebugString("Account "..ind.." has infinite VIP hours") end end end end end setTimer(makeDonateTick, 3600000 , 0) function getVipsTable(player) --if (exports.CEDadmin:doesPlayerHaveAccess(player, "viewVipGUI")) then if (not (hasObjectPermissionTo(player, "function.kickPlayer", false))) then return end triggerClientEvent(player, "donate.showDonateMembers", player, allTimeDonate) end addCommandHandler("showvip", getVipsTable) function donaterLoggedIn() dbQuery(loadUsers, con, "SELECT * FROM donators") end addEventHandler("onPlayerLogin", root, donaterLoggedIn) function getMyVIP(plr) if (not isPlayerDonator(plr)) then return end local hours = isPlayerDonator(plr) local minutes = math.floor(hours / 60) if (tonumber(hours) == 0) then hours = "infinite" minutes = "nil" end outputChatBox("You have "..hours.." VIP Hours ("..minutes.." minutes) remaining on this account ("..getAccountName(getPlayerAccount(plr))..")", plr, 0, 2500, 0) end addCommandHandler("viptime", getMyVIP) function setCorrectVIPData() for ind, plr in pairs(getElementsByType("player")) do setElementData(plr, "vipTime", donate[getAccountName(getPlayerAccount(plr))]) end end setTimer(setCorrectVIPData, 1000, 0) Link to comment
DNL291 Posted August 22, 2015 Share Posted August 22, 2015 Use estas funções dentro do comando addvip: aclGroupAddObject -- 'account' (o nome da conta) vai no 2º argumento aclGetGroup("vip") -- O nome é [b]case sensitive[/b] ! O resource deve ter direito para adicionar no grupo da ACL. Para o tempo de VIP, só usar no client: getElementData(player, "vipTime") Isso vai retornar o tempo do VIP, então você só vai usar isso na função showDonateMembers. Link to comment
BonSay~^ Posted August 22, 2015 Author Share Posted August 22, 2015 Use estas funções dentro do comando addvip: aclGroupAddObject -- 'account' (o nome da conta) vai no 2º argumento aclGetGroup("vip") -- O nome é [b]case sensitive[/b] ! O resource deve ter direito para adicionar no grupo da ACL. Para o tempo de VIP, só usar no client: getElementData(player, "vipTime") Isso vai retornar o tempo do VIP, então você só vai usar isso na função showDonateMembers. Por que nao esta pegando function addDonatorToDB(player, cmd, account, hours) if (not (hasObjectPermissionTo(player, "function.banPlayer", false))) then return end if (account and hours) then if (not getAccount(account)) then outputChatBox("No account with "..account.." as username", player, 2500, 0, 0) return end if accountName then aclGroupAddObject (aclGetGroup("VIP"), "user."..accountName) end if (not tonumber(hours) or tonumber(hours) < 0) then outputChatBox(tostring(hours).." is an invalid hour specific", player, 2500, 0, 0) return end local plr = getAccountPlayer(getAccount(account)) if (not allTimeDonate[getAccount(account)]) then dbExec(con, "INSERT INTO donators (account, time) VALUES (?, ?)", tostring(account), tostring(hours)) donate[account] = tonumber(hours) if (tonumber(hours) == 0) then hours = "infinite" end outputDebugString(getPlayerName(player).. " added "..hours.." VIP hours to "..account) outputChatBox("Added "..hours.." VIP hours to "..account, player, 255, 150, 0) if (plr) then outputChatBox(getPlayerName(player).." added "..hours.." VIP hours to your account ("..account..")", plr, 0, 2500, 0) end end end end addCommandHandler("addvip", addDonatorToDB) Link to comment
DNL291 Posted August 22, 2015 Share Posted August 22, 2015 'accountName' não está definido, 'account' já retorna o nome da conta. Link to comment
BonSay~^ Posted August 23, 2015 Author Share Posted August 23, 2015 'accountName' não está definido, 'account' já retorna o nome da conta. Ta eu consegui que adicione e remova o vip com o comando mas nao sei se o tempo de vip quando acabar vai sair da acl sozinho e eu queria colocar o tempo de vip em um painel vip que eu to fazendo pode me ajudar aqui esta o codigo editado ------------------------------------------------------------------------------------ -- RIGHTS: All rights reserved by developers -- PURPOSE: Donate stuff server -- DEVELOPERS: Sebbe (Smart) ------------------------------------------------------------------------------------ local donate = {} local allTimeDonate = {} local con = dbConnect("sqlite", "db/donate.db") dbExec(con, "CREATE TABLE IF NOT EXISTS donators (account TEXT, time TEXT)") function loadUsers(query) local data = dbPoll(query, 0) if (data) then for ind, d in ipairs(data) do allTimeDonate[d.account] = d.time if (d.account and getAccount(d.account) and getAccountPlayer(getAccount(d.account))) then donate[d.account] = tonumber(d.time) end end end end dbQuery(loadUsers, con, "SELECT * FROM donators") function isPlayerDonator(player) local account = getAccountName(getPlayerAccount(player)) return donate[account] end function addDonatorToDB(player, cmd, account, hours) if (not (hasObjectPermissionTo(player, "function.banPlayer", false))) then return end if account then local account = aclGroupAddObject (aclGetGroup("VIP"), "user."..account) end if (account and hours) then if (not getAccount(account)) then outputChatBox("No account with "..account.." as username", player, 2500, 0, 0) return end if (not tonumber(hours) or tonumber(hours) < 0) then outputChatBox(tostring(hours).." is an invalid hour specific", player, 2500, 0, 0) return end local plr = getAccountPlayer(getAccount(account)) if (not allTimeDonate[getAccount(account)]) then dbExec(con, "INSERT INTO donators (account, time) VALUES (?, ?)", tostring(account), tostring(hours)) donate[account] = tonumber(hours) if (tonumber(hours) == 0) then hours = "infinite" end outputDebugString(getPlayerName(player).. " added "..hours.." VIP hours to "..account) outputChatBox("Added "..hours.." VIP hours to "..account, player, 255, 150, 0) if (plr) then outputChatBox(getPlayerName(player).." added "..hours.." VIP hours to your account ("..account..")", plr, 0, 2500, 0) end end end end addCommandHandler("addvip", addDonatorToDB) function removeOfflineVIP(player, cmd, account) if (not (hasObjectPermissionTo(player, "function.kickPlayer", false))) then return end if account then aclGroupRemoveObject (aclGetGroup("VIP"), "user."..account) end if (account) then if (not getAccount(account)) then outputChatBox("No account with "..account.." as username", player, 2500, 0, 0) return end if (donate[account]) then donate[account] = nil end if (allTimeDonate[account]) then allTimeDonate[account] = nil end dbExec(con, "DELETE FROM donators WHERE account=?", tostring(account)) outputDebugString(getPlayerName(player).. " removed account "..account.." from database") end end addCommandHandler("removevip", removeOfflineVIP) function makeDonateTick() for ind, d in pairs(donate) do if (ind and getAccount(ind)) then if (getAccountPlayer(getAccount(ind))) then if (donate[ind] and donate[ind] < 1 and donate[ind] ~= 0) then donate[ind] = nil allTimeDonate[ind] = nil dbExec(con, "DELETE FROM donators WHERE account=?", tostring(ind)) outputDebugString("Remove account "..ind.." from database because time ran out", root, 255, 255, 0) elseif (donate[ind] and donate[ind] > 1 and donate[ind] ~= 0) then donate[ind] = donate[ind] - 1 dbExec(con, "UPDATE donators SET time=? WHERE account=?", tostring(donate[ind]), tostring(ind)) outputDebugString("Account "..ind.." VIP Time set to "..donate[ind].." Hours") elseif (donate[ind]) then outputDebugString("Account "..ind.." has infinite VIP hours") end end end end end setTimer(makeDonateTick, 3600000 , 0) function getVipsTable(player) --if (exports.CEDadmin:doesPlayerHaveAccess(player, "viewVipGUI")) then if (not (hasObjectPermissionTo(player, "function.kickPlayer", false))) then return end triggerClientEvent(player, "donate.showDonateMembers", player, allTimeDonate) end addCommandHandler("showvip", getVipsTable) function donaterLoggedIn() dbQuery(loadUsers, con, "SELECT * FROM donators") end addEventHandler("onPlayerLogin", root, donaterLoggedIn) function getMyVIP(plr) if (not isPlayerDonator(plr)) then return end local hours = isPlayerDonator(plr) local minutes = math.floor(hours / 60) if (tonumber(hours) == 0) then hours = "infinite" minutes = "nil" end outputChatBox("You have "..hours.." VIP Hours ("..minutes.." minutes) remaining on this account ("..getAccountName(getPlayerAccount(plr))..")", plr, 0, 2500, 0) end addCommandHandler("viptime", getMyVIP) function setCorrectVIPData() for ind, plr in pairs(getElementsByType("player")) do setElementData(plr, "vipTime", donate[getAccountName(getPlayerAccount(plr))]) end end setTimer(setCorrectVIPData, 1000, 0) Link to comment
DNL291 Posted August 25, 2015 Share Posted August 25, 2015 Sobre a adição ao grupo VIP, só remova a variável 'account' que vai guardar o retorno da função aclGroupAddObject (e causar problemas) nesta linha: local account = aclGroupAddObject (aclGetGroup("VIP"), "user."..account) Para remover do grupo quando o tempo de VIP acabar, use aclGroupRemoveObject na função makeDonateTick, vai funcionar da mesma forma que você fez na função removeOfflineVIP. No if statement na linha 91, só usar isso dentro do bloco: aclGroupRemoveObject (aclGetGroup("VIP"), "user."..ind) Já sobre o tempo de VIP no painel, você poderia ter deixado o seu código do painel aqui e eu explicaria onde usar getElementData - que já expliquei anteriormente. Link to comment
BonSay~^ Posted August 27, 2015 Author Share Posted August 27, 2015 Sobre a adição ao grupo VIP, só remova a variável 'account' que vai guardar o retorno da função aclGroupAddObject (e causar problemas) nesta linha: local account = aclGroupAddObject (aclGetGroup("VIP"), "user."..account) Para remover do grupo quando o tempo de VIP acabar, use aclGroupRemoveObject na função makeDonateTick, vai funcionar da mesma forma que você fez na função removeOfflineVIP. No if statement na linha 91, só usar isso dentro do bloco: aclGroupRemoveObject (aclGetGroup("VIP"), "user."..ind) Já sobre o tempo de VIP no painel, você poderia ter deixado o seu código do painel aqui e eu explicaria onde usar getElementData - que já expliquei anteriormente. Hmmm mas uma coisa como faço no lugar de horas colocar dias horas minutos e segundos ? ------------------------------------------------------------------------------------ -- RIGHTS: All rights reserved by developers -- PURPOSE: Donate stuff server -- DEVELOPERS: Sebbe (Smart) ------------------------------------------------------------------------------------ local donate = {} local allTimeDonate = {} local con = dbConnect("sqlite", "db/donate.db") dbExec(con, "CREATE TABLE IF NOT EXISTS donators (account TEXT, time TEXT)") function loadUsers(query) local data = dbPoll(query, 0) if (data) then for ind, d in ipairs(data) do allTimeDonate[d.account] = d.time if (d.account and getAccount(d.account) and getAccountPlayer(getAccount(d.account))) then donate[d.account] = tonumber(d.time) end end end end dbQuery(loadUsers, con, "SELECT * FROM donators") function isPlayerDonator(player) local account = getAccountName(getPlayerAccount(player)) return donate[account] end function addDonatorToDB(player, cmd, account, hours) if (not (hasObjectPermissionTo(player, "function.banPlayer", false))) then return end if account then local account = aclGroupAddObject (aclGetGroup("VIP"), "user."..account) end if (account and hours) then if (not getAccount(account)) then outputChatBox("#000000[#FFD700 V.I.P#000000 ] #FFFFFFNao existe nenhuma conta chamada #FF4500"..account.." #000000.", player, 255, 255, 255, true) return end if (not tonumber(hours) or tonumber(hours) < 0) then outputChatBox(tostring(hours).." is an invalid hour specific", player, 2500, 0, 0) return end local plr = getAccountPlayer(getAccount(account)) if (not allTimeDonate[getAccount(account)]) then dbExec(con, "INSERT INTO donators (account, time) VALUES (?, ?)", tostring(account), tostring(hours)) donate[account] = tonumber(hours) if (tonumber(hours) == 0) then hours = "infinite" end outputDebugString(getPlayerName(player).. " Adicionou "..hours.." Horas V.I.P na conta "..account) outputChatBox("#000000[#FFD700 V.I.P#000000 ]#FFFFFF Adicionado "..hours.." Horas #FFD700 V.I.P#FFFFFF na conta "..account, player, 255, 255, 255, true) if (plr) then outputChatBox("#000000[#FFD700 V.I.P#000000 ]#FFFFFF Foi adicionado "..hours.." Horas #FFD700 V.I.P em sua #FF0000CONTA", plr, 255, 255, 255, true) end end end end addCommandHandler("addvip", addDonatorToDB) function removeOfflineVIP(player, cmd, account) if (not (hasObjectPermissionTo(player, "function.kickPlayer", false))) then return end if account then aclGroupRemoveObject (aclGetGroup("VIP"), "user."..account) end if (account) then if (not getAccount(account)) then outputChatBox("No account with "..account.." as username", player, 2500, 0, 0) return end if (donate[account]) then donate[account] = nil end if (allTimeDonate[account]) then allTimeDonate[account] = nil end dbExec(con, "DELETE FROM donators WHERE account=?", tostring(account)) outputDebugString(getPlayerName(player).. " removed account "..account.." from database") end end addCommandHandler("removevip", removeOfflineVIP) function makeDonateTick() for ind, d in pairs(donate) do if (ind and getAccount(ind)) then if (getAccountPlayer(getAccount(ind))) then if (donate[ind] and donate[ind] < 1 and donate[ind] ~= 0) then aclGroupRemoveObject (aclGetGroup("VIP"), "user."..ind) donate[ind] = nil allTimeDonate[ind] = nil dbExec(con, "DELETE FROM donators WHERE account=?", tostring(ind)) outputDebugString("Remove account "..ind.." from database because time ran out", root, 255, 255, 0) elseif (donate[ind] and donate[ind] > 1 and donate[ind] ~= 0) then donate[ind] = donate[ind] - 1 dbExec(con, "UPDATE donators SET time=? WHERE account=?", tostring(donate[ind]), tostring(ind)) outputDebugString("Account "..ind.." VIP Time set to "..donate[ind].." Hours") elseif (donate[ind]) then outputDebugString("Account "..ind.." has infinite VIP hours") end end end end end setTimer(makeDonateTick, 3600000 , 0) function getVipsTable(player) --if (exports.CEDadmin:doesPlayerHaveAccess(player, "viewVipGUI")) then if (not (hasObjectPermissionTo(player, "function.kickPlayer", false))) then return end triggerClientEvent(player, "donate.showDonateMembers", player, allTimeDonate) end addCommandHandler("showvip", getVipsTable) function donaterLoggedIn() dbQuery(loadUsers, con, "SELECT * FROM donators") end addEventHandler("onPlayerLogin", root, donaterLoggedIn) function getMyVIP(plr) if (not isPlayerDonator(plr)) then return end local hours = isPlayerDonator(plr) local minutes = math.floor(hours / 60) if (tonumber(hours) == 0) then hours = "infinite" minutes = "nil" end outputChatBox("#000000[#FFD700 V.I.P#000000 ]#FFFFFF Voce tem #FF0000"..hours.." #FFFFFFHoras e #FF0000"..minutes.."#FFFFFF Minutos de #FFD700 V.I.P#FFFFFF em sua conta", plr, 255, 255, 255, true) end addCommandHandler("viptime", getMyVIP) function setCorrectVIPData() for ind, plr in pairs(getElementsByType("player")) do setElementData(plr, "vipTime", donate[getAccountName(getPlayerAccount(plr))]) end end setTimer(setCorrectVIPData, 1000, 0) Link to comment
DNL291 Posted August 28, 2015 Share Posted August 28, 2015 Use a função secondsToTimeDesc Já que está retorna horas, você pode converter em segundos assim: local hours = isPlayerDonator(plr) secondsToTimeDesc(( hours * 60 ) * 60) Link to comment
BonSay~^ Posted August 28, 2015 Author Share Posted August 28, 2015 Use a função secondsToTimeDescJá que está retorna horas, você pode converter em segundos assim: local hours = isPlayerDonator(plr) secondsToTimeDesc(( hours * 60 ) * 60) function getMyVIP(seconds) if seconds then local sec = ( seconds %60 ) local minutes = math.floor ( ( seconds % 3600 ) /60 ) local hours = math.floor ( ( seconds % 86400 ) /3600 ) local days = math.floor ( seconds /86400 ) end if (tonumber(hours) == 0) then hours = "infinite" minutes = "nil" end outputChatBox("Voce tem '..days..' dias, '..hours..' horas , '..minutes..' minutos , '..sec..' segundos de vip", seconds, 255, 255, 255, true) end addCommandHandler("viptime", getMyVIP) consegui nao Link to comment
DNL291 Posted August 29, 2015 Share Posted August 29, 2015 Tente isto aqui: function getMyVIP( player ) if isPlayerDonator(player) then local hours = isPlayerDonator(player) if (tonumber(hours) == 0) then -- VIP sem tempo pra acabar return outputChatBox("O seu vip tem duração eterna.", player, 255, 255, 255, true) end local vipSecs = ( isPlayerDonator(player) * 60 ) * 60 local sec = ( vipSecs %60 ) local minutes = math.floor ( ( vipSecs % 3600 ) /60 ) local hours = math.floor ( ( vipSecs % 86400 ) /3600 ) local days = math.floor ( vipSecs /86400 ) outputChatBox("Voce tem "..tostring(days).." dias, "..tostring(hours).." horas, "..tostring(minutes).." minutos, "..tostring(sec).." segundos de vip", player, 255, 255, 255, true) end end addCommandHandler("viptime", getMyVIP) Link to comment
BonSay~^ Posted August 29, 2015 Author Share Posted August 29, 2015 Tente isto aqui: function getMyVIP( player ) if isPlayerDonator(player) then local hours = isPlayerDonator(player) if (tonumber(hours) == 0) then -- VIP sem tempo pra acabar return outputChatBox("O seu vip tem duração eterna.", player, 255, 255, 255, true) end local vipSecs = ( isPlayerDonator(player) * 60 ) * 60 local sec = ( vipSecs %60 ) local minutes = math.floor ( ( vipSecs % 3600 ) /60 ) local hours = math.floor ( ( vipSecs % 86400 ) /3600 ) local days = math.floor ( vipSecs /86400 ) outputChatBox("Voce tem "..tostring(days).." dias, "..tostring(hours).." horas, "..tostring(minutes).." minutos, "..tostring(sec).." segundos de vip", player, 255, 255, 255, true) end end addCommandHandler("viptime", getMyVIP) Ta nao teve bug mas nao ta decrescendo o tempo so o dia fica 0 os minutos fica 0 eos segundos fica 0 o unico que fica eas horas Link to comment
DNL291 Posted August 31, 2015 Share Posted August 31, 2015 Tente isto novamente: function getMyVIP( player ) if isPlayerDonator(player) then if (tonumber(isPlayerDonator(player)) == 0) then -- VIP sem tempo pra acabar return outputChatBox("O seu vip tem duração eterna.", player, 255, 255, 255, true) end local vipSecs = isPlayerDonator(player) * 3600 local sec = math.floor( vipSecs %60 ) local minutes = math.floor( (vipSecs % 3600) /60 ) local hours = math.floor( (vipSecs / 3600) % 24 ) local days = math.floor( vipSecs / 86400 ) outputChatBox("Voce tem "..tostring(days).." dias, "..tostring(hours).." horas, "..tostring(minutes).." minutos, "..tostring(sec).." segundos de vip", player, 255, 255, 255, true) end end addCommandHandler("viptime", getMyVIP) Link to comment
BonSay~^ Posted August 31, 2015 Author Share Posted August 31, 2015 Tente isto novamente: function getMyVIP( player ) if isPlayerDonator(player) then if (tonumber(isPlayerDonator(player)) == 0) then -- VIP sem tempo pra acabar return outputChatBox("O seu vip tem duração eterna.", player, 255, 255, 255, true) end local vipSecs = isPlayerDonator(player) * 3600 local sec = math.floor( vipSecs %60 ) local minutes = math.floor( (vipSecs % 3600) /60 ) local hours = math.floor( (vipSecs / 3600) % 24 ) local days = math.floor( vipSecs / 86400 ) outputChatBox("Voce tem "..tostring(days).." dias, "..tostring(hours).." horas, "..tostring(minutes).." minutos, "..tostring(sec).." segundos de vip", player, 255, 255, 255, true) end end addCommandHandler("viptime", getMyVIP) Esta funfando normal e so colocar por exemplo 224.45 que vai os segundos e minutos mas nao esta decrescendo Link to comment
DNL291 Posted September 1, 2015 Share Posted September 1, 2015 Você quer dizer que só quando usa um número com decimal que não decresce o tempo? Se for isso então tente usando math.floor em isPlayerDonator(player). Link to comment
BonSay~^ Posted September 2, 2015 Author Share Posted September 2, 2015 Você quer dizer que só quando usa um número com decimal que não decresce o tempo?Se for isso então tente usando math.floor em isPlayerDonator(player). Nao qualquer tempo de vip que eu colocar na minha conta nao decresce o tempo e nao quer expirar o tempo de vip depois que passa o tempo que eu coloquei nao expira ele fica pra sempre Talvez o codigo inteiro lhe ajude a axar o erro ------------------------------------------------------------------------------------ -- RIGHTS: All rights reserved by developers -- PURPOSE: Donate stuff server -- DEVELOPERS: Sebbe (Smart) ------------------------------------------------------------------------------------ local donate = {} local allTimeDonate = {} local con = dbConnect("sqlite", "db/donate.db") dbExec(con, "CREATE TABLE IF NOT EXISTS donators (account TEXT, time TEXT)") function loadUsers(query) local data = dbPoll(query, 0) if (data) then for ind, d in ipairs(data) do allTimeDonate[d.account] = d.time if (d.account and getAccount(d.account) and getAccountPlayer(getAccount(d.account))) then donate[d.account] = tonumber(d.time) end end end end dbQuery(loadUsers, con, "SELECT * FROM donators") function isPlayerDonator(player) local account = getAccountName(getPlayerAccount(player)) return donate[account] end function addDonatorToDB(player, cmd, account, hours) if (not (hasObjectPermissionTo(player, "function.banPlayer", false))) then return end if account then local account = aclGroupAddObject (aclGetGroup("VIP"), "user."..account) end if (account and hours) then if (not getAccount(account)) then outputChatBox("#000000[#FFD700 V.I.P#000000 ] #FFFFFFNao existe nenhuma conta chamada #FF4500"..account.." #000000.", player, 255, 255, 255, true) return end if (not tonumber(hours) or tonumber(hours) < 0) then outputChatBox(tostring(hours).." is an invalid hour specific", player, 2500, 0, 0) return end local plr = getAccountPlayer(getAccount(account)) if (not allTimeDonate[getAccount(account)]) then dbExec(con, "INSERT INTO donators (account, time) VALUES (?, ?)", tostring(account), tostring(hours)) donate[account] = tonumber(hours) if (tonumber(hours) == 0) then hours = "infinite" end outputDebugString(getPlayerName(player).. " Adicionou "..hours.." Horas V.I.P na conta "..account) outputChatBox("#000000[#FFD700 V.I.P#000000 ]#FFFFFF Adicionado "..hours.." Horas #FFD700 V.I.P#FFFFFF na conta "..account, player, 255, 255, 255, true) if (plr) then outputChatBox("#000000[#FFD700 V.I.P#000000 ]#FFFFFF Foi adicionado "..hours.." Horas #FFD700 V.I.P em sua #FF0000CONTA", plr, 255, 255, 255, true) end end end end addCommandHandler("addvip", addDonatorToDB) function removeOfflineVIP(player, cmd, account) if (not (hasObjectPermissionTo(player, "function.kickPlayer", false))) then return end if account then aclGroupRemoveObject (aclGetGroup("VIP"), "user."..account) end if (account) then if (not getAccount(account)) then outputChatBox("No account with "..account.." as username", player, 2500, 0, 0) return end if (donate[account]) then donate[account] = nil end if (allTimeDonate[account]) then allTimeDonate[account] = nil end dbExec(con, "DELETE FROM donators WHERE account=?", tostring(account)) outputDebugString(getPlayerName(player).. " removed account "..account.." from database") end end addCommandHandler("removevip", removeOfflineVIP) function makeDonateTick() for ind, d in pairs(donate) do if (ind and getAccount(ind)) then if (getAccountPlayer(getAccount(ind))) then if (donate[ind] and donate[ind] < 1 and donate[ind] ~= 0) then aclGroupRemoveObject (aclGetGroup("VIP"), "user."..ind) donate[ind] = nil allTimeDonate[ind] = nil dbExec(con, "DELETE FROM donators WHERE account=?", tostring(ind)) outputDebugString("Remove account "..ind.." from database because time ran out", root, 255, 255, 0) elseif (donate[ind] and donate[ind] > 1 and donate[ind] ~= 0) then donate[ind] = donate[ind] - 1 dbExec(con, "UPDATE donators SET time=? WHERE account=?", tostring(donate[ind]), tostring(ind)) outputDebugString("Account "..ind.." VIP Time set to "..donate[ind].." Hours") elseif (donate[ind]) then outputDebugString("Account "..ind.." has infinite VIP hours") end end end end end setTimer(makeDonateTick, 3600000 , 0) function getVipsTable(player) --if (exports.CEDadmin:doesPlayerHaveAccess(player, "viewVipGUI")) then if (not (hasObjectPermissionTo(player, "function.kickPlayer", false))) then return end triggerClientEvent(player, "donate.showDonateMembers", player, allTimeDonate) end addCommandHandler("showvip", getVipsTable) function donaterLoggedIn() dbQuery(loadUsers, con, "SELECT * FROM donators") end addEventHandler("onPlayerLogin", root, donaterLoggedIn) function getMyVIP( player ) if isPlayerDonator(player) then if (tonumber(isPlayerDonator(player)) == 0) then -- VIP sem tempo pra acabar return outputChatBox("O seu vip tem duração eterna.", player, 255, 255, 255, true) end local vipSecs = isPlayerDonator(player) * 3600 local sec = math.floor( vipSecs %60 ) local minutes = math.floor( (vipSecs % 3600) /60 ) local hours = math.floor( (vipSecs / 3600) % 24 ) local days = math.floor( vipSecs / 86400 ) outputChatBox("Voce tem "..tostring(days).." dias, "..tostring(hours).." horas, "..tostring(minutes).." minutos, "..tostring(sec).." segundos de vip", player, 255, 255, 255, true) end end addCommandHandler("viptime", getMyVIP) function setCorrectVIPData() for ind, plr in pairs(getElementsByType("player")) do setElementData(plr, "vipTime", donate[getAccountName(getPlayerAccount(plr))]) end end setTimer(setCorrectVIPData, 1000, 0) Link to comment
DNL291 Posted September 4, 2015 Share Posted September 4, 2015 Acho melhor você usar outro método para o tempo de VIP, notei que o tempo de todos os VIPs só é atualizado a cada 1 hora. A melhor alternativa seria realmente substituir pelo uso de Time Stamp. Já sobre problema do tempo não expirar, não sei te dizer o que é. makeDonateTick parece estar funcionando sem erros pra mim. Se você quiser, pode usar outputChatBox pra mostrar certos valores como o que retorna na função isPlayerDonator. Link to comment
BonSay~^ Posted September 4, 2015 Author Share Posted September 4, 2015 Acho melhor você usar outro método para o tempo de VIP, notei que o tempo de todos os VIPs só é atualizado a cada 1 hora.A melhor alternativa seria realmente substituir pelo uso de Time Stamp. Já sobre problema do tempo não expirar, não sei te dizer o que é. makeDonateTick parece estar funcionando sem erros pra mim. Se você quiser, pode usar outputChatBox pra mostrar certos valores como o que retorna na função isPlayerDonator. E como posso usar o timestamp Link to comment
BonSay~^ Posted September 5, 2015 Author Share Posted September 5, 2015 Acho melhor você usar outro método para o tempo de VIP, notei que o tempo de todos os VIPs só é atualizado a cada 1 hora.A melhor alternativa seria realmente substituir pelo uso de Time Stamp. Já sobre problema do tempo não expirar, não sei te dizer o que é. makeDonateTick parece estar funcionando sem erros pra mim. Se você quiser, pode usar outputChatBox pra mostrar certos valores como o que retorna na função isPlayerDonator. Axo que o problema de nao descrescer e por que na parte do codigo que expira o vip so pra decrescer as horas e nao os minutos dias segundos e por isso que nao quer contar testei tirar 3600000 que e 1 dia e colocar 1000 que e 1 segundo e começou a tirar 1 hora de vip a cada 1 segundo so nao sei como colocar pra descrescer os segundos dias minutos Link to comment
DNL291 Posted September 6, 2015 Share Posted September 6, 2015 É por isso que te sugeri usar Timestamp, seria melhor e retornaria até os segundos do VIP enquanto esse método atual é incapaz. Sobre a sua pergunta de como usar: Tem um tutorial abordando o uso na categoria 'Tutoriais em geral'. Pra reescrever o seu código usando Timestamp é o seguinte, na função que dá o VIP, você pega as horas de VIP - me refiro ao argumento do comando - converte as horas para segundos [horas * 3600] e grava no banco de dados o tempo de VIP somado com o Timestamp do momento que a função foi chamada. Lembre-se: obedecendo o funcionamento do código, quando for 0, então será eterno. Então vai 0 em vez de somar os segundos. Na função makeDonateTick vai decrescer 3600 do tempo em vez de 1 - faça isso no if statement na parte que atualiza o tempo de VIP. Quando abaixar o tempo, já verifica se ainda é maior ou igual a zero, até porque o VIP já pode ter expirado. @EDIT Corrigindo, quando o valor do tempo for subtraído você pega o Timestamp atual e também o do momento em que o VIP foi concedido. Comparam esses valores verificando se: o tempo armazenado na tabela é menor (ou igual) ao do tempo em que foi dado o VIP. Então vai uma outra coisa, quando armazenar o tempo no banco de dados, grava também o Timestamp (da data que o VIP foi dado) para verificar a data do VIP. Link to comment
Peketo Posted October 15, 2016 Share Posted October 15, 2016 Estou tentando fazer o mesmo, só que eu não entendi muito isso do TimeStamp.. Link to comment
FelipeMallmann Posted October 18, 2016 Share Posted October 18, 2016 Veja se isso te ajuda: Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now