[QUOTE=Rory;51776543][code]
function GM:Initialize()
CreateConVar("test_roundtime", "360", true, "Sets the time per round")
CreateConVar("test_preptime", "12", true, "Sets how long preparation takes")
CreateConVar("test_breaktime", "6", true, "Sets how long preparation takes")
end
-- More code in here, not applicable
local round = {}
round.intermission = GetConVar("test_breaktime"):GetInt()
round.time = GetConVar("test_roundtime"):GetInt()
round.prep_time = GetConVar("test_preptime"):GetInt()
round.in_progess = false
round.count = 0
round.timeleft = -1
round.status = "STALE"
[/code]
What am I doing wrong? First time making ConVar's. The idea is to let the server owner/admins set the times they want to use for said values.[/QUOTE]
You're creating the convars in Initialize which is called after the gamemode is loaded, however it looks like you're attempting to get the convars outside of any block probably meaning before they're created. That's where the index nil error is coming from because GetConVar returned nothing.
Just create the convars outside of any blocks.
Also CreateConVar returns the created convar object so you won't have to call GetConVar.
Edit: ninja'd
I have a question about Render Targets. I'm trying to create an animation system for Garry's Mod so cut-scenes can happen on the client's end. I wanted to take advantage of render targets, and while I did manage to get it to work, finding which hook to use has been troublesome.
Here's a short video showing the effect:
[video]https://youtu.be/67xLSy6MyAo[/video]
The trouble is that the hook I'm using is turned off while the main menu is visible, meaning the overlay won't be visible at all. That's a problem - I want it to be visible, even while the main menu is opened.
Here's the problems I've had with these hooks I've tried:
[U][B]CRASH[/B][/U]
PostDrawOpaqueRenderables
PreDrawEffects
RenderScreenspaceEffects
PostDrawEffects
PreDrawHUD
PostDrawHUD
[B][U]Doesn’t work[/U][/B]
HUDPaintBackground
[B][U]Doesn’t render while in main menu[/U][/B]
HUDPaint
[B][U]Renders over GUI[/U][/B]
DrawOverlay
Any ideas?
EDIT: Here's the script, if that helps.
[LUA]
AddCSLuaFile()
if not CLIENT then return end
local rt_cam_pos = Vector(-3057, -1471, -77)
local rt_cam_ang = Angle(0, 177, 0)
local rt_mat = Material("rt_test/rt_add")
local rt_tex = rt_mat:GetTexture("$basetexture")
hook.Add( "HUDPaint", "HUDPaint_RT_TEST", function()
local old_rt = render.GetRenderTarget()
render.SetRenderTarget(rt_tex)
local cam_data = {}
cam_data.angles = rt_cam_ang
cam_data.origin = rt_cam_pos
cam_data.fov = 9
cam_data.x = 0
cam_data.y = 0
cam_data.w = ScrW()
cam_data.h = ScrW()
render.RenderView(cam_data)
render.SetRenderTarget(old_rt)
render.SetMaterial(rt_mat)
render.DrawScreenQuad()
end)
[/LUA]
EDIT:
Here's also the VMT I made called rt_add:
[CODE]
"gmodscreenspace"
{
"$basetexture" "_rt_FullFrameFB1"
"$additive" 1
"$vertexcolor" 1
"$vertexalpha" 1
}
[/CODE]
[QUOTE=Moat;51740895]Is "sent" printing? Have you tried using a hook rather than how you're doing it now?
[editline]28th January 2017[/editline]
Try adding a hook with [IMG]http://wiki.garrysmod.com/favicon.ico[/IMG] [URL="http://wiki.garrysmod.com/page/GM/PlayerShouldTakeDamage"]GM:PlayerShouldTakeDamage[/URL] and check if the attacker's class is prop_physics or prop_dynamic. (Return false to not allow damage)
[editline]28th January 2017[/editline]
Have tried using [IMG]http://wiki.garrysmod.com/favicon.ico[/IMG] [URL="http://wiki.garrysmod.com/page/GM/PlayerFootstep"]GM:PlayerFootstep[/URL] to suppress the sound rather than changing their velocity?[/QUOTE]
Why should I remove the footstep sounds if I want footstep sounds?
Is there like a hook or something I can use to check if Lua was refreshed?
[QUOTE=txike;51779926]Is there like a hook or something I can use to check if Lua was refreshed?[/QUOTE]
You could...uh...call a function at the beginning of a file :L
[editline]5th February 2017[/editline]
Also read this
[url]http://xyproblem.info/[/url]
[QUOTE=LegoGuy;51780008]You could...uh...call a function at the beginning of a file :L
[editline]5th February 2017[/editline]
Also read this
[url]http://xyproblem.info/[/url][/QUOTE]
I don't mean 1 specific file, I mean for [B]any[/B] file.
[QUOTE=txike;51779926]Is there like a hook or something I can use to check if Lua was refreshed?[/QUOTE]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/OnReloaded]GM:OnReloaded[/url]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/WEAPON/OnReloaded]SWEP:OnReloaded[/url]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/ENTITY/OnReloaded]ENT:OnReloaded[/url]
[QUOTE=txike;51780016]I don't mean 1 specific file, I mean for [B]any[/B] file.[/QUOTE]
Your question sounds very X-Y problem-y
[editline]5th February 2017[/editline]
Like, why do you need this?
[QUOTE=LegoGuy;51780031]Your question sounds very X-Y problem-y
[editline]5th February 2017[/editline]
Like, why do you need this?[/QUOTE]
To see when a file on the server is updated.
[QUOTE=LegoGuy;51780031]Your question sounds very X-Y problem-y
[editline]5th February 2017[/editline]
Like, why do you need this?[/QUOTE]
You are blowing this so out of proportion. He asked for a simple hook.
[QUOTE=sannys;51780126]You are blowing this so out of proportion. He asked for a simple hook.[/QUOTE]
The problem with solving questions on here is that there are many ways to do something, but only one way is actually designed to solve the given problem, and other methods may even cause more. When someone asks to solve a specific problem, they are sometimes trying to solve a problem caused by solving another problem badly.
This is why it is important to make sure this isn't an X-Y problem, where a user has problem X causing problem Y, but only gives information pertinent to Y.
Txike's problem sounds very much like an X-Y problem. Why do you need to know if a file is being reloaded? If your implementation of something is correct, then you have no need to know if it is being reloaded, otherwise try instead solving the bad implementation, rather than the symptoms of the problem it is causing.
In any cause, here is an easy way to know if your file is being reloaded:
[lua]
if ( FILE_ALREADY_LOADED ) then
print( "This file is being reloaded" )
end
FILE_ALREADY_LOADED = true
[/lua]
The variable FILE_ALREADY_LOADED is only set after the check. Therefore, if it is true during the check, then the file is being reloaded. This method is standard practice in CPP, where header files may be included multiple times, causing redefinition problems, however, you don't know which file is including it first without following every include tree.
I solved my problem. The trick is to place the part where the RT is rendered to in a separate hook (PreRender works), and then render to the screen in the RenderScreenspaceEffects hook.
[QUOTE=James xX;51780185]words[/QUOTE]
It's not that I don't know what he's talking about. I know exactly what he's talking about. The thing is, he only asked for a hook's existence. The right thing to do is either inquire for more details or provide multiple solutions that fit better under different circumstances, not instantly accuse him of withholding information.
[quote]Why do you need to know if a file is being reloaded? If your implementation of something is correct, then you have no need to know if it is being reloaded[/quote]This is what I'm talking about. It's none of your business until there's actually a tangible reason to suspect that they might be doing something wrong. Is this a thing we're doing now? Just questioning every person in this thread on why they're trying to accomplish something because there might be a better way? You have no idea what he's doing in his script or why he needs that hook. A global being checked and created when a file is ran is not equatable to a hook that is called by the engine when a refresh has taken place. They can accomplish the same thing in many circumstances, but they [B]are not the same thing.[/B] Until there is reason to believe there is a better way to do something, you should assume the person requesting help knows what they're doing.
[QUOTE=sannys;51780400]It's not that I don't know what he's talking about. I know exactly what he's talking about. The thing is, he only asked for a hook's existence. The right thing to do is either inquire for more details or provide multiple solutions that fit better under different circumstances, not instantly accuse him of withholding information.
This is what I'm talking about. It's none of your business until there's actually a tangible reason to suspect that they might be doing something wrong. Is this a thing we're doing now? Just questioning every person in this thread on why they're trying to accomplish something because there might be a better way? You have no idea what he's doing in his script or why he needs that hook. A global being checked and created when a file is ran is not equatable to a hook that is called by the engine when a refresh has taken place. They can accomplish the same thing in many circumstances, but they [B]are not the same thing.[/B] Until there is reason to believe there is a better way to do something, you should assume the person requesting help knows what they're doing.[/QUOTE]
As in the quote you are using, I was giving my reason for suspecting it was an XY problem. If you need me to further elaborate:
The only reason you would need to know if a file is being reloaded is because their behaviour is being changed between reloads. If a file runs the same before and after a reload, then they are equivalent, and need no knowledge of a reload. This also explains the solution I provided; As files reload on a file by file basis, then it makes sense that he only needs to check a specific file if it is being reloaded.
To cut this short, there is no hook that tells you if a file has been reloaded, only entire gamemodes, entities or weapons.
I don't understand why you are defending Txike without understanding our reasons for saying he is having an XY problem. You say we are "accusing" him, as if our suggesting his problem might be one he hasn't considered is a bad thing. You say I have no bussiness asking, when I'm attempting to provide a solution and you aren't. You say I have no tangible reason (as if reasons are anything BUT tangible) to suspect he is doing something wrong, without reading my explination in the post you quoted.
TLDR: Feel free to defend a guy from immagined accusations, but atleast try and provide a solution yourself beforehand.
[QUOTE=James xX;51780443]The only reason you would need to know if a file is being reloaded is because their behaviour is being changed between reloads. If a file runs the same before and after a reload, then they are equivalent, and need no knowledge of a reload. This also explains the solution I provided; As files reload on a file by file basis, then it makes sense that he only needs to check a specific file if it is being reloaded.
To cut this short, there is no hook that tells you if a file has been reloaded, only entire gamemodes, entities or weapons.[/QUOTE]
He never asked how to check if a file was reloaded. He asked how to check if there was a lua refresh.
[quote]Is there like a hook or something I can use to check if Lua was refreshed?[/quote]
[QUOTE]I don't mean 1 specific file, I mean for [B]any[/B] file.[/QUOTE]
I'm going to leave it at that because this isn't something even worth arguing about.
How about instead of a bunch of hacks we just get the hook many have wanted for years? I've wanted a refresh hook for quite a while so that I don't have to put garbage at the top of every file I need to keep an eye on.
At one point I just went OOP entirely so that I can track object registration and refresh my addon gracefully. I like to avoid map reloading when developing so I reload gamemodes and addons instead. A hook for file refreshes would assist with this.
[b]Also I'm sick of unhandled refreshes and I'd want this hook to allow returning true or something to force the reload.[/b] This is the real gear grinder.
[QUOTE=Rocket;51783630][code]
ScrW() = 1600
w = 363
padding = 10
ScrW() - w - padding = 1227
w - padding = 353
[/code]
1227 + 353 = 1580. It must be an order of operations problem, but how?[/QUOTE]
Don't exactly know what you're asking, but your last equation should be w + padding since the fourth equation is really two separate operations, and can be written as ScrW() - (w + padding)
Any workaround for text:SizeToContents() not working right when the font is different (but still included in Default Fonts) ?
[IMG]http://i.imgur.com/abKL3DA.png[/IMG]
(1st is without setting fontinternal, 2nd is with it)
Call SizeToContents after you set FontInternal
[QUOTE=Robotboy655;51784452]Call SizeToContents after you set FontInternal[/QUOTE]
This seems like it should be expected behavior, and done when SizeToContents is called?
Having trouble making the projectile to maintain velocity, it bounces off the sky, and ignores the max bounce limit.
[lua]
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include("shared.lua")
ENT.MaxBounces = 3 -- Not done yet, don't even use this... (So far it works-ish, but velocity isn't maintained, bounces off of the sky, and bounces endlessly)
ENT.DeathLimit = 15
function ENT:Initialize()
self:SetModel("models/props_junk/sawblade001a.mdl")
self:PhysicsInitSphere(6)
self:SetMoveType(MOVETYPE_VPHYSICS) --MOVETYPE_VPHYSICS
local phys = self:GetPhysicsObject()
if phys:IsValid() then
phys:EnableGravity(false)
phys:EnableDrag(false)
phys:SetBuoyancyRatio(0)
phys:Wake()
end
self:EmitSound("ricochet/disc_fire.wav")
self.DeathTime = self.DeathTime or CurTime() + self.DeathLimit
self.Direction = Vector(0, 0, 0)
self.Bounces = 0
end
function ENT:Launch(speed)
local owner = self:GetOwner()
local phys = self:GetPhysicsObject()
if phys:IsValid() then
phys:SetVelocityInstantaneous(self:GetForward() * speed)
self.Direction = self:GetForward()
end
end
function ENT:Touch(hitent)
local owner = self:GetOwner()
if IsValid(hitent) and hitent:IsPlayer() and not (hitent == owner) and (not (hitent:Team() == owner:Team()) or (GetGlobalString("rc_gametype") == "dm")) then
hitent:SetLastAttacker(self:GetOwner())
if self:GetPowerShot() then hitent:TakeDamage(999, self:GetOwner(), self) end
hitent:SetVelocity(self.Direction * 1000)
end
self:EmitSound("ricochet/disc_hit"..math.random(1,2)..".wav", 78, 80)
self:Remove()
end
function ENT:Think()
if self.DeathTime and CurTime() >= self.DeathTime then
self:Remove()
end
end
function ENT:PhysicsCollide(data, physobj)
local vphys = physobj:GetVelocity() * data.OurOldVelocity:Length()
local angles = self:GetAngles()
physobj:SetVelocityInstantaneous(Vector(vphys.x / 1000, vphys.y / 1000, 0))
self:EmitSound("ricochet/disc_hit"..math.random(1,2)..".wav", 78, 80)
self.Direction = self:GetForward()
self.Bounces = self.Bounces + 1
self.MaxBounces <= self.Bounces --This line produeces an expected symbol near '<=' error :\
if data.HitEntity:IsWorld() then --Is there away to remove the projectile if it goes outside the map (Hits sky),It bounces off the edge of map
timer.Simple(0, function() --Remove the next frame..
if (IsValid(self)) then
self:Remove()
end
end)
end
end
function ENT:OnRemove()
local owner = self:GetOwner()
if owner:Alive() and owner:GetActiveWeapon():Clip1() < 3 then
owner:GetActiveWeapon():SetClip1(owner:GetActiveWeapon():Clip1() + self:GetAmmoBack())
end
local effectdata = EffectData()
effectdata:SetOrigin(self:LocalToWorld(self:OBBCenter()))
if owner:Team() == TEAM_BLUE then
util.Effect("discdisintegration_blue", effectdata)
elseif owner:Team() == TEAM_RED or owner:Team() == TEAM_DEATHMATCH then
util.Effect("discdisintegration_red", effectdata)
else
util.Effect("discdisintegration_gray", effectdata)
end
end
[/lua]
I have tried various things to get this working and all has failed. Anyone know what is wrong with the code that causes the bugs?
[QUOTE=Robotboy655;51784452]Call SizeToContents after you set FontInternal[/QUOTE]
...Inside PerformLayout? Init? Think? None of them seem to work, size keeps being wrong. What do you mean?
[QUOTE=Coment;51784517]...Inside PerformLayout? Init? Think? None of them seem to work, size keeps being wrong. What do you mean?[/QUOTE]
After every call to anything that changes the content inside visually. After each SetText/SetFont call in everywhere.
[editline]6th February 2017[/editline]
[QUOTE=Revenge282;51784462]This seems like it should be expected behavior, and done when SizeToContents is called?[/QUOTE]
I don't follow
[QUOTE=Robotboy655;51784535]After every call to anything that changes the content inside visually. After each SetText/SetFont call in everywhere.
[/QUOTE]
[code]
local z = vgui.Create("DFrame")
z:SetSize(300,300)
local a = vgui.Create("RichText",z)
a:SetPos(10,30)
function a:PerformLayout()
self:SetFontInternal( "Trebuchet24" )
self:SetFGColor(Color(222, 137, 0, 255))
self:SetBGColor(Color(255,0,0,255))
self:SizeToContents()
end
a:SetWrap(false)
a:SetVerticalScrollbarEnabled(false)
a:SetText("123456789")
a:SizeToContents()
[/code]
I am calling it after SetText and SetFont... Still nothing. Outdated width.
Could you share a quick working example to clue me in?
-snip-
I don't think RichText even supports SizeToContents.
Okay I managed to mostly fix my issue, except velocity isn't staying constant after each bounce. I personally have little to know with how to manipulate velocity but help will be appreciated.
[lua]
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include("shared.lua")
ENT.MaxBounces = 3 -- Not done yet, don't even use this... (Need help for some of this)
ENT.DeathLimit = 15
function ENT:Initialize()
self:SetModel("models/disc.mdl")
self:PhysicsInitSphere(6)
self:SetMoveType(MOVETYPE_VPHYSICS) --MOVETYPE_VPHYSICS
local phys = self:GetPhysicsObject()
if phys:IsValid() then
phys:EnableGravity(false)
phys:EnableDrag(false)
phys:SetBuoyancyRatio(0)
phys:Wake()
end
self:EmitSound("ricochet/disc_fire.wav")
self.DeathTime = self.DeathTime or CurTime() + self.DeathLimit
self.Direction = Vector(0, 0, 0)
self.Bounces = 0
end
function ENT:Launch(speed)
local owner = self:GetOwner()
local phys = self:GetPhysicsObject()
if phys:IsValid() then
phys:SetVelocityInstantaneous(self:GetForward() * speed)
self.Direction = self:GetForward()
end
end
function ENT:Touch(hitent)
local owner = self:GetOwner()
if IsValid(hitent) and hitent:IsPlayer() and not (hitent == owner) and (not (hitent:Team() == owner:Team()) or (GetGlobalString("rc_gametype") == "dm")) then
hitent:SetLastAttacker(self:GetOwner())
if self:GetPowerShot() then hitent:TakeDamage(999, self:GetOwner(), self) end
hitent:SetVelocity(self.Direction * 1000)
end
self:EmitSound("ricochet/disc_hit"..math.random(1,2)..".wav", 78, 80)
self:Remove()
end
function ENT:Think()
if self.DeathTime and CurTime() >= self.DeathTime then
self:Remove()
end
end
function ENT:PhysicsCollide(data, physobj)
local vphys = physobj:GetVelocity() * data.OurOldVelocity:Length()
local angles = self:GetAngles()
physobj:SetVelocityInstantaneous(Vector(vphys.x / 1000, vphys.y / 1000, 0))
self:EmitSound("ricochet/disc_hit"..math.random(1,2)..".wav", 78, 80)
self.Direction = self:GetForward()
self.Bounces = self.Bounces + 1
if self.MaxBounces <= self.Bounces then --Is there away to remove this if it goes outside the map (Hits edge), versus ingame walls. It bounces off the edge of map
timer.Simple(0, function() --Remove the next frame..
if (IsValid(self)) then
self:Remove()
end
end)
end
end
function ENT:OnRemove()
local owner = self:GetOwner()
if owner:Alive() and owner:GetActiveWeapon():Clip1() < 3 then
owner:GetActiveWeapon():SetClip1(owner:GetActiveWeapon():Clip1() + self:GetAmmoBack())
end
local effectdata = EffectData()
effectdata:SetOrigin(self:LocalToWorld(self:OBBCenter()))
if owner:Team() == TEAM_BLUE then
util.Effect("discdisintegration_blue", effectdata)
elseif owner:Team() == TEAM_RED or owner:Team() == TEAM_DEATHMATCH then
util.Effect("discdisintegration_red", effectdata)
else
util.Effect("discdisintegration_gray", effectdata)
end
end
[/lua]
Everything else works and it's getting on my nerves that I can't figure out how to keep velocity the same... :\
Quick ignorant question time!!!
What's the most efficient way to set the position of surface.DrawTexturedRect(0,0,50,50) so that it's on the bottom of the screen instead of the top?
What would be ideal solution to cap a player's velocity?
For example, Player A is bhopping at 350 velocity, instead of going over it, I would want his/her velocity to be capped at 350 till it's interrupted naturally.
I'm quite confused how SetVelocity() would work in this case.
If someone would point me into the right direction, that would be great!
Codes snippets I took from a post:
[CODE]
local MAX_SPEED = 260
function speedLimiter(ply, data)
local speed = ply:GetVelocity():Length()
if speed > MAX_SPEED then
ply:ChatPrint("Speed Length: ".. speed)
ply:ChatPrint("Velocity: ".. tostring(ply:GetVelocity()))
ply:ChatPrint("Speed limit over "..MAX_SPEED )
ply:SetVelocity(ply:GetVelocity())
end
end
hook.Add("Move", "Speed Limit", speedLimiter)
[/CODE]
[QUOTE=nubpro;51788859]What would be ideal solution to cap a player's velocity?
For example, Player A is bhopping at 350 velocity, instead of going over it, I would want his/her velocity to be capped at 350 till it's interrupted naturally.
I'm quite confused how SetVelocity() would work in this case.
If someone would point me into the right direction, that would be great!
Codes snippets I took from a post:
[CODE]
local MAX_SPEED = 260
function speedLimiter(ply, data)
local speed = ply:GetVelocity():Length()
if speed > MAX_SPEED then
ply:ChatPrint("Speed Length: ".. speed)
ply:ChatPrint("Velocity: ".. tostring(ply:GetVelocity()))
ply:ChatPrint("Speed limit over "..MAX_SPEED )
ply:SetVelocity(ply:GetVelocity())
end
end
hook.Add("Move", "Speed Limit", speedLimiter)
[/CODE][/QUOTE]
When the velocity is greater than the max, simply set it back to the max.
Sorry, you need to Log In to post a reply to this thread.