Forum

> > CS2D > General > Help with Lua Hooks
Forums overviewCS2D overviewGeneral overviewLog in to reply

English Help with Lua Hooks

18 replies
To the start Previous 1 Next To the start

old Help with Lua Hooks

Marijuana
User Off Offline

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

old Re: Help with Lua Hooks

DC
Admin Off Offline

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

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

old Re: Help with Lua Hooks

Marijuana
User Off Offline

Quote
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 has written
Player has left the game. (Banned)


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

CS2D has written
Player (ADMIN) has banned Player 2.

old Re: Help with Lua Hooks

sonnenschein
User Off Offline

Quote
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)

old Re: Help with Lua Hooks

DC
Admin Off Offline

Quote
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

old Re: Help with Lua Hooks

Marijuana
User Off Offline

Quote
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 has written
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!

old Re: Help with Lua Hooks

Marijuana
User Off Offline

Quote
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

old Re: Help with Lua Hooks

Lee
Moderator Off Offline

Quote
Marijuana has written
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

Quote
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
edited 1×, last 16.07.09 07:37:41 pm

old Re: Help with Lua Hooks

Marijuana
User Off Offline

Quote
Thanks, but it doesn't work

It says:

Dedicated Server has written
LUA ERROR: sys/lua/server.lua:235: ')' expected near 'w'
edited 1×, last 16.07.09 07:40:44 pm

old Re: Help with Lua Hooks

sonnenschein
User Off Offline

Quote
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

old Re: Help with Lua Hooks

Marijuana
User Off Offline

Quote
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.
edited 1×, last 16.07.09 07:45:46 pm

old Re: Help with Lua Hooks

sonnenschein
User Off Offline

Quote
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?

old Re: Help with Lua Hooks

Marijuana
User Off Offline

Quote
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).

old Re: Help with Lua Hooks

Lee
Moderator Off Offline

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

Quote
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

old Re: Help with Lua Hooks

Marijuana
User Off Offline

Quote
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.
edited 2×, last 18.07.09 03:00:33 pm
To the start Previous 1 Next To the start
Log in to replyGeneral overviewCS2D overviewForums overview