Jump to content

Problems


Jaysds1

Recommended Posts

  • Replies 365
  • Created
  • Last Reply

Top Posters In This Topic

I want to know how to show the amount of players on a gui,

but the

getPlayerCount 

is Server-side.

this is what I have.

Client-side

  
players_on = guiCreateLabel(243,372,16,22,"0",false,rules) 
  
  
addEvent("players",true) 
addEventHandler("players",getRootElement(), 
function(count) 
    guiSetText(player_on, count) 
end) 
  

Server-side

  
local count = getPlayerCount 
triggerClientEvent("players",getRootElement(),count) 
  

If you don't get a reply by me, sorry my internet is going to be down about 1-3 days!

Link to comment

--client side:

players_on = guiCreateLabel(243,372,16,22,"0",false,rules) 
  
addEvent("players",true) 
addEventHandler("players",root, 
function(count) 
    guiSetText(player_on, tostring(count)) 
end) 

--server side:

addEventHandler("onPlayerJoin",root, 
function () 
local count = getPlayerCount() 
triggerClientEvent("players",getRootElement(),count) 
end) 

Edited by Guest
Link to comment

try this

--client side 
addEventHandler('onClientResourceStart', resourceRoot, 
function() 
players_on = guiCreateLabel(243,372,16,22,"0",false,rules) 
triggerServerEvent('onDownloadingResourceFinish', root) 
end 
) 
  
addEvent("players",true) 
addEventHandler("players",root, 
function(count) 
    guiSetText(player_on, tostring(count)) 
end) 
  
--server side 
addEvent('onDownloadingResourceFinish', true) 
addEventHandler('onDownloadingResourceFinish', root, 
function() 
local count = getPlayerCount() 
triggerClientEvent("players",getRootElement(),count) 
end 
) 

Link to comment

here:

--client side 
addEventHandler('onClientResourceStart', resourceRoot, 
function() 
players_on = guiCreateLabel(243,372,16,22,"0",false,rules) 
triggerServerEvent('onDownloadingResourceFinish', root) 
end 
) 
  
addEvent("players",true) 
addEventHandler("players",root, 
function(count) 
    guiSetText(players_on, tostring(count)) 
end) 
  
--server side 
addEvent('onDownloadingResourceFinish', true) 
addEventHandler('onDownloadingResourceFinish', root, 
function() 
local count = getPlayerCount() 
triggerClientEvent("players",getRootElement(),count) 
end 
) 

Link to comment

Jaysds1,oh ... You can use my function example :

getPlayerCount = function()  
return #getElementsByType('player')  
end  
addCommandHandler('getCount',function()  
outputChatBox(getPlayerCount())  
end)   

in client side

Link to comment
local admins = {} 
for i, v in ipairs(getElementsByType('player')) do 
--if isPlayerAdmin then check if the player is admin 
table.insert(admins, v) 
--end 
end 
triggerClientEvent('admins', root, #admins) 

and the client event is the same guiSetText or something.

Link to comment

the debugscript says that the client side:

<name> or '...' expected near ' # '. 

This is my code,

Client-side:

  
  
 addEvent("admins",true) 
 addEventHandler("admins", root, 
 function(#admins) 
    guiSetText(admins_on, tostring(#admin)) 
 end) 
  
 addEvent("mods",true) 
 addEventHandler("mods", root, 
 function(#mods) 
    guiSetText(mods_on, tostring(#mods)) 
 end) 
  

I used the code you gave me.

Link to comment

Server-side

  
local admins = {} 
for i, v in ipairs(getElementsByType('player')) do 
--if isPlayerAdmin then check if the player is admin 
table.insert(admins, v) 
--end 
end 
triggerClientEvent('admins', root, #admins) 
  
local mods = {} 
for i, v in ipairs(getElementsByType('player')) do 
--if isPlayerAdmin then check if the player is admin 
table.insert(mods, v) 
--end 
end 
triggerClientEvent('mods', root, #mods) 
  

Client-side

  
 addEvent("admins",true) 
 addEventHandler("admins", root, 
 function(admins) 
    guiSetText(admins_on, tostring(#admin)) 
 end) 
  
 addEvent("mods",true) 
 addEventHandler("mods", root, 
 function(mods) 
    guiSetText(mods_on, tostring(#mods)) 
 end) 
  

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