SteveDee Posted September 9, 2018 Posted September 9, 2018 Hi, how can i get the player object from string parameter in command? Using js.
paccoderpster Posted September 9, 2018 Posted September 9, 2018 Server-Side: When you want to find a certain player, that didn't call the command, you could use that: /** * @author Paccoderpster * @description With that function you can find a certain player * @param {str} name The name of the player * @returns {player}, if the player is found or null, if this player isn't logged in */ global.findPlayer = function findPlayer(name) { let players = mp.players.toArray(); for(let p in players) { if(players[p].name == name) { return players[p]; } } return null; } Or, if you want the player object from the player that called the command, you don't have to do anything. mp.events.addCommand(`givemoney`, (player, string) => { //Do Something with player }); Client Side: let player = mp.players.local; 1
SteveDee Posted September 9, 2018 Author Posted September 9, 2018 I was searching for the first one. I thought about doing it with an foreach loop but i hoped there would be a better possibility. But thank you 1
paccoderpster Posted September 10, 2018 Posted September 10, 2018 The forEach in js is a pain in the ass. You cannot break (return) them like in php, the return only exit the current run (like continue would).
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