MrDv0rak Posted July 24, 2014 Share Posted July 24, 2014 Hello, i have a script, and i want to add a one more option - the time played on server. I from Poland and my english can dont be good, sorry. This is client.lua -- Level System local sW, sH = guiGetScreenSize() local windowRank = guiCreateWindow ( (sW-500)/2, (sH-400)/2, 500, 400, "Lista graczy // Poziom graczy", false ) guiWindowSetSizable ( windowRank, false ) guiSetVisible ( windowRank, false) local windowRankGridList = guiCreateGridList ( 10, 28, 360, 360, false, windowRank ) local windowRankColumn = guiGridListAddColumn( windowRankGridList, "Gracz:", 0.90 ) --local windowRankEdit = guiCreateEdit( 383, 150, 100, 30, "", false, windowRank) --local windowRankEdit2 = guiCreateEdit( 383, 250, 100, 30, "", false, windowRank) --local windowRankButton = guiCreateButton( 383, 358, 100, 30, "Change", false, windowRank) local windowRankLabelLevel = guiCreateLabel(383, 120, 100, 20,"Poziom: ", false, windowRank) guiLabelSetHorizontalAlign (windowRankLabelLevel, "center") local windowRankLabelExp = guiCreateLabel(383, 220, 100, 20,"PD: ", false, windowRank) guiLabelSetHorizontalAlign (windowRankLabelExp, "center") local ranksTable = { {"1","Nowy","1000"}, {"2","Szeregowy","2000"}, {"3","Starszy Szeregowy |","3000"}, {"4","Starszy Szeregowy ||","4000"}, {"5","Kapral","5000"}, {"6","Starszy kapral","5800"}, {"7","Plutonowy |","8100"}, {"8","Plutonowy ||","11000"}, {"9","Plutonowy |||","14600"}, {"10","Sierżant |","18800"}, {"11","Sierżant ||","23800"}, {"12","Sierżant |||","29600"}, {"13","Starszy Sierżant |","36300"}, {"14","Starszy Sierżant ||","44100"}, {"15","Starszy Sierżant |||","53000"}, {"16","Starszy Sierżant Sztabowy","63000"}, {"17","Młodszy Chorąży","74500"}, {"18","Chorąży","87400"}, {"19","Starszy chorąży |","102000"}, {"20","Starszy chorąży ||","118400"}, {"21","Starszy chorąży |||","136700"}, {"22","Podporucznik |","157200"}, {"23","Podporucznik ||","180000"}, {"24","Podporucznik |||","205200"}, {"25","Podporucznik ||||","233300"}, {"26","Podporucznik |||||","264400"}, {"27","Porucznik |","298700"}, {"28","Porucznik ||","336500"}, {"29","Porucznik |||","378000"}, {"30","Porucznik ||||","423700"}, {"31","Porucznik |||||","473700"}, {"32","Kapitan |","528400"}, {"33","Kapitan ||","588100"}, {"34","Kapitan |||","653400"}, {"35","Kapitan ||||","724400"}, {"36","Kapitan |||||","801600"}, {"37","Major |","885500"}, {"38","Major ||","976400"}, {"39","Major |||","1074800"}, {"40","Major ||||","1181100"}, {"41","Major |||||","1296000"}, {"42","Podpułkownik |","1419700"}, {"43","Podpułkownik ||","1552900"}, {"44","Podpułkownik |||","1696200"}, {"45","Podpułkownik ||||","1849900"}, {"46","Podpułkownik |||||","2014800"}, {"47","Pułkownik |","2191200"}, {"48","Pułkownik ||","2380000"}, {"49","Pułkownik |||","2581500"}, {"50","Pułkownik |||| ","2796400"}, {"51","Pułkownik |||||","3025300"}, {"52","Generał Brygady |","3268800"}, {"53","Generał Brygady ||","3527500"}, {"54","Generał Brygady |||","3801900"}, {"55","Generał Brygady ||||","4092800"}, {"56","Generał Brygady |||||","4400600"}, {"57","Generał Dywizji |","4726000"}, {"58","Generał Dywizji ||","5069500"}, {"59","Generał Dywizji |||","5431800"}, {"60","Generał Dywizji ||||","6000000"}, {"61","Generał Dywizji |||||","6568200"}, {"62","Generał broni |","7136400"}, {"63","Generał broni ||","7704600"}, {"64","Generał broni |||","8272800"}, {"65","Generał broni ||||","8841000"}, {"66","Generał broni |||||","9409200"}, {"67","Generał |","9977400"}, {"68","Generał ||","10545600"}, {"69","Generał |||","11113800"}, {"70","Marszałek","11692000"} } function getPlayerRankName() for i=1,70 do if getElementData(localPlayer, "level") == tonumber(ranksTable[i][1]) then return ranksTable[i][2] end end end function getPlayerRankExperience() for i=1,70 do if getElementData(localPlayer, "level") == tonumber(ranksTable[i][1]) then return tonumber(ranksTable[i][3]) end end end function mainRanks() if getElementData(localPlayer, "logedin") == true then if getElementData(localPlayer, "experience") > getPlayerRankExperience() then if getElementData(localPlayer, "level") < 70 then setElementData(localPlayer, "level", getElementData(localPlayer, "level") + 1) end end dxDrawImage ( sW/22, sH/2.8, sW/60, sH/60, "images/level/rank"..getElementData(localPlayer, "level")..".jpg" ) dxDrawText ( getPlayerRankName().." ("..getElementData(localPlayer, "level")..")",sW/65, sH/3.6, sW/0, sH/0, tocolor ( 240, 230, 140, 255 ), 1.02, "default-bold" ) dxDrawText ( "Punkty doświadczenia: "..getElementData(localPlayer, "experience"), sW/65, sH/3.27, sW/0, sH/0, tocolor ( 70, 130, 180, 255 ), 1.02, "default-bold" ) if getElementData(localPlayer, "level") < 70 then dxDrawText ( "Potrzebne PD: "..getPlayerRankExperience(),sW/65, sH/3, sW/0, sH/0, tocolor ( 70, 130, 180, 255 ), 1.02, "default-bold" ) else dxDrawText ( "Gratulacje, masz najwyższy poziom!",sW/65, sH/3, sW/0, sH/0, tocolor ( 70, 130, 180, 255 ), 1.02, "default-bold" ) end end end addEventHandler ( "onClientRender", root, mainRanks ) function toggleWindowRanks() if getElementData(localPlayer, "adminRanks") == true then if guiGetVisible(windowRank) == false then guiSetVisible(windowRank, true) showCursor(true) for k, v in ipairs (getElementsByType("player")) do if getElementData (v, "logedin") == true then local row = guiGridListAddRow ( windowRankGridList ) guiGridListSetItemText ( windowRankGridList, row, windowRankColumn, getPlayerName ( v ), false, false ) end end else guiSetVisible(windowRank, false) showCursor(false) guiGridListClear(windowRankGridList) end end end bindKey("F7", "down", toggleWindowRanks) function windowRankClick() local playerName = guiGridListGetItemText ( windowRankGridList, guiGridListGetSelectedItem ( windowRankGridList ), 1 ) if source == windowRankGridList then if guiGridListGetSelectedCount(windowRankGridList) == 1 then guiSetText(windowRankLabelLevel, "Poziom: "..getElementData(getPlayerFromName(playerName), "level")) guiSetText(windowRankLabelExp, "PD: "..getElementData(getPlayerFromName(playerName), "experience")) else guiSetText(windowRankLabelLevel, "Poziom: ") guiSetText(windowRankLabelExp, "PD: ") end end if source == windowRankButton then if guiGridListGetSelectedCount(windowRankGridList) == 1 then local playerName = guiGridListGetItemText ( windowRankGridList, guiGridListGetSelectedItem ( windowRankGridList ), 1 ) if guiGetText(windowRankEdit) ~= "" then setElementData(getPlayerFromName(playerName), "level", tonumber(guiGetText(windowRankEdit))) guiSetText(windowRankLabelLevel, "Poziom: "..getElementData(getPlayerFromName(playerName), "level")) end if guiGetText(windowRankEdit2) ~= "" then setElementData(getPlayerFromName(playerName), "experience", tonumber(guiGetText(windowRankEdit2))) guiSetText(windowRankLabelExp, "PD: "..getElementData(getPlayerFromName(playerName), "experience")) end else outputChatBox("#FF0000[LEVEL SYSTEM]: #FFFFFFSelect the player!", thePlayer, 171, 205, 239, true) end end end addEventHandler ("onClientGUIClick", windowRank, windowRankClick) And this is server.lua -- Level System function onRanksStart () for k, v in ipairs (getElementsByType ("player")) do -- for id, object in ipairs (aclGroupListObjects (aclGetGroup ("Admin"))) do -- local user = "user."..getAccountName (getPlayerAccount (v)) -- if object == user then setElementData(v, "adminRanks", true) end end -- end --end addEventHandler ( "onResourceStart", root, onRanksStart) function onRanksPlayerJoin () -- for id, object in ipairs (aclGroupListObjects (aclGetGroup ("Admin"))) do -- local user = "user."..getAccountName (getPlayerAccount (source)) -- if object == user then setElementData(source, "adminRanks", true) end -- end --end addEventHandler ( "onPlayerLogin", root, onRanksPlayerJoin) I want to show the "play time on server of Player" above "Poziom:" in this GUI in F7 key. Like this - Play time(Czas gry - in Poland): [time] min(utes) or h(ours) Poziom: PD: example: Czas gry: 300 min Poziom: 30 PD: 15000 I want to see this in gui like that. Please help me somebody becouse im too weak to do this. Link to comment
Saml1er Posted July 24, 2014 Share Posted July 24, 2014 guiSetText getTickCount Usage: guiSetText (GuIElement, "Your text goes here") --[[ Now for getTickCount() ]] function msToTimeStr( ms ) --- miliseconds to string format "mm:ss" if not ms then return '' end local ms = ms * 1000 local s = math.floor( ms / 1000 ) local seconds = tostring( math.fmod( s, 60 ) ) if #seconds == 1 then seconds = '0' .. seconds end local minutes = tostring( math.floor( s / 60 ) ) if #minutes == 1 then minutes = '0' .. minutes end return minutes .. ':' .. seconds end local sx,sy = guiGetScreenSize() addEventHandler("onClientRender",root, function () if not tick then --- if tick variable does not exist then tick = getTickCount () --- create one end -- the if statement should be only till here thats why we put an end here local miliseconds = (getTickCount() - tick ) -- its actually current tick - old tick local seconds = miliseconds/1000 -- convert it to seconds local minutes = seconds/60 --- now convert it to minutes -- if you want a string format like "mm:ss" then local timeString = msToTimeStr( seconds ) --- we are calling this function which will convert seconds into a string dxDrawText (timeString,sx/2,sy/2,sx,sy) --- this will draw "mm:ss" format in the middle of screen end ) Link to comment
MrDv0rak Posted July 24, 2014 Author Share Posted July 24, 2014 Thanks for reply, but i dont know how i have to use it . Can u tell more? Link to comment
12p Posted July 24, 2014 Share Posted July 24, 2014 Here, an user-friendly description. string msToTimeStr(time)int time: the time you want to retrieve. must be in miliseconds. returns a string of the time you passed as parameter, formatted like "minutes:seconds" getTickCount returns a given time in miliseconds that you should use, but you gotta read the documentation for it in order to acknowledge how to use it. Sam1er gave you a whole example, you can use it to experiment and check how it works. Link to comment
Saml1er Posted July 24, 2014 Share Posted July 24, 2014 And sorry my bad I confused you, there's a line that converts seconds to miliseconds, although the function name is ms to string but still, you need call it with seconds but if you remove this line: local ms = ms * 1000 Then change this: local timeString = msToTimeStr( miliseconds ) Code works even now if you test it. ^^ Link to comment
MrDv0rak Posted July 24, 2014 Author Share Posted July 24, 2014 I have this: local windowRankEdit2 = guiCreateLabel( 383, 250, 100, 30, "Czas gry:", false, windowRank) And i have this: if guiGetText(windowRankEdit2) ~= "" then end What i have to change/add in if guiGetText(windowRankEdit2) ~= "" then end to show all playtime on server after "Czas gry:" for player? 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