• Lua Questions
    8 replies, posted
  • Avatar of Blaxus
  • Hey Guys, Ok, so i am pretty new to gmod, but i am not to scripting. Anyways, i was thinking let my try something out. So i want to make a basic Clientside only script. I was on a CSS server once and they had something called "yturl" also known as youtube url. Basically what it does is if you type: !yturl -_WHAbikzf4 then it would open it in a small window and it would start playing the youtube url [url]http://www.youtube.com/watch?v=-_WHAbikzf4[/url] this one then. I have looked around the wiki and i found this, which i still need to test. [url]http://wiki.garrysmod.com/?title=Panel.OpenURL[/url] So now i want to know. Is... What kind of command do i use to check if i typed: "!yturl -_WHAbikzf4" I was thinking maybe of checking if the console wrote it and then open that and. Of course i want to be able to close the window without the music stopping. So the window needs to be "hidden" or 100% see through or something. Anyways, i am hoping some people can launch me into the right direction. I hope i gave enough information so you guys can help me out. Best Regards Blaxus
  • Avatar of ¦FlapJack¦
  • You will need a OnPlayerChat hook, and the HTML derma controls. Unfortunately, HTML does not refresh the page without user input (So you need to use the laggier and hackier method of changing the size on think; unless you are going to think about using AzuiSleet's Chrome module.
  • Avatar of Blaxus
  • Ok so i got it work, but to do it again i need to close the window when the song has ended. Here is my code... [code]--[[ ============================ Product: Youtube Player Author : Blaxus Version: 0.1 ============================ ]] // Sart function Play Youtube Url function playturl(player, text, team, dead) if player == LocalPlayer() then // if player said !yturl activate controle if string.sub(text,0,6) == "!yturl" then // Variable Containing the link to the youtube url tur = string.sub(text,8,19) // Make the panel HTMLTest = vgui.Create("HTML") // Open the desired link HTMLTest:OpenURL("http://www.youtube.com/watch?v=" .. tur .. "") // Print in console what link we opened print("Youtube Gmod Player Is now opening: http://www.youtube.com/watch?v=" .. tur .. "") end // Check if user wants to stop playing if string.sub(text,0,3) == "!sp" then tur = string.sub(text,0,3) HTMLTest:clear("HTML") end // close if localplayer end // Close function end // Hook the actions hook.Add("OnPlayerChat" , "playturl" , playturl)[/code] I keep getting Hook 'playturl' Failed: autorun/client/yturl.lua:34: attempt to call method 'clear' (a nil value) i used "html" this time, but before it gave the same error and it was just: HTMLTest:clear()
  • Avatar of ¦FlapJack¦
  • HTMLTest:Clear() Lua is case sensitive. Although, I'm not sure this will achieve the end result you desire; it only says it clears text. I've never tried this method though (I normally open a blank URL to do this) If it does work, this could be very interesting.
  • Avatar of Blaxus
  • Your right, it was Case sensetive, however, the console returns to me: HTML:Clear doesn't work right now (Use SetHTML) But when i do any of these, my entire script does not work anymore. HTMLTest::SetHTML() HTMLTest::SetHTML("") HTMLTest::SetHTML( "<p>Youtube Player Stopped!</p>" ) EDIT: Sorry my bad, i had double times this "::" which caused the error. It is fully working now, Anyone who wants to use this, feel free to do so. Usage: type these commands ingame Play Youtube Song: [b]!yturl *link of youtube code*[/b] Stop Playing: [b]!sp[/b] Example: !yturl SpkBVFo-fWE will start playing this link: [url]http://www.youtube.com/watch?v=[/url][b]SpkBVFo-fWE[/b] everything behind: watch?v= is what you need to copy, and then it will start playing. I have no control over the volume though. Complete Script: [code]--[[ ============================ Product: Youtube Player Author : Blaxus Version: 0.1 ============================ ]] // Sart function Play Youtube Url function playturl(player, text, team, dead) if player == LocalPlayer() then // if player said !yturl activate controle if string.sub(text,0,6) == "!yturl" then // Variable Containing the link to the youtube url tur = string.sub(text,8,19) // Make the panel HTMLTest = vgui.Create("HTML", DPanel) // Open the desired link HTMLTest:OpenURL("http://www.youtube.com/watch?v=" .. tur .. "") // Print in console what link we opened print("Youtube Gmod Player Is now opening: http://www.youtube.com/watch?v=" .. tur .. "") end // Check if user wants to stop playing if string.sub(text,0,3) == "!sp" then // Close Window HTMLTest:SetHTML( "<p>Youtube Player Stopped!</p>" ) end // close if localplayer end // Close function end // Hook the actions hook.Add("OnPlayerChat" , "playturl" , playturl)[/code] Save as "yturl.lua" in "C:\Program Files\Steam\steamapps\*username*\garrysmod\garrysmod\lua\autorun\client" Have fun listening. :) And thanks FlapJack ;)
  • Avatar of Blaxus
  • Yes, but then you would have to load google first, ok it is not a slow site. But that would be unnecessary because you asked it to stop to the player. Not to visit google. If google at the time of your visit has a problem of some sorts it could cause lagg as your player is trying to reach that website. If i am correct.
  • Avatar of Blaxus
  • Console returns to me, "not opening: about:blank" But like i said before. I got it to work with SetHTML :)