Moony Posted February 18, 2020 Share Posted February 18, 2020 Scrolling through the tutorials, I found a script that displays players in the server when joining and quitting. function playerCount ( ) outputChatBox("#ff8800[server]: #ffffffPlayers: #ffffff(" .. getPlayerCount() .. "#ffffff)" , root, 255, 0, 0, true) end addEventHandler ( "onPlayerJoin", getRootElement(), playerCount ) addEventHandler ( "onPlayerQuit", getRootElement(), playerCount ) What would I have to add to trigger it with a command, such as "/players"? Link to comment
Scripting Moderators ds1-e Posted February 18, 2020 Scripting Moderators Share Posted February 18, 2020 3 hours ago, Moony said: Scrolling through the tutorials, I found a script that displays players in the server when joining and quitting. function playerCount ( ) outputChatBox("#ff8800[server]: #ffffffPlayers: #ffffff(" .. getPlayerCount() .. "#ffffff)" , root, 255, 0, 0, true) end addEventHandler ( "onPlayerJoin", getRootElement(), playerCount ) addEventHandler ( "onPlayerQuit", getRootElement(), playerCount ) What would I have to add to trigger it with a command, such as "/players"? function checkOnline(player, cmd) if player then outputChatBox(#getElementsByType("player")) end end addCommandHandler("players", checkOnline) Link to comment
Skadoosh Posted February 18, 2020 Share Posted February 18, 2020 (edited) 5 hours ago, Moony said: Scrolling through the tutorials, I found a script that displays players in the server when joining and quitting. function playerCount ( ) outputChatBox("#ff8800[server]: #ffffffPlayers: #ffffff(" .. getPlayerCount() .. "#ffffff)" , root, 255, 0, 0, true) end addEventHandler ( "onPlayerJoin", getRootElement(), playerCount ) addEventHandler ( "onPlayerQuit", getRootElement(), playerCount ) What would I have to add to trigger it with a command, such as "/players"? addCommandHandler('players',root function(thePlayer) outputChatBox("Current number of players: "..tostring(getPlayerCount()),thePlayer) end Edited February 18, 2020 by Skadoosh Is the code blocks working? I am sorry I am new to the forums ... Link to comment
Moony Posted February 18, 2020 Author Share Posted February 18, 2020 (edited) 8 hours ago, majqq said: function checkOnline(player, cmd) if player then outputChatBox(#getElementsByType("player")) end end addCommandHandler("players", checkOnline) Excuse my second beginner's question. I'm struggling with the functions. Do you come up with them? Is there a list to such commands? Scrolling through this, this, and this doesn't show any 'checkOnline' function. It does show a 'check' function, but it doesn't seem to be one for such script. UPDATE: is it normal that it doesn't work from the console, yet it does when tiggered from the in-game chatbox? Edited February 18, 2020 by Moony Info acquired from test. Link to comment
ReZurrecti0n Posted February 18, 2020 Share Posted February 18, 2020 https://wiki.multitheftauto.com/wiki/Main_Page Client Functions, Client Events, Server Functions, Server Events (Visiting just these 4 sections on the Wiki will greatly help you as it lists all those Functions as well as Events too) The console is something very different than the chatbox, personally, I don't have much experience with that console window as I never use it though Link to comment
Scripting Moderators ds1-e Posted February 19, 2020 Scripting Moderators Share Posted February 19, 2020 (edited) checkOnline is custom function, which doesn't exist normally in MTA. For console command - delete/comment check for player. function checkOnline(player, cmd) --if player then outputChatBox(#getElementsByType("player")) --end end addCommandHandler("players", checkOnline) Edited February 19, 2020 by majqq Link to comment
Moony Posted February 21, 2020 Author Share Posted February 21, 2020 On 19/02/2020 at 02:09, majqq said: checkOnline is custom function, which doesn't exist normally in MTA. Ok, so you've got the official functions for mta on one side. They can be found in the link provided above. On the other side, custom functions are functions created by the developer. Having a 'function functionName' will asign the name to a function, and between that and 'end', you add the official functions that will do what the developer wants, such as throwing something to the chatbox, creating elements, teleporting the player, changing names, setting timers, and many many other things. Is this correct? Link to comment
Scripting Moderators ds1-e Posted February 21, 2020 Scripting Moderators Share Posted February 21, 2020 (edited) 3 hours ago, Moony said: Ok, so you've got the official functions for mta on one side. They can be found in the link provided above. On the other side, custom functions are functions created by the developer. Having a 'function functionName' will asign the name to a function, and between that and 'end', you add the official functions that will do what the developer wants, such as throwing something to the chatbox, creating elements, teleporting the player, changing names, setting timers, and many many other things. Is this correct? Yes, but those do not need to be official functions. It could be operations on variables/tables, and other custom functions. Edited February 21, 2020 by majqq 1 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