renam action

Discussions about ET modding (sdk code, player/weapon modeling)

Moderators: Forum moderators, developers

Post Reply
crazyfrag
Posts: 105
Joined: Fri Oct 01, 2004 1:17 pm

renam action

Post by crazyfrag »

Code: Select all

function RenameUser(clientNum, newname)
  local userinfo = et.trap_GetUserinfo(clientNum)
  userinfo = et.Info_SetValueForKey(userinfo, "name", newname)
local name = string.gsub(userinfo, "^3@+^1%w+", "")
  et.trap_SetUserinfo(clientNum, name)
  et.ClientUserinfoChanged(clientNum)
end 

if modified this code (thx to luke4ward)
i want to change @+ to nothing but its somehow not working :S
bennz
Posts: 9
Joined: Tue Feb 06, 2007 10:24 am

Post by bennz »

Code: Select all

local name = string.gsub(userinfo, "^3@+^1%w+", "") 
well pattern machting...

Code: Select all

"^3@+^1%w+"
--> a ^ represents beginning of a string! Escape it & it will match the color code ^3

Manual says: "You can use the escape `%´ not only for the magic characters, but also for all other non-alphanumeric characters. When in doubt, play safe and put an escape. "




edit: e.g.

Code: Select all

local name = string.gsub(userinfo, "%^3%@+^1[%S]+", "") 
--> somewhere in that string: color code ^3, followed by one or more
@, color code ^1 and everything but a space character.

"^3@^1affenarsch more nick" --> " more nick"
"start ^3@^1affenarsch more nick" --> "start more nick"


or

Code: Select all

local name = string.gsub(userinfo, "%^3%@+^1.+", "") 
--> somewhere in that string: color code ^3, followed by one or more
@, color code ^1 and everything else.

"^3@^1affenarsch more nick" --> ""
"start ^3@^1affenarsch more nick" --> "start "




greetz
Last edited by bennz on Thu Jun 25, 2009 10:40 am, edited 1 time in total.
crazyfrag
Posts: 105
Joined: Fri Oct 01, 2004 1:17 pm

Post by crazyfrag »

Code: Select all

"\"^3\"@+"\^1\"%w+"
is this correct (sry im not that lua guru) :S
bennz
Posts: 9
Joined: Tue Feb 06, 2007 10:24 am

Post by bennz »

hehe

btw: crazy posted his reply before i edited my post with examples, so don't laugh :thumbup:
Post Reply