Simple way to get a playername?

If i wanted to make this button that runs a console command such as darkrp unarrest {player}, now how would the code know the playername?

DarkRP: ply:getDarkRPVar(“rpname”)

Normal: ply:Nick

Like that ?

Thanks, now how do i make the ply:getDarkRPVar(“rpname”) into a concommand?
Is it like this?

[lua]concommand.Run( Player ply, darkrp, unarrest, ply:getDarkRPVar(“rpname”) )[/lua]

Or is it:

[lua]concommand.Run( ply:getDarkRPVar(“rpname”), darkrp, unarrest, Player ply )[/lua]

The concommand from gmod wiki looks like this:

[lua]concommand.Run( Player ply, string cmd, any args, string argumentString )[/lua]

concommand.Add

Mpan, i’m not adding a command im trying to run it.

Try using

Global.RunConsoleCommand (that’s what like 99% of addons use)

I searched through the darkrp files and found that i can use unarrest instead of darkrp unarrest.
So would this work then?

[lua]concommand.Run( ply:getDarkRPVar(“rpname”), unarrest, Player ply )[/lua]

Or would this??

[lua]concommand.Run( Player ply, unarrest, ply:getDarkRPVar(“rpname”) )[/lua]

[editline]26th March 2016[/editline]

Well with global i guess this?

[lua]RunConsoleCommand( unarrest, ply:getDarkRPVar(“rpname”) )[/lua]

[editline]26th March 2016[/editline]

Or?

[lua]local function( ply )
RunConsoleCommand( unarrest, ply:getDarkRPVar(“rpname”) )[/lua]

Well,



RunConsoleCommand( "unarrest", ply:getDarkRPVar("rpname") )


Would work, but you’d need to define ply

[lua]local function( ply )
RunConsoleCommand( unarrest, ply:getDarkRPVar(“rpname”) )[/lua]?

That wouldn’t work since that’s not how you’re meant to define functions and also because you’re not making unarrest a string

[editline]26th March 2016[/editline]

And also you’re not defining ply

[editline]26th March 2016[/editline]

I think I’ll wait for someone else to post something here that will make more sense to you since we’re kind of going in circles here

What about

[lua]local function( Player, ply )
RunConsoleCommand( string unarrest, ply:getDarkRPVar(“rpname”) )[/lua]

[editline]26th March 2016[/editline]

Well, can you tell me what a string does and what it is?
I am new to lua and don’t know much

“This is a string”

And you have to define ply like MPan told you to.

you can use this in your runconsolecommand: Player:unArrest(Player Unarrester)

Ok, thanks. Still don’t get how to define ply but :
[lua]local function( Player, ply )
RunConsoleCommand( “unarrest”, “ply:getDarkRPVar(“rpname”)” )[/lua]

What I meant by ‘define ply’ was that you need to do something like



local ply = LocalPlayer()


For example. You need an actual player to unarrest for that code to work…

Then, all you need to do is



RunConsoleCommand( "unarrest", ply:getDarkRPVar("rpname") )


What you would do instead for your button is to network the player from client -> server then unarrest the player from there.

//Two people posting at the same time, haha, ill let you help him.

Deleted the message :slight_smile:

So are you saying running the console command doesn’t work? I don’t see the need to network when you can just use that instead

No. Thats a serverside function.

@MPan, unarrest is a undefined console command.

:snip:

So, it wont work?