Jump to content

Visits in my server[solved]


#RooTs

Recommended Posts

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

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
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
https://wiki.multitheftauto.com/wiki/GetPlayerCount

You 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

I not got it :cry::cry:

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

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
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

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
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

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 by Guest
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...