#RooTs Posted December 12, 2014 Share Posted December 12, 2014 (edited) Hello, wanted to show on the screen a total number of hits on my server. what function should I use? example in my screen Players online: 20 Visits: 500 Edited December 18, 2014 by Guest Link to comment
DiSaMe Posted December 12, 2014 Share Posted December 12, 2014 https://wiki.multitheftauto.com/wiki/OnPlayerJoin https://wiki.multitheftauto.com/wiki/OnPlayerQuit Link to comment
#RooTs Posted December 12, 2014 Author Share Posted December 12, 2014 https://wiki.multitheftauto.com/wiki/OnPlayerJoinhttps://wiki.multitheftauto.com/wiki/OnPlayerQuit just want to count all players My example: local sx,sy = guiGetScreenSize() local px,py = 1600,900 local x,y = (sx/px), (sy/py) function LekRoots() local visits = NAME_FUNCTION ??????? dxDrawText("Visits"..visits,x*100, y*450, x*1420, y*90,tocolor(255,255,255,255),0.6,"bankgothic","left","top",false,false,false) end Link to comment
DiSaMe Posted December 12, 2014 Share Posted December 12, 2014 What function? MTA doesn't count the players who have visited. You have to do it. Using "onPlayerJoin" event. Link to comment
xeon17 Posted December 12, 2014 Share Posted December 12, 2014 https://wiki.multitheftauto.com/wiki/GetPlayerCount You can use this function to check how many players are currently online. Link to comment
#RooTs Posted December 12, 2014 Author Share Posted December 12, 2014 What function? MTA doesn't count the players who have visited. You have to do it. Using "onPlayerJoin" event. can make an example to me, try to understand? thank ever since already. Link to comment
DiSaMe Posted December 12, 2014 Share Posted December 12, 2014 Oh, come on... local visitCount = 0 function increaseVisitCountOnJoin() visitCount = visitCount+1 end addEventHandler("onPlayerJoin", root, increaseVisitCountOnJoin) Of course, this is server-side, and in order to draw it via DX drawing functions on the client-side, you need to use element data or custom events to send the data to the client. Link to comment
ViRuZGamiing Posted December 12, 2014 Share Posted December 12, 2014 Oh, come on... local visitCount = 0 function increaseVisitCountOnJoin() visitCount = visitCount+1 end addEventHandler("onPlayerJoin", root, increaseVisitCountOnJoin) Of course, this is server-side, and in order to draw it via DX drawing functions on the client-side, you need to use element data or custom events to send the data to the client. You'll need to store and check name too so it doesn't make the same player count for 1+ visits. Link to comment
MTA Team 0xCiBeR Posted December 13, 2014 MTA Team Share Posted December 13, 2014 I would store serial actually, anyone can change their name Link to comment
Anubhav Posted December 13, 2014 Share Posted December 13, 2014 https://wiki.multitheftauto.com/wiki/GetPlayerCountYou can use this function to check how many players are currently online. trigger or #getElementsByType("player") Oh guyz, wasn't this easy? Link to comment
MTA Team 0xCiBeR Posted December 13, 2014 MTA Team Share Posted December 13, 2014 https://wiki.multitheftauto.com/wiki/GetPlayerCountYou can use this function to check how many players are currently online. trigger or #getElementsByType("player") Oh guyz, wasn't this easy? That would just work to get online players. As stated in the first post, he wants to store Total Unique Player Visit & Total Online Players. Link to comment
Anubhav Posted December 13, 2014 Share Posted December 13, 2014 https://wiki.multitheftauto.com/wiki/GetPlayerCountYou can use this function to check how many players are currently online. trigger or #getElementsByType("player") Oh guyz, wasn't this easy? That would just work to get online players. As stated in the first post, he wants to store Total Unique Player Visit & Total Online Players. Ow, I just read the players online! For the total unique player, store it in a database of SQL, If you restart the script and it's storing with variables/tables, it'll be lost. Save the serial and remember to get the data and insert the data Link to comment
#RooTs Posted December 13, 2014 Author Share Posted December 13, 2014 I not got it Client local sx,sy = guiGetScreenSize() local px,py = 1600,900 local x,y = (sx/px), (sy/py) function LekRoots() local visits = increaseVisitCountOnJoin(getLocalPlayer()) dxDrawText("Visits"..visits,x*100, y*450, x*1420, y*90,tocolor(255,255,255,255),0.6,"bankgothic","left","top",false,false,false) end Server local visitCount = 0 function increaseVisitCountOnJoin() visitCount = visitCount+1 end addEventHandler("onPlayerJoin", root, increaseVisitCountOnJoin) Link to comment
.:HyPeX:. Posted December 13, 2014 Share Posted December 13, 2014 Seriously, how hard can this be?! Server local serials = {} function onPlayerJoin() local serial = getPlayerSerial(source) if serials[serial] then else serials[serial] = serial end setElementData(source, "uniqueHits", CountHits) addEventHandler("onPlayerJoin",root,onPlayerJoin) function CountHits() local hits = 0 for i,v in pairs(serials) do hits = hits + 1 end return hits end function onResourceStart() local file = fileOpen("pc.txt") if file then size = fileGetSize(file) local buffer = fileRead(file,size) local serials = fromJSON(buffer) fileClose(file) end end addEventHandler("onResourceStart", resourceRoot, onResourceStart) function onResourceStop() local file = fileCreate("pc.txt") fileWrite(file, toJSON(serials)) fileClose(file) end addEventHandler("onResourceStop", resourceRoot, onResourceStop) Client local uniqueHits = getElementData(getLocalPlayer(), "uniqueHits") Link to comment
Banex Posted December 13, 2014 Share Posted December 13, 2014 You can not call the function to the side of the client this way, and not add arguments that are not used in function use https://wiki.multitheftauto.com/wiki/OnClientPlayerJoin Link to comment
#RooTs Posted December 17, 2014 Author Share Posted December 17, 2014 Seriously, how hard can this be?!Server local serials = {} function onPlayerJoin() local serial = getPlayerSerial(source) if serials[serial] then else serials[serial] = serial end setElementData(source, "uniqueHits", CountHits) addEventHandler("onPlayerJoin",root,onPlayerJoin) function CountHits() local hits = 0 for i,v in pairs(serials) do hits = hits + 1 end return hits end function onResourceStart() local file = fileOpen("pc.txt") if file then size = fileGetSize(file) local buffer = fileRead(file,size) local serials = fromJSON(buffer) fileClose(file) end end addEventHandler("onResourceStart", resourceRoot, onResourceStart) function onResourceStop() local file = fileCreate("pc.txt") fileWrite(file, toJSON(serials)) fileClose(file) end addEventHandler("onResourceStop", resourceRoot, onResourceStop) Client local uniqueHits = getElementData(getLocalPlayer(), "uniqueHits") no work, sorry for the delay, more more was traveling Link to comment
WASSIm. Posted December 17, 2014 Share Posted December 17, 2014 realy guys its that to hard ? local totalVisiters = 0 addEventHandler("onResourceStart", resourceRoot, function () executeSQLQuery("CREATE TABLE IF NOT EXISTS players (name TEXT, serial TEXT)") for _, player in pairs(getElementsByType("player")) do local serial = getPlayerSerial(player) local result = executeSQLQuery("SELECT * FROM players WHERE serial=?", serial) if (#result == 0) then local name = getPlayerName(player) executeSQLQuery("INSERT INTO players(name,serial) VALUES(?,?)", name, serial) end end local count = #executeSQLQuery("SELECT * FROM players") if (count) and (tonumber(count)) then totalVisiters = count end end) addEventHandler("onPlayerJoin",root, function () local serial = getPlayerSerial(source) local result = executeSQLQuery("SELECT * FROM players WHERE serial=?", serial) if (#result == 0) then local name = getPlayerName(source) executeSQLQuery("INSERT INTO players(name,serial) VALUES(?,?)", name, serial) totalVisiters = totalVisiters+1 end end) Link to comment
Anubhav Posted December 17, 2014 Share Posted December 17, 2014 realy guys its that to hard ?[lua]local totalVisiters = 0 addEventHandler("onResourceStart", resourceRoot, function () executeSQLQuery("CREATE TABLE IF NOT EXISTS players (name TEXT, serial TEXT)") for _, player in pairs(getElementsByType("player")) do local serial = getPlayerSerial(player) local result = executeSQLQuery("SELECT * FROM players WHERE serial=?", serial) if (#result == 0) then local name = getPlayerName(player) executeSQLQuery("INSERT INTO players(name,serial) VALUES(?,?)", name, serial) end end local count = #executeSQLQuery("SELECT * FROM players") if (count) and (tonumber(count)) then totalVisiters = count end end) addEventHandler("onPlayerJoin",root, function () local serial = getPlayerSerial(source) local result = executeSQLQuery("SELECT * FROM players WHERE serial=?", serial) if (#result == 0) then local name = getPlayerName(source) executeSQLQuery("INSERT INTO players(name,serial) VALUES(?,?)", name, serial) totalVisiters = totalVisiters+1 end end) Sorry if I'm posting something wrong, but hey dude: Mainly all scripters are working on thier servers, they have no time for this. Some people have exams? Link to comment
WASSIm. Posted December 17, 2014 Share Posted December 17, 2014 Sorry if I'm posting something wrong, but hey dude: Mainly all scripters are working on thier servers, they have no time for this. Some people have exams? i talking with people post wrong code, and i working nn my own server Link to comment
#RooTs Posted December 17, 2014 Author Share Posted December 17, 2014 (edited) what's wrong? Client: local screenW,screenH = guiGetScreenSize() local resW, resH = 1280, 720 local x, y = (screenW/resW), (screenH/resH) local myFont = dxCreateFont( "info/font.ttf", 10 ) local player = getLocalPlayer() function DXINFO ( ) local visit = getElementData(getLocalPlayer(), "uniqueHits") dxDrawText("Visitas"..visit ,x*310+alin, y*660+mais, x*310, y*40,tocolor(255, 255, 255,Text+100),1.0,myFont,"left","top",false,false,false,true) end function toggleRadar() if isVisible then addEventHandler("onClientRender", root, DXINFO) else removeEventHandler("onClientRender", root, DXINFO) end isVisible = not isVisible end bindKey ("F11", "down", toggleRadar) addEventHandler("onClientRender", root, DXINFO) Server: local serials = {} function onPlayerJoin() local serial = getPlayerSerial(source) if serials[serial] then else serials[serial] = serial end setElementData(source, "uniqueHits", CountHits) addEventHandler("onPlayerJoin",root,onPlayerJoin) function CountHits() local hits = 0 for i,v in pairs(serials) do hits = hits + 1 end return hits end function onResourceStart() local file = fileOpen("pc.txt") if file then size = fileGetSize(file) buffer = fileRead(file,size) serials = fromJSON(buffer) fileClose(file) end end addEventHandler("onResourceStart", resourceRoot, onResourceStart) function onResourceStop() local file = fileCreate("pc.txt") fileWrite(file, toJSON(serials)) fileClose(file) end addEventHandler("onResourceStop", resourceRoot, onResourceStop) Edited December 17, 2014 by Guest Link to comment
WASSIm. Posted December 17, 2014 Share Posted December 17, 2014 you should tell us whats wrong and we will fixed it Link to comment
TAPL Posted December 17, 2014 Share Posted December 17, 2014 ^ At the server side there's an 'end' missing after line 10, also at line 26 you shouldn't have local. At the client side the variables alin, mais and Text is not defined. Link to comment
Bonsai Posted December 17, 2014 Share Posted December 17, 2014 Maybe you should stick to creating HUDs Link to comment
#RooTs Posted December 17, 2014 Author Share Posted December 17, 2014 ^At the server side there's an 'end' missing after line 10, also at line 26 you shouldn't have local. At the client side the variables alin, mais and Text is not defined. Update and no work you know I'm not professional about it someone help me? Link to comment
Bonsai Posted December 17, 2014 Share Posted December 17, 2014 Wouldn't it be muuuuuuuuuuuuuuuch easier to just save players in a database by serial, as you might even already do for stats, and take the number of rows as total visitors? No files, variables or other weird stuff involved. SELECT count(*) FROM TABLE; 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