Forum

> > CS2D > General > Help with Lua Hooks
ForenübersichtCS2D-ÜbersichtGeneral-ÜbersichtEinloggen, um zu antworten

Englisch Help with Lua Hooks

18 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Help with Lua Hooks

Marijuana
User Off Offline

Zitieren
I'm trying to add a function that displays a text stating that an admin had banned a certain player.

So far I have:

1
2
3
4
5
6
7
8
9
addhook("ban","admin_ban")
function admin_ban(id)
	msg("©255000000"..player(id, "name").." (ADMIN) has banned "..victim(id, "name").."")
end

addhook("kick","admin_kick")
function admin_kick(id)
	msg("©255000000"..player(id, "name").." (ADMIN) has kicked "..victim(id, "name").."")
end

What did I do wrong? Apparently the Dedicated Server Console says that "ban" and "kick" is not a valid hook/command.

alt Re: Help with Lua Hooks

DC
Admin Off Offline

Zitieren
read sys/lua/info.txt
it contains all available hooks.

"ban" and "kick" are no valid hooks. so you can't use them.

alt Re: Help with Lua Hooks

Marijuana
User Off Offline

Zitieren
Is there any possible way to display an admin kicking or banning a player, besides the info displayed on the top-left corner of the screen?

CS2D hat geschrieben
Player has left the game. (Banned)


I want the text box (chat area) to display this:

CS2D hat geschrieben
Player (ADMIN) has banned Player 2.

alt Re: Help with Lua Hooks

sonnenschein
User Off Offline

Zitieren
I think you need this hook:

1
2
3
leave(id, reason)					on leave
-id: player id
-reason: reason id (0 normal, >0 kick/ban/timeout)

alt Re: Help with Lua Hooks

DC
Admin Off Offline

Zitieren
yes the leave hook would probably be the best choice. however you can't display which player performed the kick/ban. that's not possible with the current set of Lua commands/parameters

alt Re: Help with Lua Hooks

Marijuana
User Off Offline

Zitieren
Thanks for you help. I have one more question:

I noticed this in the info.txt

1
2
3
4
5
6
hit(id,source,weapon,hpdmg,apdmg)			on hit/damage
-id: player id
-source: source player id or 0
-weapon: weapon type / source type id
-hpdmg: caused damage (health)
-apdmg: caused damage (armor)

Is it possible to display a text stating how much damage a certain weapon have given to another player?

Example:

CS2D hat geschrieben
5 HP Damage given
5 HP Damage given
12 HP Damage received
Player *DEAD*: Stop shooting me!
84 HP Damage received
You are dead! Try harder next time!

alt Re: Help with Lua Hooks

Marijuana
User Off Offline

Zitieren
Can I do this?

1
2
3
4
5
addhook("hit","player_hit")
function player_hit(id)
	msg("©150150255 "..hpdmg.." HP given to "..id.."")
	msg("©150150255 "..hpdmg.." HP received from "..source.."")
end

alt Re: Help with Lua Hooks

Lee
Moderator Off Offline

Zitieren
Marijuana hat geschrieben
Is it possible to display a text stating how much damage a certain weapon have given to another player?


1
2
3
4
5
6
addhook("hit", "displayinfo")
function displayinfo(p, v w, hp, ap)
	if (player(p, "team") ~= player(v, "team")) and hp > 0 then
		print("Player "..player(v, "name").. " has done " .. hp .. " damage to player " .. player(p, "name"))
	end
end

Zitat
1
2
3
4
5
addhook("hit","player_hit")
function player_hit(id)
     msg("©150150255 "..hpdmg.." HP given to "..id.."")
     msg("©150150255 "..hpdmg.." HP received from "..source.."")
end


No, the function's parameters are missing the upvalue hpdmg, and you'll also have to check that you're not hitting your own team members and in turn creating a bunch of 0-damages. Add the following to your code - player_hit (id, source, w, hpdmg)

and add an if statement right before the msg code
1× editiert, zuletzt 16.07.09 19:37:41

alt Re: Help with Lua Hooks

Marijuana
User Off Offline

Zitieren
Thanks, but it doesn't work

It says:

Dedicated Server hat geschrieben
LUA ERROR: sys/lua/server.lua:235: ')' expected near 'w'
1× editiert, zuletzt 16.07.09 19:40:44

alt Re: Help with Lua Hooks

sonnenschein
User Off Offline

Zitieren
lee was 15153153153 times faster
and 1545154145151 times better too
EDIT:
1
2
3
4
5
6
addhook("hit", "displayinfo")
function displayinfo(p, v, w, hp, ap)
	if (player(p, "team") ~= player(v, "team")) and hp > 0 then
		print("Player "..player(v, "name").. " has done " .. hp .. " damage to player " .. player(p, "name"))
	end
end
idk if that works

alt Re: Help with Lua Hooks

Marijuana
User Off Offline

Zitieren
LUA ERROR: sys/lua/server.lua:239: 'end' expected (to close 'function' at line 220) near '(eof)'

EDIT: Nevermind, I fixed it. It should be:

1
2
3
4
5
6
7
addhook("hit", "displayinfo") 
function displayinfo(p, v, w, hp, ap) 
if (player(p, "team") ~= player(v, "team")) and hp > 0 then 
print("Player "..player(v, "name").. " has done " .. hp .. " damage to player " .. player(p, "name")) 
end 
end
end

Just add an extra 'end'.

Thanks DC, LinuxGuy, and Lee.
1× editiert, zuletzt 16.07.09 19:45:46

alt Re: Help with Lua Hooks

sonnenschein
User Off Offline

Zitieren
1
2
3
4
5
6
7
addhook("hit", "displayinfo")
function displayinfo(p, v, w, hp, ap)
	if (player(p, "team") ~= player(v, "team")) and hp > 0 then
		print("Player "..player(v, "name").. " has done " .. hp .. " damage to player " .. player(p, "name"))
	end
end 
end
now?

alt Re: Help with Lua Hooks

Marijuana
User Off Offline

Zitieren
This is the last question, I swear!

What is the correct id for Kick, Ban, and Timeout?

Using:
1
2
3
leave(id, reason)					on leave
-id: player id
-reason: reason id (0 normal, >0 kick/ban/timeout)

If normal is 0, would kick be 1, ban be 2, and timeout be 3?

Is it possible to show a text stating someone leaving?


Example:

Player 2 has been banned

instead of:

Player 2 has left the game (Banned).

alt Re: Help with Lua Hooks

Lee
Moderator Off Offline

Zitieren
oO that's weird, I could've sworn I had the right number of ends -.-, so much for coding on the fly

Zitat
Is it possible to show a text stating someone leaving?


I'm not sure if this is the correct sequence but it should go something like this

1
2
3
4
5
6
7
addhook("leave", "hk_leave_msg")
function hk_leave_msg(p, r)
	if r == 0 then return msg("Player "..player(p, "name").. " left the server") end
	if r == 1 then return msg("Player "..player(p, "name").. " has been kicked")
	elseif r == 2 then return msg("Player "..player(p, "name").. " has been banned")
	elseif r == 3 then return msg("Player "..player(p, "name").. " timedout") end
end

alt Re: Help with Lua Hooks

Marijuana
User Off Offline

Zitieren
Thanks, it works fine. IF I need more help I post on the forums.

I renamed some of the words, but it doesn't affect the behavior of the server whatsoever.

1
2
3
4
5
6
7
addhook("leave", "hk_leave_msg") 
function hk_leave_msg(p, r) 
     if r == 0 then return msg("Player "..player(p, "name").. " left the server!") end
     if r == 1 then return msg("Player "..player(p, "name").. " has been kicked!")
     elseif r == 2 then return msg("Player "..player(p, "name").. " has been banned by an admin!")
     elseif r == 3 then return msg("Player "..player(p, "name").. " lagged out!") end
end

I should post this on the Script Database. I'll be sure to include your name.
2× editiert, zuletzt 18.07.09 15:00:33
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antwortenGeneral-ÜbersichtCS2D-ÜbersichtForenübersicht