General > Developers Corner
Lua n00b questions
krooks:
I found a bug with my script: http://pastebin.com/q578QtGM
What happens is, if _anyone_ disconnects while someone has 2 slays on them, they will get banned.
So I've changed the code to:
--- Code: ---function snrdisconnect(v)
if v.totalz == 2 and v.snr then
ULib.ban(v, 10080, "[Auto SNR] RDM and Run.")
ulx.warn(calling_ply, v, "[Auto SNR] RDM and Ran (one week ban).")
end
end
hook.Add( "PlayerDisconnected", "snrdisconnect"..v:Nick(), snrdisconnect )
--- End code ---
But adding the v doesn't seem to help targeting for some reason, and maybe this is an issue because I'm testing with bots?
(also, Mr. President should be proud, I've built the script to work with his warn system ;D
JamminR:
Krooks, your new function.. is it inside your "ulx.dksnr" function and for loop, or no?
Reason I ask...though your unique naming method ( "blah"..v:Nick() ), in theory, should work while within your ulx.dksnr function 'for' loop, once you move it outside of either, lua will have little idea what 'v' is.
You use it in naming, and it may error out.
Any errors during loading of this on server end?
Or while attempting to execute the function?
krooks:
Yes, it is, here's the whole code as it is currently: http://pastebin.com/b0BdF2UP
You can see how I had the old code there as well, just commented out.
edit
Also, no errors. I'm going to mess with it for a bit more right now, will report if I come up with anything.
edit
Did some testing with willing real-live helpers, and it seems to be ok with the new code. Thanks for taking a look
JamminR:
Personally, I don't understand why you're adding a disconnect hook for every single person you're watching (and maybe even for the TTT round start).
Once the player object 'v' gets assigned info to it's table...even if in another function, that player object info should be able to be looked up.
It would seem to me that individual hooks for each player, especially if not needed, would use more server resources than necessary.
For optimization, I'd work on just adding 'one' playerdisconnect hook, then monitoring each disconnecting player within that.
But that's me.
Continuing your way, I'd recommend finding a way to use hook.Remove when you ban and/or reset each player's 'watching'
http://wiki.garrysmod.com/page/Libraries/hook/Remove
krooks:
Interesting thought, I'll explore doing it that way because it sounds a lot less taxing.
The reason I'm doing it this way is because I'm n00b and it was the first idea that popped in my head to remedy the problem :P
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version