Jump to content

Problems


Jaysds1

Recommended Posts

  • Replies 365
  • Created
  • Last Reply

Top Posters In This Topic

Posted

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!

My in-game name: Jaysds1

Retired CMG Scripter

World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode

Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/

 

sE5Qm.png

TiV3C.png

img.php?id=0&text=Lua%20Scripter

Posted (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 by Guest

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Copy the server side part again, you could have did what I changed to do what you want.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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 
) 

Business System viewtopic.php?f=108&t=35797

Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726

SQLite Tutorial viewtopic.php?f=148&t=38203

Posted

I create client side function :

  
getPlayerCount = function()  
return #getElementsByType('player')   
end       
  

use it (tested).

http://vk.com/the_kenix

Вопросы задавайте на форуме, не пишите мне в личку.

Please don't pm me.

Posted

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 
) 

Business System viewtopic.php?f=108&t=35797

Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726

SQLite Tutorial viewtopic.php?f=148&t=38203

Posted

That's easily changeable, you just have to think for a while, and not come here and ask without even try.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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

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

in client side

http://vk.com/the_kenix

Вопросы задавайте на форуме, не пишите мне в личку.

Please don't pm me.

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

Business System viewtopic.php?f=108&t=35797

Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726

SQLite Tutorial viewtopic.php?f=148&t=38203

Posted

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.

My in-game name: Jaysds1

Retired CMG Scripter

World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode

Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/

 

sE5Qm.png

TiV3C.png

img.php?id=0&text=Lua%20Scripter

Posted

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) 
  

My in-game name: Jaysds1

Retired CMG Scripter

World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode

Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/

 

sE5Qm.png

TiV3C.png

img.php?id=0&text=Lua%20Scripter

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