Forum

> > CS2D > Scripts > Name hook
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Name hook

9 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Name hook

Powermonger
User Off Offline

Zitieren
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!

alt Re: Name hook

Zeik
User Off Offline

Zitieren
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.

alt Re: Name hook

GeoB99
Moderator Off Offline

Zitieren
@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.

alt Re: Name hook

Powermonger
User Off Offline

Zitieren
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

alt Re: Name hook

Mami Tomoe
User Off Offline

Zitieren
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...
1× editiert, zuletzt 23.01.17 21:48:32

alt Re: Name hook

Zeik
User Off Offline

Zitieren
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.
1× editiert, zuletzt 24.01.17 02:35:34

alt Re: Name hook

Powermonger
User Off Offline

Zitieren
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.

alt Re: Name hook

Zeik
User Off Offline

Zitieren
It should work with the condition I suggested, otherwise there could be a bug in the game.
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht