In Progress James' lua shit

jamEs

fqjdlkmsbvqfgkhpoiuaeazer
Joined
Apr 26, 2016
Messages
1,155
Nebulae
3,345
How do you make Dynamic Lights for RealCS weapons whenever you fire the gun?
what zak said p. much

once just made particle systems for weapons and spawned a dynamiclight (attached to actual entity projectiles) on every successful primary fire

 
Reactions: List
D

Deleted member 5162

Guest
what zak said p. much

once just made particle systems for weapons and spawned a dynamiclight (attached to actual entity projectiles) on every successful primary fire


Thanks James and @Zak , I tried to do it, but it failed, says this 'attempt to call global 'localplayer' (a nil value)'
I know that I am definitely doing something very very wrong
 
Reactions: List

axido

whatttttttt
Joined
May 8, 2016
Messages
2,791
Nebulae
11,044
Reactions: List
D

Deleted member 5162

Guest
Code:
--REAL CS BASE
--sorry for no comments to show what everything does im too lazy to do it LOL!

if (SERVER) then

    AddCSLuaFile("shared.lua")
    SWEP.Weight                = 5
    SWEP.SetHoldType        = "smg"   
    SWEP.CSMuzzleFlashes    = false
    SWEP.Penetrating        = true

end

if (CLIENT) then
    SWEP.PrintName            = "H&K MP7"   
    SWEP.Author                = "E"
    SWEP.Contact            = ""
    SWEP.Purpose            = ""
    SWEP.Instructions       = "A fully automatic Submachine Gun designed to chamber the 4.6x30mm cartridge with an innate slight armor piercing ability."
    SWEP.SlotPos            = 1
    SWEP.IconLetter            = ""
    SWEP.Slot                = 2
    SWEP.ViewModelFlip        = false
    SWEP.ViewModelFOV        = 75
    SWEP.DefaultVFOV        = 75
    SWEP.CSMuzzleFlashes    = true
    SWEP.DrawCrosshair        = false
    SWEP.NameOfSWEP            = "rcs_mp7" --always make this the name of the folder the SWEP is in.
    killicon.AddFont(SWEP.NameOfSWEP, "CSKillIcons", SWEP.IconLetter, Color(255, 80, 0, 255))
    SWEP.SetHoldType        = "smg"   

end

SWEP.SetHoldType            = "smg"   
SWEP.Category                = "RealCS"
SWEP.Base                    = "rcs_base"

SWEP.Spawnable                = true
SWEP.AdminSpawnable            = true

SWEP.ViewModel                = "models/weapons/v_smg1.mdl"
SWEP.WorldModel                = "models/weapons/w_smg1.mdl"

SWEP.Weight                    = 7
SWEP.AutoSwitchTo            = false
SWEP.AutoSwitchFrom            = false

SWEP.Primary.Sound            = Sound("Weapon_SMG1.NPC_Single")
SWEP.PlayReloadSounds       = true
SWEP.Primary.Recoil            = 0.60
SWEP.Primary.Damage            = 13
SWEP.Penetrating            = true
SWEP.Primary.NumShots        = 1
SWEP.Primary.Cone            = 0.0002 --starting cone, it WILL increase to something higher, so keep it low
SWEP.Primary.ClipSize        = 45
SWEP.Primary.Delay            = 0.1
SWEP.Primary.DefaultClip    = 0
SWEP.Primary.MaxReserve        = 65
SWEP.Primary.Automatic        = true
SWEP.Primary.Ammo            = "smg1"
SWEP.ReloadLol              = Sound("Weapon_SMG1.Reload");

SWEP.Primary.MaxSpread        = 0.15 --the maximum amount the spread can go by, best left at 0.20 or lower
SWEP.Primary.Handle            = 0.2 --how many seconds you have to wait between each shot before the spread is at its best
SWEP.Primary.SpreadIncrease    = 0.05/6 --how much you add to the cone after each shot

SWEP.MoveSpread                = 1 --multiplier for spread when you are moving
SWEP.JumpSpread                = 10 --multiplier for spread when you are jumping
SWEP.CrouchSpread            = 0.6 --multiplier for spread when you are crouching

SWEP.Secondary.ClipSize        = -1
SWEP.Secondary.DefaultClip    = -1
SWEP.Secondary.Automatic    = false
SWEP.Secondary.Ammo            = "none"


SWEP.IronSightsPos = Vector (0.50, -11.356, 4.0395);
SWEP.IronSightsAng = Vector (0.4146, -0.0641, 0.1913);


function SWEP:RCSReload()
    self.Owner:EmitSound(self.ReloadLol)
end

function SWEP:Equip()
    self:SetHoldType( "smg" )
end

function SWEP:PrimaryAttack()
    hook.Add( "Think", "Think_Lights!", function()
    local dlight = DynamicLight( LocalPlayer()[-1]:EntIndex() )
    if ( dlight ) then
        dlight.pos = LocalPlayer():GetShootPos()
        dlight.r = 255
        dlight.g = 255
        dlight.b = 255
        dlight.brightness = 2
        dlight.Decay = 1000
        dlight.Size = 256
        dlight.DieTime = CurTime() + 1
    end
end )
end

Here it is
 
Reactions: List

jamEs

fqjdlkmsbvqfgkhpoiuaeazer
Joined
Apr 26, 2016
Messages
1,155
Nebulae
3,345
Code:
--REAL CS BASE
--sorry for no comments to show what everything does im too lazy to do it LOL!

if (SERVER) then

    AddCSLuaFile("shared.lua")
    SWEP.Weight                = 5
    SWEP.SetHoldType        = "smg"
    SWEP.CSMuzzleFlashes    = false
    SWEP.Penetrating        = true

end

if (CLIENT) then
    SWEP.PrintName            = "H&K MP7"
    SWEP.Author                = "E"
    SWEP.Contact            = ""
    SWEP.Purpose            = ""
    SWEP.Instructions       = "A fully automatic Submachine Gun designed to chamber the 4.6x30mm cartridge with an innate slight armor piercing ability."
    SWEP.SlotPos            = 1
    SWEP.IconLetter            = ""
    SWEP.Slot                = 2
    SWEP.ViewModelFlip        = false
    SWEP.ViewModelFOV        = 75
    SWEP.DefaultVFOV        = 75
    SWEP.CSMuzzleFlashes    = true
    SWEP.DrawCrosshair        = false
    SWEP.NameOfSWEP            = "rcs_mp7" --always make this the name of the folder the SWEP is in.
    killicon.AddFont(SWEP.NameOfSWEP, "CSKillIcons", SWEP.IconLetter, Color(255, 80, 0, 255))
    SWEP.SetHoldType        = "smg"

end

SWEP.SetHoldType            = "smg"
SWEP.Category                = "RealCS"
SWEP.Base                    = "rcs_base"

SWEP.Spawnable                = true
SWEP.AdminSpawnable            = true

SWEP.ViewModel                = "models/weapons/v_smg1.mdl"
SWEP.WorldModel                = "models/weapons/w_smg1.mdl"

SWEP.Weight                    = 7
SWEP.AutoSwitchTo            = false
SWEP.AutoSwitchFrom            = false

SWEP.Primary.Sound            = Sound("Weapon_SMG1.NPC_Single")
SWEP.PlayReloadSounds       = true
SWEP.Primary.Recoil            = 0.60
SWEP.Primary.Damage            = 13
SWEP.Penetrating            = true
SWEP.Primary.NumShots        = 1
SWEP.Primary.Cone            = 0.0002 --starting cone, it WILL increase to something higher, so keep it low
SWEP.Primary.ClipSize        = 45
SWEP.Primary.Delay            = 0.1
SWEP.Primary.DefaultClip    = 0
SWEP.Primary.MaxReserve        = 65
SWEP.Primary.Automatic        = true
SWEP.Primary.Ammo            = "smg1"
SWEP.ReloadLol              = Sound("Weapon_SMG1.Reload");

SWEP.Primary.MaxSpread        = 0.15 --the maximum amount the spread can go by, best left at 0.20 or lower
SWEP.Primary.Handle            = 0.2 --how many seconds you have to wait between each shot before the spread is at its best
SWEP.Primary.SpreadIncrease    = 0.05/6 --how much you add to the cone after each shot

SWEP.MoveSpread                = 1 --multiplier for spread when you are moving
SWEP.JumpSpread                = 10 --multiplier for spread when you are jumping
SWEP.CrouchSpread            = 0.6 --multiplier for spread when you are crouching

SWEP.Secondary.ClipSize        = -1
SWEP.Secondary.DefaultClip    = -1
SWEP.Secondary.Automatic    = false
SWEP.Secondary.Ammo            = "none"


SWEP.IronSightsPos = Vector (0.50, -11.356, 4.0395);
SWEP.IronSightsAng = Vector (0.4146, -0.0641, 0.1913);


function SWEP:RCSReload()
    self.Owner:EmitSound(self.ReloadLol)
end

function SWEP:Equip()
    self:SetHoldType( "smg" )
end

function SWEP:PrimaryAttack()
    hook.Add( "Think", "Think_Lights!", function()
    local dlight = DynamicLight( LocalPlayer()[-1]:EntIndex() )
    if ( dlight ) then
        dlight.pos = LocalPlayer():GetShootPos()
        dlight.r = 255
        dlight.g = 255
        dlight.b = 255
        dlight.brightness = 2
        dlight.Decay = 1000
        dlight.Size = 256
        dlight.DieTime = CurTime() + 1
    end
end )
end

Here it is
ok instead of using LocalPlayer(), try using self.Owner

everywhere

EDIT:

so that means

local dlight = DynamicLight(self.Owner:EntIndex())

and

dlight.pos = self.Owner:GetShootPos()
 
Reactions: List
D

Deleted member 5162

Guest
ok instead of using LocalPlayer(), try using self.Owner

everywhere

EDIT:

so that means

local dlight = DynamicLight(self.Owner:EntIndex())

and

dlight.pos = self.Owner:GetShootPos()
attempt to call field 'Owner' (a userdata value)

This comes from the console, gun doesnt fire
 
Reactions: List
D

Deleted member 5162

Guest
addons/realcs - half-life 2/lua/weapons/rcs_mp7/shared.lua:91: Tried to use a NULL entity!

nah, self.Owner works for SWEPs just fine; the problem is that DynamicLight is clientside only, and he's calling it in a shared file
Ohh okay, so how do I do it? Should I make another LUA file but in autoexec?
 

Zak

Resident xenophile
Joined
Apr 26, 2016
Messages
5,887
Nebulae
16,124
addons/realcs - half-life 2/lua/weapons/rcs_mp7/shared.lua:91: Tried to use a NULL entity!


Ohh okay, so how do I do it? Should I make another LUA file but in autoexec?
the best way to do it is to move the dlight code to its own function in the "if (CLIENT) then" block and call it in the primaryattack function
 
Reactions: List

jamEs

fqjdlkmsbvqfgkhpoiuaeazer
Joined
Apr 26, 2016
Messages
1,155
Nebulae
3,345
tried to do this with fft to make the colours frequency dependent, but it lagged too much and crashed my client. still animated but not as cool now tho:


 
Reactions: List

deathwolf

I AM SPIDERMAN, GRIST LIES! I AM HIM REALLY! ﷽﷽﷽﷽﷽
GTA RP Playtester
Joined
Aug 23, 2016
Messages
9,729
Nebulae
35,940
tried to do this with fft to make the colours frequency dependent, but it lagged too much and crashed my client. still animated but not as cool now tho:


Cool what is it though
 

jamEs

fqjdlkmsbvqfgkhpoiuaeazer
Joined
Apr 26, 2016
Messages
1,155
Nebulae
3,345
Cool what is it though
Bridge model rendered in 3D by grabbing its mesh with each vertex having a different colour. The colours are generated by overlapping 3 phase shifted sines (rgb) translated with the current time to animate them.

It's pretty worthless tho, also wanted to do it for all prop_physics on the server to simulate some kind of trip but it's too performance intensive
 
Reactions: List

jamEs

fqjdlkmsbvqfgkhpoiuaeazer
Joined
Apr 26, 2016
Messages
1,155
Nebulae
3,345
Tried to implement the discrete fourier transform in C++



if there's any C++ wizards out there, tell me why my code is bad pls

Also doesn't work because
iHUWmaM.png


is the plot I'm getting out of it while there should only be one peak at 880 Hz