opnaiC Posted July 6, 2016 Share Posted July 6, 2016 Server sided script: function experience () for i, pPlayer in ipairs( getElementsByType( "player" ) ) do local pAccount = getPlayerAccount( pPlayer ) local exp = getAccountData(pAccount, "exp") local exps = tonumber(getAccountData(pAccount, "exp")) local lvls = tonumber(getAccountData(pAccount, "lvl")) local needexp = lvls * 4 if not exp then setAccountData(pAccount, "exp", 1) setAccountData(pAccount, "allexp", 1) setAccountData(pAccount, "lvl", 1) outputChatBox("Ваш опыт: " .. exps .. "/" .. needexp, getRootElement(), 0, 255, 0) else setAccountData(pAccount, "exp", exps + 1) if exps == needexp then setAccountData(pAccount, "lvl", lvls + 1) setAccountData(pAccount, "exp", 1) outputChatBox("Ваш уровень повышен до " .. lvls + 1 .. "!", getRootElement(), 0, 255, 0) else end end end end setTimer(experience, 3600000, 0) function nilexp (thePlayer) setAccountData(getPlayerAccount(thePlayer), "exp", 1) setAccountData(getPlayerAccount(thePlayer), "lvl", 1) end addCommandHandler("nilexp", nilexp) function command (thePlayer) outputChatBox("Ваш опыт: " .. exps .. "/" .. needexp ".", thePlayer, 0, 255, 0) outputChatBox("Ваш уровень: " .. lvls .. ".", thePlayer, 0, 255, 0) end addCommandHandler("level", command) Any idea why this system isnt working correctly ? Link to comment
Walid Posted July 6, 2016 Share Posted July 6, 2016 Try this one function experience () for i, pPlayer in ipairs( getElementsByType( "player" ) ) do local pAccount = getPlayerAccount( pPlayer ) if pAccount and not isGuestAccount(pAccount) then local exps = getAccountData(pAccount, "exp") or 0 local lvls = getAccountData(pAccount, "lvl") or 0 local needexp = lvls * 4 if exps ~= 0 then setAccountData(pAccount, "exp", tonumber(exps) + 1) if exps == needexp then setAccountData(pAccount, "lvl", tonumber(lvls) + 1) setAccountData(pAccount, "exp", 1) outputChatBox("Ваш уровень повышен до " .. lvls + 1 .. "!",pPlayer, 0, 255, 0) end else setAccountData(pAccount, "exp", 1) setAccountData(pAccount, "allexp", 1) setAccountData(pAccount, "lvl", 1) outputChatBox("Ваш опыт: " ..tonumber(exps).. "/" ..tonumber(needexp),pPlayer, 0, 255, 0) end end end end setTimer(experience, 3600000, 0) function nilexp (thePlayer) local account = getPlayerAccount(thePlayer) if account and not isGuestAccount(account) then setAccountData(account, "exp", 1) setAccountData(account, "lvl", 1) end end addCommandHandler("nilexp", nilexp) function command (thePlayer) local account = getPlayerAccount(thePlayer) if account and not isGuestAccount(account) then local exps = getAccountData(account, "exp") or 0 local lvls = getAccountData(account, "lvl") or 0 local needexp = lvls * 4 outputChatBox("Ваш опыт: " ..tonumber(exps).. "/" ..tonumber(needexp)..".", thePlayer, 0, 255, 0) outputChatBox("Ваш уровень: " ..tonumber(lvls).. ".", thePlayer, 0, 255, 0) end end addCommandHandler("level", command) Link to comment
opnaiC Posted July 7, 2016 Author Share Posted July 7, 2016 Try this one function experience () for i, pPlayer in ipairs( getElementsByType( "player" ) ) do local pAccount = getPlayerAccount( pPlayer ) if pAccount and not isGuestAccount(pAccount) then local exps = getAccountData(pAccount, "exp") or 0 local lvls = getAccountData(pAccount, "lvl") or 0 local needexp = lvls * 4 if exps ~= 0 then setAccountData(pAccount, "exp", tonumber(exps) + 1) if exps == needexp then setAccountData(pAccount, "lvl", tonumber(lvls) + 1) setAccountData(pAccount, "exp", 1) outputChatBox("Ваш уровень повышен до " .. lvls + 1 .. "!",pPlayer, 0, 255, 0) end else setAccountData(pAccount, "exp", 1) setAccountData(pAccount, "allexp", 1) setAccountData(pAccount, "lvl", 1) outputChatBox("Ваш опыт: " ..tonumber(exps).. "/" ..tonumber(needexp),pPlayer, 0, 255, 0) end end end end setTimer(experience, 3600000, 0) function nilexp (thePlayer) local account = getPlayerAccount(thePlayer) if account and not isGuestAccount(account) then setAccountData(account, "exp", 1) setAccountData(account, "lvl", 1) end end addCommandHandler("nilexp", nilexp) function command (thePlayer) local account = getPlayerAccount(thePlayer) if account and not isGuestAccount(account) then local exps = getAccountData(account, "exp") or 0 local lvls = getAccountData(account, "lvl") or 0 local needexp = lvls * 4 outputChatBox("Ваш опыт: " ..tonumber(exps).. "/" ..tonumber(needexp)..".", thePlayer, 0, 255, 0) outputChatBox("Ваш уровень: " ..tonumber(lvls).. ".", thePlayer, 0, 255, 0) end end addCommandHandler("level", command) Thank you! I have a second question. Do you know how I can add this server sided data to a client sided guiGridlist ? I made my own TAB Panel with Player name and Ping. Its working perfectly but I need also the level to be displayed in the gridlist.. Link to comment
opnaiC Posted July 7, 2016 Author Share Posted July 7, 2016 triggerClientEvent() This is what I mean: function getLevel (thePlayer, lvls) local account = getPlayerAccount(thePlayer) local lvls = getAccountData(account, "lvl") or 0 end addEvent ("level", true) addEventHandler("level", root, getLevel) guiGridListSetItemText(gridlist, row, 2, triggerServerEvent ("level", root), false, false) Only a part of the panel script Link to comment
Walid Posted July 7, 2016 Share Posted July 7, 2016 -- Server side function getLevel (thePlayer) local account = getPlayerAccount(thePlayer) if account and not isGuestAccount(account) then local playerName = getPlayerName(thePlayer) local lvls = getAccountData(account, "lvl") or 0 local ping = getPlayerPing (thePlayer) -- etc ... -- then triggerClientevent triggerClientEvent(thePlayer,"eventName",thePlayer,playerName,lvls,ping) end end addCommandHandler("tab",getLevel) -- Client side function pg (playerName,lvls,ping) local account = getPlayerAccount(thePlayer) local lvls = getAccountData(account, "lvl") or 0 -- etc end addEvent ("eventName", true) addEventHandler("eventName", root, pg ) Link to comment
opnaiC Posted July 7, 2016 Author Share Posted July 7, 2016 -- Server side function getLevel (thePlayer) local account = getPlayerAccount(thePlayer) if account and not isGuestAccount(account) then local playerName = getPlayerName(thePlayer) local lvls = getAccountData(account, "lvl") or 0 local ping = getPlayerPing (thePlayer) -- etc ... -- then triggerClientevent triggerClientEvent(thePlayer,"eventName",thePlayer,playerName,lvls,ping) end end addCommandHandler("tab",getLevel) -- Client side function pg (playerName,lvls,ping) local account = getPlayerAccount(thePlayer) local lvls = getAccountData(account, "lvl") or 0 -- etc end addEvent ("eventName", true) addEventHandler("eventName", root, pg ) I think you dont understand what I want. Look this is my tab panel: local sx,sy = guiGetScreenSize() local px,py = 1600,900 local x,y = (sx/px), (sy/py) window = guiCreateWindow(x*430, y*170, x*739, y*379, "", false) guiWindowSetSizable(window, false) guiWindowSetMovable(window, false) guiSetVisible(window, false) gridlist = guiCreateGridList(x*9, y*24, x*720, y*345, false, window) guiGridListAddColumn(gridlist, "Имя Фамилия", 0.3) guiGridListAddColumn(gridlist, "Уровень", 0.3) guiGridListAddColumn(gridlist, "Пинг", 0.3) scrollbar = guiCreateScrollBar(x*681, y*19, x*15, y*310, false, false, gridlist) guiScrollBarSetScrollPosition(scrollbar, 100.0) function openpanel () if guiGetVisible(window) == false then guiSetVisible(window, true) showCursor(true) getplayers () elseif guiGetVisible(window) == true then guiSetVisible(window, false) showCursor(false) guiGridListClear(gridlist) end end bindKey ( "TAB", "down", openpanel ) function getplayers () guiGridListClear(gridlist) for index, player in ipairs(getElementsByType("player")) do local row = guiGridListAddRow(gridlist) guiGridListSetItemText(gridlist, row, 1, getPlayerName(player), false, false) guiGridListSetItemText(gridlist, row, 2, triggerServerEvent ("level", root), false, false) guiGridListSetItemText(gridlist, row, 3, getPlayerPing(player), false, false) end end addEventHandler("onClientPlayerChangeNick", getRootElement(), getplayers) I want in row 2 to be displayed the level Link to comment
Walid Posted July 7, 2016 Share Posted July 7, 2016 I want in row 2 to be displayed the level I think you don't undrestand what i'm talking about. anyways here is what you want -- Client side: addEventHandler("onClientResourceStart", resourceRoot, function() local screenW, screenH = guiGetScreenSize() local windowW, windowH = 739, 379 local x, y = (screenW - windowW) /2,(screenH - windowH) /2 window = guiCreateWindow(x, y, windowW, windowH, "", false) guiWindowSetSizable(window, false) guiWindowSetMovable(window, false) guiSetVisible(window, false) gridlist = guiCreateGridList(9, 24, 720, 345, false, window) guiGridListAddColumn(gridlist, "Имя Фамилия", 0.3) guiGridListAddColumn(gridlist, "Уровень", 0.3) guiGridListAddColumn(gridlist, "Пинг", 0.3) scrollbar = guiCreateScrollBar(681, 19, 15, 310, false, false, gridlist) guiScrollBarSetScrollPosition(scrollbar, 100.0) end ) function openpanel (tab) guiSetVisible(window, not guiGetVisible(window)) showCursor(guiGetVisible(window)) addPlayersToTab(tab) end addEvent("eventName", true) addEventHandler("eventName", root, openpanel) function addPlayersToTab (tabTable) guiGridListClear(gridlist) for i,v in pairs (tabTable) do local row = guiGridListAddRow(gridlist) guiGridListSetItemText(gridlist, row, 1, v[1], false, false) guiGridListSetItemText(gridlist, row, 2, v[3], false, false) guiGridListSetItemText(gridlist, row, 3, v[2], false, false) end end -- Server side -- show up tab panel function showUp (player, key, keyState ) playersTab = {} if ( keyState == "down" ) then for index, player in ipairs(getElementsByType("player")) do local account = getPlayerAccount(player) if account and not isGuestAccount(account) then local playerName = getPlayerName(player) local ping = getPlayerPing(player) local lvls = getAccountData(account, "lvl") or 0 table.insert(playersTab,{playerName,ping,lvls}) end end triggerClientEvent(player,"eventName", player, playersTab) end end -- bind key function function bindTab( thePlayer ) bindKey(thePlayer, "tab","down",showUp) end -- bind key on player join function startBind () bindTab(source) end addEventHandler("onPlayerJoin",getRootElement(), startBind) -- bind key on resource start function bindForAll () for index, player in pairs(getElementsByType("player")) do bindTab(player) end end addEventHandler("onResourceStart",getResourceRootElement(getThisResource()), bindForAll ) 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