Author Topic: Please Help!  (Read 3131 times)

0 Members and 2 Guests are viewing this topic.

Offline BrightLiteFilms

  • Newbie
  • *
  • Posts: 2
  • Karma: 0
Please Help!
« on: July 12, 2010, 10:35:32 AM »
I am running ULX and Ulib. I just want to know if there is a way to make it so that deaths (who killed who) shows up in the chat bar for admins only. This will help me know if it was RDM, and it would be appreciated if someone would tell me how to do that, if there is even a way.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Please Help!
« Reply #1 on: July 12, 2010, 10:53:08 AM »
Completely untested but try the following:

Code: [Select]
local function death( victim_name, victim_team, inflicter_name, attacker_name, attacker_team )
local players = player.GetAll()
local str = ("%s was killed by %s"):format( victim_name, attacker_name )
for i=1, #players do
if players[ i ]:IsAdmin() then
players[ i ]:PrintMessage( HUD_PRINTTALK, str )
end
end
return true
end
hook.Add( "AddDeathNotice", "deathNotifyAdmins", death )
« Last Edit: July 12, 2010, 01:13:38 PM by Megiddo »
Experiencing God's grace one day at a time.

Offline BrightLiteFilms

  • Newbie
  • *
  • Posts: 2
  • Karma: 0
Re: Please Help!
« Reply #2 on: July 12, 2010, 10:59:11 AM »
Thank you! It is much appretiated. But, I don't mean to sound stupid, but I am new to LUA coding. What .lua file does it go into? :/

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: Please Help!
« Reply #3 on: July 12, 2010, 11:35:26 AM »
It's fine, everyone has to start somewhere.. But you would want to put this into its own file.

Create a file called deathnotifyadmin.lua and place it in your garrysmod/lua/autorun folder.

also... sorry to step on your toes Meg.. but this would be a more optimal way of doing it..

Code: [Select]
function PlayerDeathAdminNotify( victim, weapon, killer )
if not victim:IsPlayer() or not killer:IsPlayer() then return end
local str = victim:GetName() .. " was killed by " .. killer:GetName() .. "."
for _, v in pairs( player.GetAll() ) do
if v:IsAdmin() then
v:PrintMessage( HUD_PRINTTALK, str )
end
end
end
hook.Add( "PlayerDeath", "PlayerDeathAdminNotify", PlayerDeathAdminNotify )
« Last Edit: July 12, 2010, 11:53:50 AM by MrPresident »

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Please Help!
« Reply #4 on: July 12, 2010, 11:45:37 AM »
also... sorry to step on your toes Meg.. but this would be a more optimal way of doing it..

Code: [Select]
function PlayerDeathAdminNotify( victim, weapon, killer )
if not victim:IsPlayer() or not killer:IsPlayer() then return end
local str = victim:GetName() .. " was killed by " .. killer:GetName() .. "."
for _, v in pairs( player.GetAll() ) do
if v:IsAdmin() then
v:PrintMessage( HUD_PRINTTALK, str )
end if
end
end
hook.Add( "PlayerDeath", "PlayerDeathAdminNotify", PlayerDeathAdminNotify )

No problem, though you do have an 'end if' in there, and you should be returning to make it not show on the upper right. :)

I'd disagree on the use of pairs, but when we're talking about a difference of a few milliseconds every minute, it hardly matters.
Experiencing God's grace one day at a time.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: Please Help!
« Reply #5 on: July 12, 2010, 11:53:00 AM »
Oh, I am used to VBasic.. lua is still slowly trickling back to me.. but about the returning.. it wouldn't stop it from showing up using this hook. I didn't know he wanted it to block the death notifications.. I just thought he wanted it to ADDITIONALLY display in the chat for admins.

My function will not stop the death notifications in the upper right corner.

Also.. I'll fix the code.. opps :)

Sorry to ninja this thread a little, but what is the difference in you using local instead of function for your function? Does it just restrict it to that lua file? Because if that's the case then I just learned something new today.. also with the difference in for loops, I can't imagine that the difference would even be that great.
« Last Edit: July 12, 2010, 11:57:34 AM by MrPresident »

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Please Help!
« Reply #6 on: July 12, 2010, 01:12:40 PM »
Oh, I am used to VBasic.. lua is still slowly trickling back to me.. but about the returning.. it wouldn't stop it from showing up using this hook. I didn't know he wanted it to block the death notifications.. I just thought he wanted it to ADDITIONALLY display in the chat for admins.

My function will not stop the death notifications in the upper right corner.

Also.. I'll fix the code.. opps :)

Sorry to ninja this thread a little, but what is the difference in you using local instead of function for your function? Does it just restrict it to that lua file? Because if that's the case then I just learned something new today.. also with the difference in for loops, I can't imagine that the difference would even be that great.

'local' has the affect of declaring a variable's existence from the point it was declared to the end of the block (usually a file or do/then ... end). Since functions are first class variables, the same is true with them, a local function can be used any point after it's declared. This means that if you want two local functions to be able to call each other, you need a bit of a workaround (see code for 'ulx maul').

As far as loops, I've always been pushing people to use ipairs wherever possible instead of pairs, but for some reason ipairs doesn't perform any better than pairs (even checking out the lua source code, I don't understand why this is the case). You can, however, use a "for i=1, #t do ... end" loop, which iterates ~2x faster. See this thread: I didn't verify all the data there but from what I could tell in my quick tests his data was pretty good. Actually, I'd recommend 100% against using ipairs anymore since it's being removed from Lua 5.2 (probably because of the performance reason, they want you to use fori instead).
Experiencing God's grace one day at a time.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Please Help!
« Reply #7 on: July 12, 2010, 03:41:32 PM »
* JamminR followed this thread moved to Off-Topic.
* JamminR considers moving this thread from Off-Topic to Developers Corner.
:P
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Please Help!
« Reply #8 on: July 12, 2010, 04:19:38 PM »
Ah, forgot to mention that "local function x() end" is just syntactic sugar for "local x; x = function() end", likewise when you say "function x() end" you're really saying "x = function() end". So... that actually means that if you do "local x; function x() end" x is a local function (which I never really thought about before). Cool :)
Experiencing God's grace one day at a time.