Author Topic: Lua n00b questions  (Read 18991 times)

0 Members and 3 Guests are viewing this topic.

Offline krooks

  • Sr. Member
  • ****
  • Posts: 382
  • Karma: 32
  • I don't like video games.
    • Diamond Krooks
Re: Lua n00b questions
« Reply #30 on: January 19, 2013, 12:25:29 PM »
Ok, so I've really built upon my !snr command for TTT. This code works just fine as is, and I'm pretty excited, because it has built in ban features!
http://pastebin.com/q578QtGM

It could probably look better, or be more efficient, I'm sure.

But I am still having issues echoing what is happening to said players via chat, I've use ULX commands, and also built in gmod chat commands. I can't figure out how to target everyone, since "v" only targets the selected player and "target_plys" targets the selected group.

I'd like everyone to know what is happening so that I don't have to manually write "the RDM'er is being dealt with" when ppl are crying about RDM.
My TTT server. Join the fun!

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Lua n00b questions
« Reply #31 on: January 19, 2013, 01:17:01 PM »
But I am still having issues echoing what is happening to said players via chat, I've use ULX commands, and also built in gmod chat commands. I can't figure out how to target everyone, since "v" only targets the selected player and "target_plys" targets the selected group.

I'd like everyone to know what is happening so that I don't have to manually write "the RDM'er is being dealt with" when ppl are crying about RDM.

http://ulyssesmod.net/docs/files/lua/ulib/shared/messages-lua.html#tsay
Not sure why you'd have trouble. As long as you run tsay from the server, and leave the target nil, it would print to everyone's chat and console.

ULib.tsay( , "Message to all players" )
Above would work. If you like placeholders for nil, you could actually type nil, or use a known nil variable. Ulysses often uses _
ULib.tsay( _, "Message to all players" )
« Last Edit: January 19, 2013, 01:28:58 PM by JamminR »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline krooks

  • Sr. Member
  • ****
  • Posts: 382
  • Karma: 32
  • I don't like video games.
    • Diamond Krooks
Re: Lua n00b questions
« Reply #32 on: January 21, 2013, 01:56:08 PM »
Ugh, and it says it right in the documentation.  :-X
Thanks for putting up with me. I'm going to write a couple more TTT specific commands and release a ULX TTT command pack soon (my first official release! woo!)
My TTT server. Join the fun!

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Lua n00b questions
« Reply #33 on: January 21, 2013, 03:40:12 PM »
Ugh, and it says it right in the documentation.  :-X
Thanks for putting up with me.<clip> release a ULX TTT command pack soon (my first official release! woo!)
No worries. Makes me use my brain to assist someone actually coding.
I've just not had motivation for lua projects of my own in years.
Helping others lets me live vicariously in the Gmod lua code world. :)

We look forward to your contributions.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline krooks

  • Sr. Member
  • ****
  • Posts: 382
  • Karma: 32
  • I don't like video games.
    • Diamond Krooks
Re: Lua n00b questions
« Reply #34 on: January 21, 2013, 03:51:55 PM »
Well it doesn't go unappreciated. I'm the same way, though. I love helping people on forums, I've got a few where I help out with design/ web related things, it's always nice, and as I become more comfortable with lua, I'll probably be doing the same.
My TTT server. Join the fun!

Offline krooks

  • Sr. Member
  • ****
  • Posts: 382
  • Karma: 32
  • I don't like video games.
    • Diamond Krooks
Re: Lua n00b questions
« Reply #35 on: January 26, 2013, 03:42:39 PM »
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: [Select]
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 )
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
My TTT server. Join the fun!

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Lua n00b questions
« Reply #36 on: January 26, 2013, 05:20:02 PM »
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?
« Last Edit: January 26, 2013, 05:39:09 PM by JamminR »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline krooks

  • Sr. Member
  • ****
  • Posts: 382
  • Karma: 32
  • I don't like video games.
    • Diamond Krooks
Re: Lua n00b questions
« Reply #37 on: January 27, 2013, 12:00:51 AM »
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
« Last Edit: January 27, 2013, 12:40:43 AM by krooks »
My TTT server. Join the fun!

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Lua n00b questions
« Reply #38 on: January 27, 2013, 07:28:34 AM »
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
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline krooks

  • Sr. Member
  • ****
  • Posts: 382
  • Karma: 32
  • I don't like video games.
    • Diamond Krooks
Re: Lua n00b questions
« Reply #39 on: January 27, 2013, 09:43:08 AM »
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
My TTT server. Join the fun!

Offline krooks

  • Sr. Member
  • ****
  • Posts: 382
  • Karma: 32
  • I don't like video games.
    • Diamond Krooks
Re: Lua n00b questions
« Reply #40 on: February 05, 2013, 10:45:50 PM »
Hey all, been a busy couple weeks, back with a new code:
Code: [Select]
function GlowT(ply)
if IsValid(LocalPlayer()) and LocalPlayer():IsActiveTraitor() then
for _, v in pairs (player.GetAll()) do
if v:IsActiveTraitor() then
effects.halo.Add({v}, Color(255,10,0), 2, 2, 2, true, true)
end
end
end
end
hook.Add("Think", "GlowT", GlowT)

I wrote this to make T buddies glow, it works, and I've been running it for a few weeks now, but I've noticed it crashes players every so often. It will crash me almost every time a map changes, and I'm a T the first round.

Is there anything that stands out to anyone that I might be able to optimize or that could be done better?

===
EDIT

On the wiki ( http://wiki.garrysmod.com/page/Libraries/halo/Add ) it shows them using "PreDrawHalos" as the hook, I'll test with that and give results.
« Last Edit: February 06, 2013, 02:00:51 PM by krooks »
My TTT server. Join the fun!

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Lua n00b questions
« Reply #41 on: February 06, 2013, 02:49:18 PM »
What I see -
Optimization thoughts -
You check for valid player, then if they are an active traitor. - Does the TTT IsActiveTraitor function not already do the valid player check? If so, seems redundant.
Your using 'think' hook. That's fine when absolutely necessary, but, code must be optimized like crazy. Think is called every frame.
Every frame, you're asking the server to cycle through all players, verify they are traitor, AND if so add a halo.
I've no experience with the halo effect, but, if it will add itself to the player once and stay with them until you tell it otherwise, then don't use think to add it.
Find the hooks/functions, if there are custom ones, where TTT actually updates the player to become 'Traitor' (team change?), THEN add the halo effect (or remove, if left)
And, even less familiar to me, yes, check out the wiki link you provided, and see if you can make glow's 'view' only.

General oddity -
You write GlowT(PLY) - do you ever actually call the function passing it a object(player or otherwise)?
Doesn't seem to be a ply object used in the rest of the function.

Possible crash ??
During your code, you check yourself (local player) to see if you are valid.
THEN, you grab all players, check if they are traitor, then apply the effect.
I get the idea that, pertaining to my original "does IsActiveTraitor check player validity?" question above, the answer is no.
So, I'm thinking it may be crashing, especially during a map change, when the code is trying to apply an effect to a player that just isn't quite valid yet, or if mid game, trying to apply to a player that left/isn't valid but is still queued up in the for loop.
« Last Edit: February 06, 2013, 02:51:22 PM by JamminR »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline krooks

  • Sr. Member
  • ****
  • Posts: 382
  • Karma: 32
  • I don't like video games.
    • Diamond Krooks
Re: Lua n00b questions
« Reply #42 on: March 01, 2013, 04:34:13 PM »
I am adding a tab to Pointshop that displays a webpage.
Code: [Select]
local XTab = vgui.Create( "DHTML" )
XTab:SetSize( self:GetWide() - 20, self:GetTall())
XTab:OpenURL( "http://XXXXX.com/X.php" )

tabs:AddSheet('Hello There', XTab, 'icon16/badge.png', false, false, '')
It displays properly, scrolls properly, <input type="submit"> is clickable, links are clickable;
but I can't use dropdown <select> menus, and <input type="text"> does not take focus.

I can select the text within the text box with the cursor, but when I type nothing shows up in the box, instead it just executes the game binds like walk, say, etc.

Someone suggested toggling "mouse and keyboard clickers" first.
So I added all of these separately, and together with no luck:
Code: [Select]
XTab:SetMouseInputEnabled(true)
XTab:SetKeyboardInputEnabled(true)
gui.EnableScreenClicker(true)

If I XTab:MakePopup() I am able to enter text in the <input> (delete key doesn't work) but the <select> box still doesn't work at all.
And I'd rather this not be a popup, because of how pointshop is already built.

Any ideas?

note, I've also tried XTab = vgui.Create( "HTML" ), (didn't work) but from the wiki it sounds like DHTML is best.
My TTT server. Join the fun!

Offline krooks

  • Sr. Member
  • ****
  • Posts: 382
  • Karma: 32
  • I don't like video games.
    • Diamond Krooks
Re: Lua n00b questions
« Reply #43 on: December 05, 2013, 12:03:18 AM »
Hiya! Been super busy lately but recently got back into messing with lua stuffs for my server, quick question:

What's the best way to go about calling ulx.playsound (or other ulx functions like it) within another script that is called from a hook event?
Currently it just looks like ulx.playsound(nil,"blah/blah.mp3")
The sound plays, but I'm getting an error because it's not being called by a player, so the fancy logging gets confused.

Thankyuh! Hope you've all been well
« Last Edit: December 05, 2013, 12:05:24 AM by krooks »
My TTT server. Join the fun!

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Lua n00b questions
« Reply #44 on: December 05, 2013, 06:22:13 AM »
Welcome back. You've been missed.
One question - do you really need logging of the command, if being used in a hook?
I imagine not needing it for a hook event (such as somebody said something, did something, do you really need "console played sound <x>" in logging/notify when the something happened.?

EDIT - to save you time -
If you need the same log the command does, use actual command, not function. RunConCommand (or whatever it is now) ("ulx playsound " .. your_sound)
The actual command will determine it's the console and pass/log it as calling_ply.
If you don't need the log, verify your sound exists on the server and then use the ULib usermessage sound command (actually used within ulx playsound itself)
Code: [Select]
umsg.Start( "ulib_sound" )
umsg.String( Sound( your_sound ) )
umsg.End()

« Last Edit: December 05, 2013, 06:50:31 AM by JamminR »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming