[QUOTE=MegaTronJohn;48150498]Well yeah, but I only want the ironsights to be activated if Secondary attack is [i]held down[/i]. When you hold it down you ironsight, but when you release the key you stop ironsighting. I don't know how I'd do that with SecondaryAttack.[/QUOTE]
SWEP:Think and self.Owner:KeyDown(IN_ATTACK2)?
[QUOTE=Robotboy655;48150557]SWEP:Think and self.Owner:KeyDown(IN_ATTACK2)?[/QUOTE]
[lua]function SWEP:Think()
if self.Owner:KeyDown( IN_ATTACK2 ) and not self.Owner:GetNWBool( "Ironsights" ) then
self:SetIronsights( true )
elseif !self.Owner:KeyDown( IN_ATTACK2 ) and self.Owner:GetNWBool( "Ironsights" ) then
self:SetIronsights( false )
end
end
[/lua]
This doesn't seem to work. I'm using Garry's Ironsight code in case you need to know...
How do I trace/make traceable a clientside ragdoll on client, created using ClientsideRagdoll()? util.TraceLine or Player:GetEyeTrace() seems like skipping it.
[QUOTE=MegaTronJohn;48150639][lua]function SWEP:Think()
if self.Owner:KeyDown( IN_ATTACK2 ) and not self.Owner:GetNWBool( "Ironsights" ) then
self:SetIronsights( true )
elseif !self.Owner:KeyDown( IN_ATTACK2 ) and self.Owner:GetNWBool( "Ironsights" ) then
self:SetIronsights( false )
end
end
[/lua]
This doesn't seem to work. I'm using Garry's Ironsight code in case you need to know...[/QUOTE]
"Doesn't work" is never helpful. Put in print("test1"), print("test2") around the function to see what is called at all, what are the values, etc.
print("test1", self.Owner:KeyDown( IN_ATTACK2 ), self.Owner:GetNWBool( "Ironsights" ) )
Like do some basic debugging before asking questions.
[QUOTE=grinchfox;48151906]How do I trace/make traceable a clientside ragdoll on client, created using ClientsideRagdoll()? util.TraceLine or Player:GetEyeTrace() seems like skipping it.[/QUOTE]
I don't think you can do that.
Might wanna try these two though:
[url]http://wiki.garrysmod.com/page/Global/ClientsideRagdoll[/url]
[url]http://wiki.garrysmod.com/page/ents/CreateClientProp[/url]
How would I make a thumper model play it's animations? I currently simply spawn a thumper and set it as a child of the entity, yet its kinda silly. I'd like to create my own thumper entity that would play sounds, the animations, and maybe even the sand-around-it-when-it-hits effect. Any ideas? I really don't want to use the one written in C++ ([url]https://developer.valvesoftware.com/wiki/Prop_thumper[/url])
How do I make it so that whenever I auto refresh my Lua files to test stuff like HUD, I don't reset some running instances (like making the timer stuck at 00:00)?
Learning lua by trying to trial and error my way to a simple thing I want to do, going pretty well so far.
I wanted to make a script that affects the player's model/body when they die via fire damage- turn them into a charple, change color/texture and ignite the actual ragdoll.
It works well except for the ignite part, which does not work and produces a script error
[code]local function DoPlayerDeath( ply, attacker, dmg )
if ( dmg:IsDamageType(DMG_BURN)) then
ply:SetModel("models/Humans/Charple01.mdl")
ply:SetMaterial("models/flesh")
ply:SetColor(Color(75,75,75,255))
local corpse = ply:GetRagdollEntity()
co​rpse:Ignite( 5 ) -- line of error
end
end
hook.Add( "DoPlayerDeath", "DoPlayerDeath", DoPlayerDeath )[/code]
With the console error;
[code]
[ERROR] addons/littlethings/lua/autorun/earringing.lua:24: attempt to index local 'corpse' (a nil value)
1. v - addons/littlethings/lua/autorun/earringing.lua:24
2. unknown - lua/includes/modules/hook.lua:84
[/code]
(earringing.lua is the name of the file- boring story.)
DoPlayerDeath is called like, 90% of the way through the player's death. At this point, the player has not 'died'. Try slaying the player a line before the line you localize the ragdoll entity.
[QUOTE=RedNinja;48160524]How would I make a thumper model play it's animations? I currently simply spawn a thumper and set it as a child of the entity, yet its kinda silly. I'd like to create my own thumper entity that would play sounds, the animations, and maybe even the sand-around-it-when-it-hits effect. Any ideas? I really don't want to use the one written in C++ ([url]https://developer.valvesoftware.com/wiki/Prop_thumper[/url])[/QUOTE]I think I know what you are going to create.
So I've been messing with the [URL="http://steamcommunity.com/sharedfiles/filedetails/?id=307541473"]TTT-Bulldozer Weapon[/URL]. Basically it's just a Traitor weapon that can be purchased and the player gains more health and receives a powerful gun they cannot drop.
I changed the shotgun to a [URL="http://steamcommunity.com/sharedfiles/filedetails/?id=402109323"]Handheld M2 Browning HMG[/URL] and changed the riot model from CS:S to a [URL="http://steamcommunity.com/sharedfiles/filedetails/?id=188562859"]Heavy Combine Soldier[/URL]. I've changed a few other things, but I would like to know how to solve these issues:
1.) I would like this weapon to slow the player's walk and run speed so that other players can actually run away from it. I've tried using this section of code, but it doesn't affect the player's movement speed:
[CODE]function SWEP:WasBought(buyer)
if IsValid(buyer) then -- probably already self.Owner
[B]buyer:SetWalkSpeed(150)
buyer:SetRunSpeed(150)[/B]
end
end[/CODE]
2.) I would like to fix the size of the world model for the M2 Browning. I used this section of code that is all over facepunch and it works quite well on the positioning of the world model but there doesn't seem to be a "size" argument for it:
[CODE]SWEP.Offset = {
Pos = {
Up = -5,
Right = 0,
Forward = 0,
},
Ang = {
Up = 0,
Right = 0,
Forward = 0,
}
}
function SWEP:DrawWorldModel( )
local hand, offset, rotate
local pl = self:GetOwner()
if IsValid( pl ) then
local boneIndex = pl:LookupBone( "ValveBiped.Bip01_R_Hand" )
if boneIndex then
local pos, ang = pl:GetBonePosition( boneIndex )
pos = pos + ang:Forward() * self.Offset.Pos.Forward + ang:Right() * self.Offset.Pos.Right + ang:Up() * self.Offset.Pos.Up
ang:RotateAroundAxis( ang:Up(), self.Offset.Ang.Up)
ang:RotateAroundAxis( ang:Right(), self.Offset.Ang.Right )
ang:RotateAroundAxis( ang:Forward(), self.Offset.Ang.Forward )
self:SetRenderOrigin( pos )
self:SetRenderAngles( ang )
self:DrawModel()
end
else
self:SetRenderOrigin( nil )
self:SetRenderAngles( nil )
self:DrawModel()
end
end[/CODE]
If that doesn't work, then I'll have to edit the MDL file for it.
[QUOTE=Invule;48148549]I'm trying to make the RGB(Alpha) fade away real smooth and fast but nothing is working :(
How could I make Alpha go down from 255 to 0 smoothly so it dosent disappear instantly?[/QUOTE]
[code]
local go_up = true --go up bool
local go_down = false --go down bool (set to false because it goes up first <val starts at 0>)
local r = 0 --start at 0 r
local g = 0 --start at 0 g
local b = 0 --start at 0 b
local end_val_add = 255 --how red it gets
local end_val_take = 0 --how black it gets
local add_val = 1 --how fast it goes up (goes from black to red)
local take_val = 1 --how fast it goes down (goes from red to black)
hook.Add("Think", "whatever", function()
if go_up then
r = r + add_val
g = g + add_val
b = b + add_val
elseif !go_up and go_down then
r = r - take_val
g = g - take_val
b = b - take_val
end
if r != end_val_add then
go_up = true
go_down = false
elseif r == end_val_take then
go_up = false
go_down = true
end
end )
[/code]
call setcolor(r, g, b, 255)
[QUOTE=Z0mb1n3;48162425]DoPlayerDeath is called like, 90% of the way through the player's death. At this point, the player has not 'died'. Try slaying the player a line before the line you localize the ragdoll entity.[/QUOTE]
Would that not call the DoPlayerDeath hook again and try to slay again..... inifinitely?
[QUOTE=Blasteh;48163520]Would that not call the DoPlayerDeath hook again and try to slay again..... inifinitely?[/QUOTE]
Use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/PostPlayerDeath]GM/PostPlayerDeath[/url] instead, the ragdoll should be available unless the player has been killed with [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Player/KillSilent]Player:KillSilent[/url]
[QUOTE=RedNinja;48160524]How would I make a thumper model play it's animations? I currently simply spawn a thumper and set it as a child of the entity, yet its kinda silly. I'd like to create my own thumper entity that would play sounds, the animations, and maybe even the sand-around-it-when-it-hits effect. Any ideas? I really don't want to use the one written in C++ ([url]https://developer.valvesoftware.com/wiki/Prop_thumper[/url])[/QUOTE]
Anyone?
So I have my gamemode, then a folder inside it called /challenges, which are sort of like achievements. I want every file within that to be included. What is the correct format to do this?
Like, this prints the file names and their .lua extension perfectly fine:
[code]
for k, v in pairs(file.Find("gamemodes/name/gamemode/challenges/*.lua", "GAME")) do
print(v)
end
[/code]
But this gives me serverside errors that the file name, which is printed correctly, cannot be found:
[code]
for k, v in pairs(file.Find("gamemodes/name/gamemode/challenges/*.lua", "GAME")) do
if SERVER then
include(v)
AddCSLuaFile(v)
else
include(v)
end
end
[/code]
All the files have code inside them and I can't see any other related errors - what am I doing wrong or what method would be best appropriate for this?
[QUOTE=NiandraLades;48164399]So I have my gamemode, then a folder inside it called /challenges, which are sort of like achievements. I want every file within that to be included. What is the correct format to do this?
Like, this prints the file names and their .lua extension perfectly fine:
[code]
for k, v in pairs(file.Find("gamemodes/name/gamemode/challenges/*.lua", "GAME")) do
print(v)
end
[/code]
But this gives me serverside errors that the file name, which is printed correctly, cannot be found:
[code]
for k, v in pairs(file.Find("gamemodes/name/gamemode/challenges/*.lua", "GAME")) do
if SERVER then
include(v)
AddCSLuaFile(v)
else
include(v)
end
end
[/code]
All the files have code inside them and I can't see any other related errors - what am I doing wrong or what method would be best appropriate for this?[/QUOTE]
[lua]
include( "gamemode/challenges/"..v )
[/lua]
This works for me.
Is the should collide hook working properly?
[lua]
hook.Add( "ShouldCollide", "should_collide_gate", function(ent1, ent2)
if ( ent1:GetClass() == "breakable_entry" and ent2:GetClass() == "nut_zombie" ) then
if ent1:Health() == 0 then
print("colliding!")
return false
end
end
end )
[/lua]
The text is being printed to the console, but the 2 entitys are still colliding.
I'm getting the following error
[CODE][ERROR] gamemodes/skeleton/gamemode/cl_init.lua:63: '=' or 'in' expected near '.'
1. unknown - gamemodes/skeleton/gamemode/cl_init.lua:0
[/CODE]
from the following code:
[CODE]function FindTarget()
local me = LocalPlayer()
local _ents = ents.GetAll()
local _validents = function() for k, v in pairs(_ents) do
if ( IsValid(v) and v == ents.FindByClass( "npc_*" ) ) or ( IsValid(v) and v:IsPlayer() ) then
return v;
end
end
end
local _T = function()
if (_validents:GetPos():Distance(LocalPlayer():GetPos())<30) then
return _validents;
else
return;
end
end--changable table of targets [[this is line 63]]
for me.Counter[i] = 1, #_T do
if me.Counter[i] < #_T then
me.Counter[i] = me.Counter[i+1]
print( me.Counter )
net.Start( "SendTargetEntity" )
net.WriteEntity( me.Counter )
net.SendToServer()
else
me.Counter[i] = me.Counter[1]
net.Start( "SendTargetEntity" )
net.WriteEntity( me.Counter )
net.SendToServer()
end
end
end[/CODE]
Basically I'm trying to get a table and fill it; i.e _validents; then I'm trying to make sure they are within
a certain distance from the player. Then I'm trying to put them in the me.Counter table, and cycle between them
and eventually end up with one entity as my target for the spell casting system I've been working on.
[QUOTE=Apple_Bloom;48166959]I'm getting the following error
[CODE][ERROR] gamemodes/skeleton/gamemode/cl_init.lua:63: '=' or 'in' expected near '.'
1. unknown - gamemodes/skeleton/gamemode/cl_init.lua:0
[/CODE]
from the following code:
[CODE]function FindTarget()
local me = LocalPlayer()
local _ents = ents.GetAll()
local _validents = function() for k, v in pairs(_ents) do
if ( IsValid(v) and v == ents.FindByClass( "npc_*" ) ) or ( IsValid(v) and v:IsPlayer() ) then
return v;
end
end
end
local _T = function()
if (_validents:GetPos():Distance(LocalPlayer():GetPos())<30) then
return _validents;
else
return;
end
end--changable table of targets [[this is line 63]]
for me.Counter[i] = 1, #_T do
if me.Counter[i] < #_T then
me.Counter[i] = me.Counter[i+1]
print( me.Counter )
net.Start( "SendTargetEntity" )
net.WriteEntity( me.Counter )
net.SendToServer()
else
me.Counter[i] = me.Counter[1]
net.Start( "SendTargetEntity" )
net.WriteEntity( me.Counter )
net.SendToServer()
end
end
end[/CODE]
Basically I'm trying to get a table and fill it; i.e _validents; then I'm trying to make sure they are within
a certain distance from the player. Then I'm trying to put them in the me.Counter table, and cycle between them
and eventually end up with one entity as my target for the spell casting system I've been working on.[/QUOTE]
[lua]
for i = 1, #(_T()) do
if me.Counter[i] < #(_T()) then
me.Counter[i] = me.Counter[i+1]
print( me.Counter )
net.Start( "SendTargetEntity" )
net.WriteEntity( me.Counter )
net.SendToServer()
else
me.Counter[i] = me.Counter[1]
net.Start( "SendTargetEntity" )
net.WriteEntity( me.Counter )
net.SendToServer()
end
end
[/lua]
How do I make it so that a table I coded containing functions is global across all files?
[QUOTE=James xX;48167001]-snip-[/QUOTE]
Thanks for the quick reply, I'm not sure why I forgot the () after _T, now I'm getting the
following error on the client only:
[CODE][ERROR] gamemodes/skeleton/gamemode/cl_init.lua:57: attempt to index upvalue '_validents' (a function value)
1. _T - gamemodes/skeleton/gamemode/cl_init.lua:57
2. FindTarget - gamemodes/skeleton/gamemode/cl_init.lua:63
3. v - gamemodes/skeleton/gamemode/cl_init.lua:78
4. unknown - lua/includes/modules/hook.lua:84
[/CODE]
I'm assuming it's expecting _validents to be a table, and since its only returning entities that's why its giving me the error?
How would I fix this? By put the ents into another table possibly?
[QUOTE=Apple_Bloom;48167078]-snip-[/QUOTE]
_validents is a function, you'd need to call it to return a table/whatever. Like with _T().
[QUOTE=FireArrow133;48167029]How do I make it so that a table I coded containing functions is global across all files?[/QUOTE]
[CODE]if ( SERVER and CLIENT ) then table = {}; end[/CODE]
Put that in a shared file, I believe this is the correct way.
[QUOTE=FireArrow133;48167029]How do I make it so that a table I coded containing functions is global across all files?[/QUOTE]
Make the table global
[QUOTE]local sequence = self:LookupSequence( "AE_THUMPER_THUMP" )
self:SetSequence( sequence )
[/QUOTE]
Makes the entity disappear. How the hell should I do this?
[QUOTE=Apple_Bloom;48167113][CODE]if ( SERVER and CLIENT ) then table = {}; end[/CODE]
Put that in a shared file, I believe this is the correct way.[/QUOTE]
SERVER is true when CLIENT is false, and vis versa. SERVER and CLIENT always equals false.
[editline]10th July 2015[/editline]
[QUOTE=RedNinja;48167142]Makes the entity disappear. How the hell should I do this?[/QUOTE]
You filthy ninja, RedNinja! Stealing my automerge :(
[QUOTE=James xX;48167139]Make the table global[/QUOTE]
SetGlobalTable() ?
[QUOTE=FireArrow133;48167152]SetGlobalTable() ?[/QUOTE]
When you define the table, don't put "local" in front.
[QUOTE=James xX;48167144]-snip-[/QUOTE]
Yikes, yeah forget what I had said FireArrow133.
@stev_ where should I be calling the function at? Inside the for loop?
Sorry, you need to Log In to post a reply to this thread.