Jaysds1 Posted June 29, 2011 Author Share Posted June 29, 2011 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
Castillo Posted June 29, 2011 Share Posted June 29, 2011 (edited) --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 June 29, 2011 by Guest Link to comment
Jaysds1 Posted June 29, 2011 Author Share Posted June 29, 2011 it doesn't work! Edit: When someone joins, it's suppose to trigger the event and and show the amount of people/players online. Link to comment
Castillo Posted June 29, 2011 Share Posted June 29, 2011 Copy the server side part again, you could have did what I changed to do what you want. Link to comment
Jaysds1 Posted June 29, 2011 Author Share Posted June 29, 2011 that's what i did, but it still shows 0 when i'm the only person online Link to comment
JR10 Posted June 29, 2011 Share Posted June 29, 2011 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
Kenix Posted June 29, 2011 Share Posted June 29, 2011 I create client side function : getPlayerCount = function() return #getElementsByType('player') end use it (tested). Link to comment
Jaysds1 Posted June 29, 2011 Author Share Posted June 29, 2011 JR10, this is part of the gui me and u were working on at the top! And volk-rus, that doesn't work! and yours too JR10. EDIT: Do you want me to upload the whole code? Link to comment
JR10 Posted June 30, 2011 Share Posted June 30, 2011 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 Posted June 30, 2011 Author Share Posted June 30, 2011 thanks JR10. it worked now, How do i show how much Moderators or Admin are online? Link to comment
Castillo Posted June 30, 2011 Share Posted June 30, 2011 I think this could help you: https://community.multitheftauto.com/index.php?p= ... ls&id=1029 Link to comment
Jaysds1 Posted June 30, 2011 Author Share Posted June 30, 2011 In the resource, the Admins online shows the player name, I want mine to show how much admins is online, but thanks anyways. Link to comment
Castillo Posted June 30, 2011 Share Posted June 30, 2011 That's easily changeable, you just have to think for a while, and not come here and ask without even try. Link to comment
Jaysds1 Posted June 30, 2011 Author Share Posted June 30, 2011 lol, ok, I'll think first Link to comment
Kenix Posted June 30, 2011 Share Posted June 30, 2011 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
Jaysds1 Posted June 30, 2011 Author Share Posted June 30, 2011 Volk-rus, I we're done with that now. I just need help with showing the amount of admins or moderators on a gui. thank u though Link to comment
JR10 Posted July 1, 2011 Share Posted July 1, 2011 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
Jaysds1 Posted July 1, 2011 Author Share Posted July 1, 2011 so this is the same thing as the players online function but just change the server-side function? Link to comment
JR10 Posted July 1, 2011 Share Posted July 1, 2011 Well, yeah it's the same client side but change it server side like mine. Link to comment
Jaysds1 Posted July 1, 2011 Author Share Posted July 1, 2011 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
JR10 Posted July 1, 2011 Share Posted July 1, 2011 Remove that # client side but keep it server side. Link to comment
Jaysds1 Posted July 1, 2011 Author Share Posted July 1, 2011 It doesn't show that 1 admin is online. Link to comment
JR10 Posted July 1, 2011 Share Posted July 1, 2011 Did you edit the server? and show me the full code now. Link to comment
Jaysds1 Posted July 1, 2011 Author Share Posted July 1, 2011 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
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