Cider "/rpname" Scipt wanted!

Me and a couple of my friends are starting a Cider server…
It’s going to be serious Role-play, so for that we need “/rpname”.
I know that this is possible We’ve played on a server which had a script like this.

-I’m a newb at LUA in anyway.
If you know how to remove backdoors, i would be really glad if you would post suggestion on how to remove backdoors.

I totally respect that you want to roleplay, but there are already alot of roleplay servers outthere(incase you want to do a public one). And back to your request, what should it do? Set the RP Name? Retrieve the RPName of the one you look at? Etc… details…

Yeah so you can change from your steam name into a Rpname within the server… I’m doing public, i’m just experimenting with owning a server…

I suppose this’d work…lemme try.

[lua]local meta = FindMetaTable(“Player”)

meta:Nick()
return ply:GetNWString(“Name”)
end

end[/lua]

And for the setting of that name…

[lua]function SetRPName(ply)

local name = args[1] --Deprecated method.

ply:SetNWString(“Name”, name)

end
concommand.Add(“rp_setname”, SetRPName)[/lua]

Second function is the actual command, using the deprecated local args method, I suggest you figure out a different way of doing things before this is removed from GMod, if it hasn’t been already. Note that I’m not entirely sure this will work, since I’m still studying the language myself, but I suppose it’s something to work off of in search of a working method.

It was a good try, but there are several errors:

[lua]local meta = FindMetaTable(“Player”)

meta:Nick()
return self:GetNWString(“Name”) //This should not be ply but self.
end

end[/lua]

and

[lua]function SetRPName(ply,com,args)

local name = args[1] --Deprecated method.

self:SetNWString(“Name”, name) //Again not ply, but self.

end
concommand.Add(“rp_setname”, SetRPName)[/lua]

Now I did not correct you to offend you, but so you can learn and not make the same mistakes again! (They happen to everyone!)

Now back to the topic:

A version I would use:

[lua]
local m_player = _R.Player;

//Shared!
m_player.LastNameSet = 0;
function m_player:RPName()

return self:GetNWString('RPName','Name not set!');

end

//Server-side

function m_player:SetRPName(name)

self:SetNWString('RPName',name);

end

local NAME_CHANGE_DAMP = 5; //5 secs between name changes.

local function SetRPName(ply,com,args)

if(ply.LastNameSet < CurTime() + NAME_CHANGE_DAMP) //Check if the last time they changed their name is not too soon!
	
	ply:ChatPrint('You are trying to change your name too often.'); //Remove this line if you want to fail it silently
	return;
end

//Ok, now we can set it.

if(args[1] == '' or args[1] == '  ')
	
	ply:ChatPrint('You tried to set an empty name!');
	return;
end

//Not null perfect.
ply:SetRPName(args[1]);
ply:ChatPrint('Your name is now: '..args[1]);

end
concommand.Add(‘set_rpname’,SetRPName)
[/lua]
This is something I whipped up in notepad, nothing big.

[editline]06:59PM[/editline]

notepad++ of course!

I’ve got no problem with being corrected, I’ve never gotten on-the-spot Lua scripts right anyway. I learned something, at least.

I keep seeing posts about args being deprecated, or improper, or some crap like that, and I see … in the parameters instead of args. I’m gonna stick with args till it stops working. Also, I thought you had to replace the Nick function with your own using FindMetaTable, not this _R method, what’s _R do?

How would i implement it into the server?..

Ok you would do the following in your gamemode files garrysmod/garrysmod/gamemodes/<the gamemode folder>/gamemode

Put this into the “shared.lua” file anywhere as long as its in blank space and not inside another function.

[lua]
local m_player = _R.Player;

m_player.LastNameSet = 0;
function m_player:RPName()

return self:GetNWString('RPName','Name not set!');

end
[/lua]

Put this into the “init.lua” file anywhere as long as its in blank space and not inside another function.

[lua]
local m_player = _R.Player;

function m_player:SetRPName(name)

self:SetNWString('RPName',name);

end

local NAME_CHANGE_DAMP = 5; //5 secs between name changes.

local function SetRPName(ply,com,args)

if(ply.LastNameSet &lt; CurTime() + NAME_CHANGE_DAMP) //Check if the last time they changed their name is not too soon!
	
	ply:ChatPrint('You are trying to change your name too often.'); //Remove this line if you want to fail it silently
	return;
end

//Ok, now we can set it.

if(args[1] == '' or args[1] == '  ')
	
	ply:ChatPrint('You tried to set an empty name!');
	return;
end

//Not null perfect.
ply:SetRPName(args[1]);
ply:ChatPrint('Your name is now: '..args[1]);

end
concommand.Add(‘set_rpname’,SetRPName)
[/lua]

That will have you all set, I think this is all right.

You would then trigger the name change by typing in console “set_rpname <name of chose in quote marks>”
e.g.


set_rpname "the epic name"

There is no shared.lua within Cider gamemod :o

You sure? Else just make the shared.lua file urself and put it in there, I guess.

Args are not deprecated in console commands. They would have been at a specific case if we would have used LuaJIT. But at the end we didn’t. The case they were talking about was this:

[lua]
function FunctionWithUnlimitedArguments(…)

print(arg[1]); //Will print the first argument you gave the function.

end
[/lua]

The good way too use it would have to be this:

[lua]
arg = {…};
[/lua]
If you still want to use args.

_R is the Metatable ‘table’. _R.Player == FindMetaTable(‘Player’)

that’s not args that’s arg

Ah yeah, I was thinking Args as in Arguments xD but yeah it is arg.