I'm getting a script error. When I try to remove a hook that I've made it gives me a lua error from the hooks.lua module file. My best guess is it's doing this because it's a custom hook. I need a hand to find a way around this, the hook.Remove is the only way I know to stop a loop early.
[url]https://paste.ofcode.org/365fRWNVEAFqS5KtHkTABfL[/url]
[IMG]http://i.imgur.com/24OBfL3.png[/IMG]
[QUOTE=Shadow02;52452913]I'm getting a script error. When I try to remove a hook that I've made it gives me a lua error from the hooks.lua module file. My best guess is it's doing this because it's a custom hook. I need a hand to find a way around this, the hook.Remove is the only way I know to stop a loop early.
[url]https://paste.ofcode.org/365fRWNVEAFqS5KtHkTABfL[/url]
[IMG]http://i.imgur.com/24OBfL3.png[/IMG][/QUOTE]
Why are you defining functions inside another function? What is your goal?
[QUOTE=JasonMan34;52452937]Why are you defining functions inside another function? What is your goal?[/QUOTE]
It's so both the menus don't pull up at once. If I had it so it opened them inside the loop then it would open up a ton of them, so I had to add a function and hook around the loop so I could use hook.Remove to get rid of it. This is the only way I know how to stop a loop from continuing.
This is the only way I could figure out how to do it.
Excuse me for any grammatical errors!
I'm making a weapon that works only when the owner of the weapon is looking another player.
All perfectly works but I'm having some problem to stop what the weapon is doing when the player looks away:
[CODE]
function SWEP:DrawHUD()
local tl = util.TraceLine( {
start = self:GetOwner():GetShootPos(),
endpos = self:GetOwner():GetShootPos() + self:GetOwner():GetAimVector() * 10000,
filter = self:GetOwner()
} )
if not tl.Entity:IsPlayer() then
self:GetOwner():SetNWBool("isLookingAPlayer", false)
end
end
[/CODE]
The problem is that the NWBool doesn't change, because in the function "PrimaryAttack()" if I try to print the "isLookingAPlayer" NWBool it doesn't change when the player looks away.
The strange thing is that if I try to print the NWBool in the "DrawHUD" function, it changes when the player looks away.
Why I'm doing this in the "SWEP:DrawHUD" function?
-Because I want to make this control every frames.
[QUOTE=Shadow02;52453013]It's so both the menus don't pull up at once. If I had it so it opened them inside the loop then it would open up a ton of them, so I had to add a function and hook around the loop so I could use hook.Remove to get rid of it. This is the only way I know how to stop a loop from continuing.
This is the only way I could figure out how to do it.[/QUOTE]
Paste the client-side code.
What you're doing is unnecessarily complex
[QUOTE=JasonMan34;52453082]Paste the client-side code.
What you're doing is unnecessarily complex[/QUOTE]
Sorry about all of the commented out stuff. It's for features I may use later on that need changing.
[url]https://paste.ofcode.org/F7kwt5FznsfmQvmtGHq6e5[/url]
is there way to check if player is above certain cordinates over certain time and if player is over that time he dies?
[QUOTE=Predda;52453074]Excuse me for any grammatical errors!
I'm making a weapon that works only when the owner of the weapon is looking another player.
All perfectly works but I'm having some problem to stop what the weapon is doing when the player looks away:
[CODE]
function SWEP:DrawHUD()
local tl = util.TraceLine( {
start = self:GetOwner():GetShootPos(),
endpos = self:GetOwner():GetShootPos() + self:GetOwner():GetAimVector() * 10000,
filter = self:GetOwner()
} )
if not tl.Entity:IsPlayer() then
self:GetOwner():SetNWBool("isLookingAPlayer", false)
end
end
[/CODE]
The problem is that the NWBool doesn't change, because in the function "PrimaryAttack()" if I try to print the "isLookingAPlayer" NWBool it doesn't change when the player looks away.
The strange thing is that if I try to print the NWBool in the "DrawHUD" function, it changes when the player looks away.
Why I'm doing this in the "SWEP:DrawHUD" function?
-Because I want to make this control every frames.[/QUOTE]
DrawHud is clientside, it won't change the NW var server side, so it will remain the same in any server code. You'd have to move the code to a serverside function like Think() for the NW book to change on both.
[QUOTE=Shadow02;52453204]Sorry about all of the commented out stuff. It's for features I may use later on that need changing.
[url]https://paste.ofcode.org/F7kwt5FznsfmQvmtGHq6e5[/url][/QUOTE]
First - Don't call surface.CreateFont inside a function, there's no reason for it to run every time.
Aside from that, why are you even using hooks? The hook is just calling a function that's sending a net message. Why not just change your server-side code to: [lua]function ENT:Use(activator, person)
local apts = apartment_list[game.GetMap()] or {}
for k, v in pairs(apts) do
local door = ents.GetMapCreatedEntity(v[1])
assert(IsValid(door), "Bad map creation ID: " .. v[1])
if not door:isKeysOwnedBy(person) then
net.Start("OpenBuy")
net.Send(person)
else
net.Start("OpenSell")
net.Send(person)
end
end
end[/lua]
[QUOTE=JasonMan34;52453786]First - Don't call surface.CreateFont inside a function, there's no reason for it to run every time.
Aside from that, why are you even using hooks? The hook is just calling a function that's sending a net message. Why not just change your server-side code to: [lua]function ENT:Use(activator, person)
local apts = apartment_list[game.GetMap()] or {}
for k, v in pairs(apts) do
local door = ents.GetMapCreatedEntity(v[1])
assert(IsValid(door), "Bad map creation ID: " .. v[1])
if not door:isKeysOwnedBy(person) then
net.Start("OpenBuy")
net.Send(person)
else
net.Start("OpenSell")
net.Send(person)
end
end
end[/lua] ?[/QUOTE]
Because it opens the menu multiple times, that's why I'm trying to find a way to stop the loop.
[QUOTE=Shadow02;52453827]Because it opens the menu multiple times, that's why I'm trying to find a way to stop the loop.[/QUOTE]
....
[lua]
if MenuOpen then
-- The menu is open
else
-- Open the menu
MenuOpen = true
end
function yourMenu.OnClose()
MenuOpen = false
end[/lua]
Is there a hook for detecting resolution changes that I'm missing somewhere?
[QUOTE=a1steaksa;52455079]Is there a hook for detecting resolution changes that I'm missing somewhere?[/QUOTE]
Doesn't seem to be, even an undocumented one. A Think hook that checks CurW() and CurH() is probably the best you're gonna get
[lua]
local oldw, oldh = ScrW(), ScrH()
hook.Add("Think", "ScreenSize", function()
local w, h = ScrW(), ScrH()
if w ~= oldw or h ~= oldh then
hook.Run("ScreenSizeChanged", oldw, oldh, w, h)
oldw, oldh = w, h
end
end)
[/lua]
Concommands not coming up on client, no errors noted.
GMOD Wiki states it as a shared function so I supposed that concommand.Add works on client.
[url]https://github.com/WasabiThumb/WorldVectorTools[/url]
[editline]10th July 2017[/editline]
just a little test, nothing big
I'm trying to change a playermodel after it burns from the flare gun. In terrortown\entities\weapons\weapon_ttt_flaregun.lua, I made these changes:
[code]
local function RunIgniteTimer(ent, timer_name)
if IsValid(ent) and ent:IsOnFire() then
if ent:WaterLevel() > 0 then
ent:Extinguish()
elseif CurTime() > ent.burn_destroy then
-- Begin Changes --
util.PrecacheModel("models/player/charple.mdl")
ent:SetModel("models/player/charple.mdl")
--ent:SetNotSolid(true)
--ent:Remove()
-- Rest of the file is normal --
[/code]
Here's the result:
[vid]https://s.gvid.me/s/2017/07/10/buggyragdoll.webm[/vid]
Any way to make it have the normal ragdoll physics and not freak out on itself?
[QUOTE=Shadari;52455967]I'm trying to change a playermodel after it burns from the flare gun. In terrortown\entities\weapons\weapon_ttt_flaregun.lua, I made these changes:
[code]
local function RunIgniteTimer(ent, timer_name)
if IsValid(ent) and ent:IsOnFire() then
if ent:WaterLevel() > 0 then
ent:Extinguish()
elseif CurTime() > ent.burn_destroy then
-- Begin Changes --
util.PrecacheModel("models/player/charple.mdl")
ent:SetModel("models/player/charple.mdl")
--ent:SetNotSolid(true)
--ent:Remove()
-- Rest of the file is normal --
[/code]
Here's the result:
[vid]https://s.gvid.me/s/2017/07/10/buggyragdoll.webm[/vid]
Any way to make it have the normal ragdoll physics and not freak out on itself?[/QUOTE]
*snip*
My bad..
I made a seat for gmod and can get it to spawn with the ACT_DRIVE_JEEP player pose
[t]https://i.imgur.com/cugGwd3.png[/t]
However I made it for a map so it will be placed in hammer as a prop_vehicle_prisoner_pod with the correct model. Sadly I have no control over the player animation there and the standart rollercoaster position is in use.
My Lua skills are very bad but here is what someone helped me with:
[CODE]hook.Add("CalcMainActivity", "IrgendeinNameHier",
function(ply, vel)
if ply:InVehicle() and ply:GetVehicle():GetName() == "test" then
ply:SelectWeightedSequence( ACT_DRIVE_JEEP )
end
end)[/CODE]
runs fine with no errors but it doesnt do anything. The player stays in rollercoaster pose
[QUOTE=Shadari;52455967]I'm trying to change a playermodel after it burns from the flare gun. In terrortown\entities\weapons\weapon_ttt_flaregun.lua, I made these changes:
[code]
local function RunIgniteTimer(ent, timer_name)
if IsValid(ent) and ent:IsOnFire() then
if ent:WaterLevel() > 0 then
ent:Extinguish()
elseif CurTime() > ent.burn_destroy then
-- Begin Changes --
util.PrecacheModel("models/player/charple.mdl")
ent:SetModel("models/player/charple.mdl")
--ent:SetNotSolid(true)
--ent:Remove()
-- Rest of the file is normal --
[/code]
Here's the result:
[vid]https://s.gvid.me/s/2017/07/10/buggyragdoll.webm[/vid]
Any way to make it have the normal ragdoll physics and not freak out on itself?[/QUOTE]
ragdoll is a mess, i would recommend you to decompile ragdoll and add the flag in qc $noselfcollisions
[QUOTE=gonzalolog;52459130]ragdoll is a mess, i would recommend you to decompile ragdoll and add the flag in qc $noselfcollisions[/QUOTE]
De-compiling shouldn't be necessary because it's already a player-model (at models/player/charple.mdl)
Moreover, when the model has been set before the player is killed, the corpse behaves as it should.
[vid]https://s.gvid.me/s/2017/07/11/playermodelcharp.webm[/vid]
I have a hard time understanding how animation events work for both SWEPs and SENTs.
How would I, for instance, go about forcing a player's active weapon to fire it's "fire" animation?
-FP
[QUOTE=Fillipuster;52460414]I have a hard time understanding how animation events work for both SWEPs and SENTs.
How would I, for instance, go about forcing a player's active weapon to fire it's "fire" animation?
-FP[/QUOTE]
Is this what you need? [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Weapon/SendWeaponAnim]Weapon:SendWeaponAnim[/url] (ACT_VM_PRIMARYATTACK is the "fire" animation)
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/WEAPON/FireAnimationEvent]SWEP:FireAnimationEvent[/url] is a hook, it's called whenever an event happens during animation, you shouldn't call it yourself.
Also, please don't sign your posts.
[QUOTE=SFArial;52460440]Is this what you need? [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Weapon/SendWeaponAnim]Weapon:SendWeaponAnim[/url] (ACT_VM_PRIMARYATTACK is the "fire" animation)
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/WEAPON/FireAnimationEvent]SWEP:FireAnimationEvent[/url] is a hook, it's called whenever an event happens during animation, you shouldn't call it yourself.
Also, please don't sign your posts.[/QUOTE]
Ah, nice. I'll try that. Thanks :D
- Jones "Fillipuster" Lightbulb, July 12, 2017
What is an efficient way to create a function that finds the player with the greatest value of a variable? Should I just use the FindHighest function on [URL="https://github.com/Facepunch/garrysmod/blob/master/garrysmod/gamemodes/terrortown/gamemode/cl_awards.lua"]https://github.com/Facepunch/garrysmod/blob/master/garrysmod/gamemodes/terrortown/gamemode/cl_awards.lua[/URL]?
[QUOTE=PigeonTroll;52461399]What is an efficient way to create a function that finds the player with the greatest value of a variable? Should I just use the FindHighest function on [URL="https://github.com/Facepunch/garrysmod/blob/master/garrysmod/gamemodes/terrortown/gamemode/cl_awards.lua"]https://github.com/Facepunch/garrysmod/blob/master/garrysmod/gamemodes/terrortown/gamemode/cl_awards.lua[/URL]?[/QUOTE]
Just loop through all the players and see who has the greatest value. Its a simple function for finding the max value of the variable
[QUOTE=Gmod4phun;52461409]Just loop through all the players and see who has the greatest value. Its a simple function for finding the max value of the variable[/QUOTE]
It's also exactly what FindHighest does
[QUOTE=JasonMan34;52461460]It's also exactly what FindHighest does[/QUOTE]
Yeah but its not a global GMod function, he is either going to have to copy it or make his own one
If I've got a set of points that make up a cube or a ramp, how do I create a mesh out of them? I understand how to make a single triangle mesh, but not a full on 3D object.
[QUOTE=wauterboi;52461515]If I've got a set of points that make up a cube or a ramp, how do I create a mesh out of them? I understand how to make a single triangle mesh, but not a full on 3D object.[/QUOTE]
You'd divide each surface up into triangles. For example, the face of a cube would be two triangles that have points at 3 adjacent verticies, and the hypotenuse would run between two diagonal points.
One of my calculus textbooks has a chart listing algorithms for dividing each 2D and 3D shape into tris, but I haven't found a similar comprehensive list online. Searching "dividing * into triangles" usually works for individual implementations, however.
[QUOTE=code_gs;52461604]You'd divide each surface up into triangles. For example, the face of a cube would be two triangles that have points at 3 adjacent verticies, and the hypotenuse would run between two diagonal points.
One of my calculus textbooks has a chart listing algorithms for dividing each 2D and 3D shape into tris, but I haven't found a similar comprehensive list online. Searching "dividing * into triangles" usually works for individual implementations, however.[/QUOTE]
How would I separate vertexes into surfaces? That's what I'm stuck on right now. I can make cubes just fine because I can control the order of points, but if someone is going to delete an edge then I'm very unsure of how to handle that.
Sorry, you need to Log In to post a reply to this thread.