*snip*
[editline]10th February 2015[/editline]
I'm trying to restrict this TTS system to one class.
[lua]local accents = {
"http://tts.peniscorp.com/speak.lua?"
}
local wait = false
local channels = {}
local function playvoice(ply,text,accent,speed)
if (not ply:Team() == TEAM_ASTRO) then return end
if wait then
accent = "http://tts.peniscorp.com/speak.lua?"
end
sound.PlayURL(accent..text,"3d noplay",function(channel,errorid,errorname)
if channel == nil || errorid != nil || errorname != nil then --peniscorp backup; google is upset
if wait == false then
wait = true
timer.Simple(125,function() wait = false end)
playvoice(ply,text,accent,speed)
end
return
end
channel:SetPos(ply:GetPos(),Vector(0,0,0))
channel:Set3DFadeDistance(300,9999999999)
channel:SetPlaybackRate(math.Clamp(.5+speed,.5,2))
channel:Play()
table.insert(channels,{channel,ply})
end)
end
hook.Add("Think","TTSThink",function()
for k, v in pairs(channels) do
if !v[1]:IsValid() then table.remove(channels,k) return end
if v[2] == nil ||
v[1]:GetState() != GMOD_CHANNEL_PLAYING ||
v[1]:GetTime() >= v[1]:GetLength() then
v[1]:Stop()
table.remove(channels,k)
return
end
v[1]:SetPos(v[2]:GetPos(),Vector(0,0,0))
end
end)
hook.Add("OnPlayerChat","TTSPlayerChat",function(ply,text,team,dead)
--firstly, checking for popular gamemode limitations
local dotts = true
if engine.ActiveGamemode() == "terrortown" then
if dead then dotts = false end
if ply.IsSpec != nil && ply:IsSpec() then dotts = false end
end
if engine.ActiveGamemode() == "darkrp" then
if text[1] == "/" then dotts = false end
if ply:GetPos():Distance(LocalPlayer():GetPos()) > 500 then dotts = false end --250 = default chat range
end
if dotts then
local speed,accent,nick = 1, accents[1], ply:Nick()
local nlen = #nick
local vowels, vow, notvow, vrat = {"a","e","i","o","u","y"}, 0, 0, 1
for i = 1, nlen do
if table.HasValue(vowels,nick[i]) then vow = vow+1 else notvow = notvow+1 end
end
if vow == 0 then notvow = nlen end
vrat = vow/notvow
accent = accents[math.Clamp(vow,1,#accents)]
speed = vrat
playvoice(ply,text,accent,speed)
end
end)[/lua]
I put the code right underneath the playvoice function. The code itself works still, but the restriction doesn't; I can still use the TTS on all teams. Sometimes, it doesn't even work, but this might be latency issues?
[code] function SWEP:DrawWorldModel()
local Laser = Material( "cable/redlaser" )
local cdTr = util.TraceLine( {
start = self.Owner:EyePos( ),
endpos = self.Owner:EyePos( ),
mask = MASK_SHOT,
filter = self.Owner
} )
local i = 0
local targetLength = math.abs( math.sin( CurTime( ) ) * 512 )
while !cdTr.Hit do
local blah = cdTr.HitPos
cdTr = util.TraceLine( {
start = cdTr.HitPos,
endpos = cdTr.HitPos + Angle( 0, 0, 0 ):Forward( ) * ( ( targetLength / 32 ) ) + Vector( 0, 0, ( i * -1 ) ),
mask = MASK_SHOT,
filter = self.Owner
} )
i = i + 1
render.DrawBeam( blah, cdTr.HitPos, 1, 1, 1, Color( 255, 0, 255, 255 ) )
end
local bulletTr = { ["HitPos"] = cdTr.HitPos, ["HitNormal"]=cdTr.HitNormal, ["Entity"]=cdTr.Entity }
render.DrawBeam( self.Owner:EyePos( ), self.Owner:EyePos( ) + Angle( 0, 0, 0 ):Forward( ) * targetLength, 1, 1, 1, Color( 0, 0, 255, 255 ) )
print( ( ( self.Owner:EyePos( ) + Angle( 0, 0, 0 ):Forward( ) * targetLength ) - bulletTr.HitPos ).x )
self:DrawModel( )
end[/code]
I need the pink line to match the blue line. It's a simulation of bullet drop, and the way it's supposed to work is the curved pink line will meet the ground at the same length as the blue line. I have no idea how to do this though.
Ideally, the trace would be broken up into 32 units and check to see if it's hit something. If it doesn't, it drops a certain amount and repeat until it hits the ground at the target length away. I'm using a sinewave simply for testing.
How are tables numerically indexed?
Table: { "string1", "string2", "string3" }
Would those be indexed as 1, 2, 3, or would they be 0, 1, 2 ?
1, 2, 3
[editline]10th February 2015[/editline]
How to test something like this:
[lua]
for k,v in ipairs({"string1", "string2", "string3"}) do -- pairs or ipairs
print(k,v)
end
[/lua]
Remember you can test default lua code on [url]http://www.lua.org/cgi-bin/demo[/url]
[QUOTE=WalkingZombie;47117537]How are tables numerically indexed?
Table: { "string1", "string2", "string3" }
Would those be indexed as 1, 2, 3, or would they be 0, 1, 2 ?[/QUOTE]
Lua is hipster language and its indexes start at 1 instead of 0 like every other language.
[QUOTE=zerf;47117576]1, 2, 3
[editline]10th February 2015[/editline]
How to test something like this:
for k,v in ipairs({"string1", "string2", "string3"}) do -- pairs or ipairs print(k,v)end
Remember you can test default lua code on [URL]http://www.lua.org/cgi-bin/demo[/URL][/QUOTE]
Thanks a lot. Before I got the answer, I took a little shortcut to do what I wanted. table.GetFirstKey( table )
Sincerely, though, thank you very much!
[QUOTE=bobbleheadbob;47117631]Lua is hipster language and its indexes start at 1 instead of 0 like every other language.[/QUOTE]
And in every other language,
For ( int x = 0; x<= arr.count() - 1; x++ )
[QUOTE=Kogitsune;47118091]And in every other language,
For ( int x = 0; x< arr.count() - 1; x++ )[/QUOTE]
That'd be true if you used a less than or equal to sign.
[QUOTE=Kogitsune;47118091]And in every other language,
For ( int x = 0; x<= arr.count() - 1; x++ )[/QUOTE]
I actually like lua's method MUCH better. For loops in other languages are oddly named, since you have to define the actual point of it yourself (and can in fact make use of it for something completely different). It's just a fancy while loop.
A for loop should be specific for FOR loops or be named something different!
/rant
Is there any way to get the maximum velocity of a vehicle in GMod Lua ?
Anyone know what to use to check which buttons are being pressed on a controller and things related to that?
I'm messing around with my controller and it works fine by default, but I don't know how to do anything to it in Lua. Is this possible? Also, it'd be really helpful to know how far to the left or right the analog sticks are for example like this: [URL="http://visualspicer.s3.amazonaws.com/client/forza5/telemitry.jpg"]http://visualspicer.s3.amazonaws.com/client/forza5/telemitry.jpg[/URL] at the top where it says steering.
Yeah yeah, I know... Why would you use a controller on Garry's Mod.
[editline]11th February 2015[/editline]
[QUOTE=Yuri6037;47119047]Is there any way to get the maximum velocity of a vehicle in GMod Lua ?[/QUOTE]
[LUA] PrintTable(physenv.GetPerformanceSettings()) [/LUA]
and use
[LUA]
Settings = {}
Settings.MaxVelocity = 60000
physenv.SetPerformanceSettings(Settings)
[/LUA]
to change it.
That's from what I remember. I'm pretty sure vehicles don't have their own velocity. Just how fast they reach it. Because I've noticed that all vehicles, even a Bugatti for example, cap out at the same area which was like [I]way[/I] below 200 MPH if you convert it.
[QUOTE=WitheredPyre;47114408]*snip*
[editline]10th February 2015[/editline]
I'm trying to restrict this TTS system to one class.
[lua]
hook.Add("OnPlayerChat","TTSPlayerChat",function(ply,text,team,dead)
--firstly, checking for popular gamemode limitations
local dotts = true
if engine.ActiveGamemode() == "terrortown" then
if dead then dotts = false end
if ply.IsSpec != nil && ply:IsSpec() then dotts = false end
end
if engine.ActiveGamemode() == "darkrp" then
if text[1] == "/" then dotts = false end
if ply:GetPos():Distance(LocalPlayer():GetPos()) > 500 then dotts = false end --250 = default chat range
end
if dotts then
local speed,accent,nick = 1, accents[1], ply:Nick()
local nlen = #nick
local vowels, vow, notvow, vrat = {"a","e","i","o","u","y"}, 0, 0, 1
for i = 1, nlen do
if table.HasValue(vowels,nick[i]) then vow = vow+1 else notvow = notvow+1 end
end
if vow == 0 then notvow = nlen end
vrat = vow/notvow
accent = accents[math.Clamp(vow,1,#accents)]
speed = vrat
if ply:Team() == TEAM_ASTRO then playvoice(ply,text,accent,speed) end --Change it to this, remove the check in the playvoice function
end
end)[/lua]
I put the code right underneath the playvoice function. The code itself works still, but the restriction doesn't; I can still use the TTS on all teams. Sometimes, it doesn't even work, but this might be latency issues?[/QUOTE]
and yes, the TTS does not play when the API is under high load, which is most of the time due to my own TTS addon
[QUOTE=TheLuaNoob;47119067]Anyone know what to use to check which buttons are being pressed on a controller and things related to that?
I'm messing around with my controller and it works fine by default, but I don't know how to do anything to it in Lua. Is this possible? Also, it'd be really helpful to know how far to the left or right the analog sticks are for example like this: [URL="http://visualspicer.s3.amazonaws.com/client/forza5/telemitry.jpg"]http://visualspicer.s3.amazonaws.com/client/forza5/telemitry.jpg[/URL] at the top where it says steering.
Yeah yeah, I know... Why would you use a controller on Garry's Mod.[/QUOTE]
[url=http://wiki.garrysmod.com/page/Enums/KEY]here[/url] is a list of enums (KEY_X*) that can be used with gamepads, but for your second question, you have to do something like this:
[lua]local oang = Angle()
hook.Add("InputMouseApply", "aeiou", function(cmd, x, y, ang)
x, y = math.AngleDifference(oang.y, ang.y), math.AngleDifference(ang.p, oang.p)
oang = ang
end)[/lua]
and mess with it from there
Does anyone know whats going on with Entity:SetSubMaterial and Entity:GetSubMaterial? They're in the wiki but don't appear to be in-game. Are they slated for the next update or depreciated?
[QUOTE=huntskikbut;47121180]Does anyone know whats going on with Entity:SetSubMaterial and Entity:GetSubMaterial? They're in the wiki but don't appear to be in-game. Are they slated for the next update or depreciated?[/QUOTE]
They will be available in the next update. They are currently only available in the Dev branch.
[QUOTE=Robotboy655;47121201]They will be available in the next update. They are currently only available in the Dev branch.[/QUOTE]
Alright, thanks! We really need update number tags on the wiki
Hey guys. I can't find a hook to directly disable shooting on default HL2 weapons. Anyone know what's the best way around?
How do you get a panel's size after docking it?
panel:GetSize() returns 64, 24 after doing panel:Dock(FILL), which is obviously incorrect. Unless that's how it's supposed to behave in case you want to undock.. Regardless, I would still like to get the current size of docked panels without a nasty hack in performlayout.
[code] local CurrentSizeX = 128 + 32 - 8
local CurrentSizeY = 64*0.75
local OriginalSizeX = 2048*0.75
local OriginalSizeY = 64*0.75
local Mod = (LocalPlayer():EyeAngles().y)/90
local UStart = (CurrentSizeX / OriginalSizeX)*Mod
local VStart = 0
local UEnd = ( CurrentSizeX / OriginalSizeX ) + ((CurrentSizeX / OriginalSizeX)*Mod)
local VEnd = 1
surface.SetMaterial(CompassCord)
surface.DrawTexturedRectUV(256 + 128 - 16 - 8,ScrH() - 64, CurrentSizeX, CurrentSizeY, UStart, VStart, UEnd, VEnd )[/code]
I'm having a problem with DrawTextureUV
Basically the texture is cut when the yaw is around -45 degrees and jumps when at 180 degrees
I don't know how to fix this
[QUOTE=xaviergmail;47121723]How do you get a panel's size after docking it?
panel:GetSize() returns 64, 24 after doing panel:Dock(FILL), which is obviously incorrect. Unless that's how it's supposed to behave in case you want to undock.. Regardless, I would still like to get the current size of docked panels without a nasty hack in performlayout.[/QUOTE]
Have you tried waiting a frame? Print the size in the docked panel's PerformLayout.
[QUOTE=VIoxtar;47121441]Hey guys. I can't find a hook to directly disable shooting on default HL2 weapons. Anyone know what's the best way around?[/QUOTE]
You can either:
1) Remove bullets with GM:FireBullet
2) Prevent +attack bind from being usable with GM:PlayerBindPress ( +attack in console will still work )
3) Try Weapon:SetNextPrimaryFire(CurTime() + 8888)
4) Remove all ammo?
Oh hey, quick question i'm gonna ask way before I can apply it. My resolution is 1920x1080, but I want to take a screenshot at 3840x2160 (2x resolution). Well, there are ways to do this, but for someone who doesn't know those ways, or can't manage to do them? What is the question, then?
RT Textures are glorious. Is it possible to render an RT texture at a much higher resolution than the actual client's screen?
[QUOTE=WalkingZombie;47124198]Oh hey, quick question i'm gonna ask way before I can apply it. My resolution is 1920x1080, but I want to take a screenshot at 3840x2160 (2x resolution). Well, there are ways to do this, but for someone who doesn't know those ways, or can't manage to do them? What is the question, then?
RT Textures are glorious. Is it possible to render an RT texture at a much higher resolution than the actual client's screen?[/QUOTE]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/GetRenderTargetEx]Global.GetRenderTargetEx[/url] with sizeMode set to RT_SIZE_OFFSCREEN should do.
render.Capture has a bug where if you use a parameter greater than the game's resolution it'll die.
[QUOTE=Willox;47124223][IMG]http://wiki.garrysmod.com/favicon.ico[/IMG] [URL="http://wiki.garrysmod.com/page/Global/GetRenderTargetEx"]Global.GetRenderTargetEx[/URL] with sizeMode set to RT_SIZE_OFFSCREEN should do.
render.Capture has a bug where if you use a parameter greater than the game's resolution it'll die.[/QUOTE]
Hmm? Now wait, my intention was to save local copies of the larger screenshot. Are you saying that won't be possible, thanks to render.Capture?
[editline]12th February 2015[/editline]
[del]What of "render.CopyRenderTargetToTexture" ?[/del] couldn't find a way that I could change a texture into a jpg
[QUOTE=Robotboy655;47122726]You can either:
1) Remove bullets with GM:FireBullet
2) Prevent +attack bind from being usable with GM:PlayerBindPress ( +attack in console will still work )
3) Try Weapon:SetNextPrimaryFire(CurTime() + 8888)
4) Remove all ammo?[/QUOTE]
Thanks for these. Awesome tips, will give it a shot.
I feel like I am misunderstanding what order to place the points in for surface.polygon. I am trying to make a angled bar that needs to decrease along with the players health.
[IMG]http://i.gyazo.com/ccba5855c72f06c3ae212c6f4da83820.png[/IMG]
[lua]
local hpp = 100/100
local hadd = -30
local c = 10
local ang = math.rad( -70 )
local b = math.sin( ang )*c
local a = math.cos( ang )*c
local xp = ScrW()-300
local yp = ScrH()-200
local triangle = {
{ x = xp, y = yp },
{ x = (xp+250)*hpp, y = (yp+30)*hpp },
{ x = (xp+250+b)*hpp, y = (yp+40+a)*hpp },
{ x = xp+b, y = yp+10+a },
}
[/lua]
[QUOTE=WalkingZombie;47124608]Hmm? Now wait, my intention was to save local copies of the larger screenshot. Are you saying that won't be possible, thanks to render.Capture?
[editline]12th February 2015[/editline]
[del]What of "render.CopyRenderTargetToTexture" ?[/del] couldn't find a way that I could change a texture into a jpg[/QUOTE]
poster 2
[url]http://garry.tv/2012/02/25/poster-screenshots/[/url]
is there any way to make constraint.Axis behave more linear? Right now it's flimsy as fuck and bends in different directions if you apply some force and I just want the axis to rotate around its set axis without bending :pwn: Increasing the weight is a really bad solution as its for my airplanes. more weight = i need more lift to take off = weirder physics.. My "flight model" is not designed to accommodate wheels that are as heavy as the plane......
[QUOTE=Hoffa1337;47124819]is there any way to make constraint.Axis behave more linear? Right now it's flimsy as fuck and bends in different directions if you apply some force and I just want the axis to rotate around its set axis without bending :pwn: Increasing the weight is a really bad solution as its for my airplanes. more weight = i need more lift to take off = weirder physics.. My "flight model" is not designed to accommodate wheels that are as heavy as the plane......[/QUOTE]
That's just Source physics and I don't there's anything you can do about it.
Disclaimer: I don't ACTUALLY know what I'm talking about.
[QUOTE=Neat-Nit;47124812]poster 2
[URL]http://garry.tv/2012/02/25/poster-screenshots/[/URL][/QUOTE]
I feel like I've seen that somewhere else before. Well, now here come a few other problems I guess. 1: Where / how do I get that? 2: This camera in question would be something that's part of a gamemode; within a workshop entry. How can I legitimately / fairly include such a thing in that gamemode? 3: Uhh... can I use something from the workshop to save a file to the client?
Sorry, you need to Log In to post a reply to this thread.