Forum

> > CS2D > Scripts > Name hook
Forums overviewCS2D overview Scripts overviewLog in to reply

English Name hook

9 replies
To the start Previous 1 Next To the start

old Name hook

Powermonger
User Off Offline

Quote
Hi scripters,

I tried to block namechaning with this following script:
1
2
3
4
function name(id,old,new,forced)
  if forced == 0 then  msg2(id,"Name changing is not allowed@C")  return 1  end
end
addhook("name","name")
What I would like to have:
* No namechanging by players
* Script is able to change names

When player is alive, namechaning is blocked (forced is 0), but when player is dead the name will be changed on respawn (forced is now 1).

Is there a simple way to avoid this?

If anyone can figure out a good way, please let me know. Thank you!

old Re: Name hook

Zeik
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
addhook("name","_name")
function _name(id,old,new,forced)
  if forced == 0 then
    msg2(id,"Name changing is not allowed@C")
    return 1
  else
    return 0
  end
end

I think it should've worked as you did it. Maybe the problem was that the function's name was the same as the hook's name.

old Re: Name hook

GeoB99
Moderator Off Offline

Quote
@user Zeik: Unless if it was a reserved word identifier then it could cause unexpected behaviours but it isn't so you can use it as a function's name.

old Re: Name hook

Powermonger
User Off Offline

Quote
Problem still exists; players can still change name when dead.

I know that I could add a blocker to spawn hook ...
1
2
3
4
5
function unblock(id)  block[tonumber(id)] = nil  end
function spawn(id)
block[id] = true
timer(1000,unblock,id)
end
... and add
1
if forced == 0 and not block[id] then
... to name function.

But it looks stupid :s

old Re: Name hook

Mami Tomoe
User Off Offline

Quote
Try this:
1
2
3
4
5
6
7
addhook("name","name")
function name(id)
	if player(id,"health")>0 and forced==0 then
    		msg2(id,"Name changing is not allowed@C")
		return 1
	end
end

You can remove the
and forced==0
if you don't need it...
edited 1×, last 23.01.17 09:48:32 pm

old Re: Name hook

Zeik
User Off Offline

Quote
I misunderstood what the problem was lol.

user Mami Tomoe's solution is way simpler lol. But the condition should be:
1
2
3
4
5
6
7
8
9
addhook("name","name")
function name(id,old,new,forced)
     if player(id,"health")>0 and forced==1 then
          return 0
     else
          msg2(id,"Name changing is not allowed@C")
          return 1
     end
end

EDIT: Yep, didn't see there were parameters lacking. Thanks user Waldin.
edited 1×, last 24.01.17 02:35:34 am

old Re: Name hook

Powermonger
User Off Offline

Quote
Checking health kinda works, but not quite.

The one I managed to get work:
1
if forced == 0 or player(id,"health") > 0 then
Contains a major drawback: it blocks ALL kind of name changes (either by player or lua)!

So, I ended up using this:
1
2
3
4
5
6
7
8
9
10
11
go = {}

function serveraction(id)
go[id] = true	parse("setname "..id.." \"NyNewName\"")	go[id] = nil
end
addhook("serveraction","serveraction")

function name(id)
if not go[id] then	msg2(id,"Name changing is not allowed@C")	return 1	end
end
addhook("name","name")
It's simple, it works.

Thank you for your suggestions!
If someone figures out an easier way, please let me know.

old Re: Name hook

Zeik
User Off Offline

Quote
It should work with the condition I suggested, otherwise there could be a bug in the game.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview