This code works in singleplayer but is shit for multiplayer, how would i make it properly predict?
[lua]
function SWEP:PrimaryAttack()
if not self.Weapon:CanPrimaryAttack() then return end
if self.Bursts < 2 and self.NextBurst < CurTime() then
self.Bursts = self.Bursts + 1
self.NextBurst = CurTime() + self.Primary.Burst
self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Burst )
elseif self.Bursts >= 2 then
self.Bursts = 0
self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
end
self.Weapon:ShootBullets( self.Primary.Damage, self.Primary.NumShots, self.Primary.Cone )
self.Weapon:TakePrimaryAmmo( 1 )
if IsFirstTimePredicted() then
self.Weapon:EmitSound( self.Primary.Sound, 100, math.random(95,105) )
if SERVER then
local scale = 0.50
if self.Owner:KeyDown( IN_DUCK ) then
scale = 0.25
elseif self.Owner:KeyDown( IN_FORWARD ) or self.Owner:KeyDown( IN_BACK ) or self.Owner:KeyDown( IN_MOVELEFT ) or self.Owner:KeyDown( IN_MOVERIGHT ) then
scale = 0.60
end
local pang, yang = math.Rand( -1 * scale, 0 ) * self.Primary.Recoil, math.Rand( -1 * ( scale / 3 ), ( scale / 3 ) ) * self.Primary.Recoil
self.Owner:ViewPunch( Angle( pang, yang, 0 ) )
self.Owner:AddAmmo( -1 )
timer.Simple( math.Rand( 0.4, 0.6 ), function() if IsValid( self ) then sound.Play( table.Random( self.ShellSounds[ self.ShellType ].Wavs ), self.Owner:GetPos(), 75, self.ShellSounds[ self.ShellType ].Pitch + math.random( -5, 5 ) ) end end )
end
end
end
function SWEP:Holster()
return self.Bursts == 0
end
function SWEP:Think()
if self.Bursts > 0 and self.NextBurst < CurTime() then
self.Weapon:PrimaryAttack()
end
end
function SWEP:Reload()
if SERVER and self.Owner:GetAmmo() < 1 then return end
if CLIENT and GAMEMODE:GetInt( "Ammo" ) < 1 then return end
if self.Weapon:Clip1() == self.Primary.ClipSize or self.Bursts != 0 then return end
self.Weapon:DefaultReload( ACT_VM_RELOAD )
end[/lua]
How would you go about adding a swep to a class? e.g. perfect climbing swep.
How would I change the attacker in EntityTakeDamage? If a certain entity damages a player, I'd like to set the entity that's damaging the player to a different player, instead of that entity.
[QUOTE=Paulmol;38189633]How would you go about adding a swep to a class? e.g. perfect climbing swep.[/QUOTE]
Use the class's PLAYER:Loadout() hook.
See here: [url]http://wiki.garrysmod.com/page/Player_Classes[/url]
[QUOTE=.\\Shadow};38189643]How would I change the attacker in EntityTakeDamage? If a certain entity damages a player, I'd like to set the entity that's damaging the player to a different player, instead of that entity.[/QUOTE]
Couldn't you use [url=http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index4589.html]dmginfo:SetAttacker()[/url]?
[QUOTE=Luni;38189694]Couldn't you use [url=http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index4589.html]dmginfo:SetAttacker()[/url]?[/QUOTE]
Didn't even know about that. Guess the wiki should be the first place I should look, hah. Thanks!
Hmph.
Is there any way to [b]undo[/b] the effects of panel:MakePopup(), so it doesn't render on top of the GMod menu? I tried panel:ParentToHUD() and taking keyboard/mouse focus, but that doesn't seem to do anything except make it disappear completely when the menu's open (which is not ideal).
I wana do something so that when i shoot a npc bluelaser1.vtf comes out in a chain.
im trying to learn lua.
thanks in advance.
[QUOTE=thejjokerr;38190611]Since I still have no idea how to properly change the GWEN skin my panels use, I've gone the hacky way:
[lua]local old = Material("gwenskin/GModDefault.png");
local new = Material("gwenskin/MyGWENSkin.png");
old:SetTexture("$basetexture", new:GetTexture("$basetexture"));[/lua]
Most of the time this works fine, but sometimes this happens to the border of my panels:
[img]http://i.imgur.com/NMRkd.png[/img]
Anyone already know how to properly set the GWEN skin, without these hacky ways? Or know how to fix this problem.[/QUOTE]
[url]http://luabin.overvprojects.nl/svn/lua/skins/default.lua[/url]
Copy that and rename it to whatever.lua, change SKIN.GwenTexture to your own png, then use panel:SetSkin( "yourskin" )
[editline]26th October 2012[/editline]
[QUOTE=Luni;38189752]Hmph.
Is there any way to [b]undo[/b] the effects of panel:MakePopup(), so it doesn't render on top of the GMod menu? I tried panel:ParentToHUD() and taking keyboard/mouse focus, but that doesn't seem to do anything except make it disappear completely when the menu's open (which is not ideal).[/QUOTE]
[lua]
gui.EnableScreenClicker( false )
self:KillFocus()
self:SetKeyboardInputEnabled( false )
self:SetMouseInputEnabled( false )[/lua]
my legacy swep world models are invisible. No big red error, just completely invisible. I'm working on packaging them for the workshop, but before I do, I want to fix this goofy error.
How do I get world models to show again?
[QUOTE=Drakehawke;38190757][lua]
gui.EnableScreenClicker( false )
self:KillFocus()
self:SetKeyboardInputEnabled( false )
self:SetMouseInputEnabled( false )
[/lua][/QUOTE]
It still draws above GMod's menu. :|
I need to know how the new Dmginfo works, if somebody could give me an example, please.
Is there a way to spawn entities on the client anymore? ents.Create doesn't exist on the client... Say, for example, i wanted to spawn an ambient_generic or something.
Yeah I was wondering the same, This is the last piece I need to fix.
[LUA]
if ( tr.Hit ) then
local ent = ents.Create ("ent_tripmine")
if ( ent ~= nil and ent:IsValid() ) then
ent:SetPos(tr.HitPos)
//ent:SetOwner(self.Owner)
ent.User = self.Owner
ent:Spawn()
ent:Activate()
ent.EntHealth = 300
self.Owner:EmitSound( "weapons/slam/mine_mode.wav" )
self.Owner:SetAnimation(PLAYER_ATTACK1)
self.Weapon:SendWeaponAnim(ACT_VM_THROW)
timer.Create("trippulltimer",0.8,1,function()
if (IsValid(self) and IsEntity(self)) then
self:Remove()
elseif SERVER then
MsgN("Tripmine: Failed to remove on Placement - Already removed?")
end
end,self)
ent:GetTable():StartTripmineMode( tr.HitPos + tr.HitNormal, tr.HitNormal )
self:TakePrimaryAmmo( 1 )
end
end
end[/LUA]
I need some help with file.Read()
[LUA]
function TestingFileRead( ply )
print("--------")
print( file.Read( "helloworld.txt", "Data" ) ) -- Prints Hello World
end
concommand.Add("TestingFRead", TestingFileRead )
[/LUA]
This prints the file Helloworld.txt which is located in the Data folder but when I try to move that text file to another folder located within the data folder and read it from there it doesn't work.
[LUA]
function TestingFileRead( ply )
print("--------")
print( file.Read( "helloworld.txt", "Data/TestFolder" ) ) -- Prints nothing
end
concommand.Add("TestingFRead", TestingFileRead )
[/LUA]
Anyone mind helping me out?
[QUOTE=McDunkable;38194392]I need to know how the new Dmginfo works, if somebody could give me an example, please.[/QUOTE]
What do you mean by how it works? If you need to see its class methods just check the [url=http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index7801.html]wiki[/url]
[QUOTE=I Fail At Lua;38195320]I need some help with file.Read()
[/QUOTE]
You've got your argument mixed up, probably because the wiki article doesnt explain what it means by "path". The first argument to file.Read() is the actual file path (e.g. "chimera/logs.txt"), while the second argument is the directory set that the path starts in ("DATA", "LUA", "MOD" or "GAME"). Those are [i]not[/i] necessarily folder names.
The article for [url=http://wiki.garrysmod.com/page/Libraries/file/Find]file.Find()[/url] does a much better job of explaining how each path type works (under Additional Notes).
[QUOTE=Luni;38196216]
You've got your argument mixed up, probably because the wiki article doesnt explain what it means by "path". The first argument to file.Read() is the actual file path (e.g. "chimera/logs.txt"), while the second argument is the directory set that the path starts in ("DATA", "LUA", "MOD" or "GAME"). Those are [i]not[/i] necessarily folder names.
The article for [url=http://wiki.garrysmod.com/page/Libraries/file/Find]file.Find()[/url] does a much better job of explaining how each path type works (under Additional Notes).[/QUOTE]
Oh that explains it, thanks for the help man!
How would I go about deleting a entity with a certain Entity:SetName("name")
Example
Make a entity with Entity:SetName("carl")
Then I need a way to delete all entitys with their name being "carl"
Or how can I remove by id?
[QUOTE=J.R.;38197669]How would I go about deleting a entity with a certain Entity:SetName("name")
Example
Make a entity with Entity:SetName("carl")
Then I need a way to delete all entitys with their name being "carl"
Or how can I remove by id?[/QUOTE]
[lua]
for k, v in pairs (ents.FindByName("carl")) do
v:Remove()
end
[/lua]
try that
No no, what I need is how the new dmginfo works or if the class method was changed to something else, as of now it's nil
Thanks.
[QUOTE=McDunkable;38198739]No no, what I need is how the new dmginfo works or if the class method was changed to something else, as of now it's nil
Thanks.[/QUOTE]
[lua]
function GM:EntityTakeDamage(ent,dmginfo)
local inflictor = dmginfo:GetInflictor()
local attacker = dmginfo:GetAttacker()
local damage = dmginfo:GetDamage() //or GetAmount(), not sure
// do stuff
end
[/lua]
[QUOTE=Persious;38148480]
[editline]23rd October 2012[/editline]
Does anyone know if Spacetech will update his gmsv_teleport module?[/QUOTE]
Anyone able to re-convert it? :(
is there a hook that controls what decals/effects are used when you shoot a player? I searched the base gamemode files and i didn't see anything, maybe there's some other file i missed?
Can someone please give me a example of a working DVScrollBar?
I've been cracking my head and didn't get it working...
Anyone know how to remove this thing:
[IMG]http://puu.sh/1j8Ks[/IMG]
from a DListView?
I get this error when I try to add a new task to an AI schedule. Any ideas?
[lua]
local schedule = ai_schedule.New( "TestSched" )
schedule:AddTask( "FindEnemy", { Class = "player", Radius = 10000 } )
[/lua]
[lua]
[ERROR] lua/includes/modules/ai_schedule.lua:58: attempt to index global 'ai_task' (a nil value)
1. AddTask - lua/includes/modules/ai_schedule.lua:58
2. SelectSchedule - gamemodes/cokescript/entities/entities/npc_zombie/init.lua:56
3. unknown - gamemodes/base/entities/entities/base_ai/schedules.lua:28
[/lua]
So i'm really bad at lua, and was wondering how I could make a standalone timer to run a console command.
Here's what i'm doing with GoldenForge:
[CODE]timer.Create( "metal", 10, 1, function()
for k, v in pairs (player.GetAll()) do
if !v:IsUserGroup("vip") then
RunConsoleCommand("gf_gvspml", v, 10)
v:PrintMessage( HUD_PRINTCENTER, "Thanks for playing! You have been given 10 scrap metal!" )
else
RunConsoleCommand("gf_gvspml", v, 25)
v:PrintMessage( HUD_PRINTCENTER, "Thanks for donating! You have been given 25 scrap metal!" )
end
end
end)[/CODE]
But with GoldenForge, I cannot edit anything. If I edit something, my server refuses to start. So It has to happen in an outside file (using console commands). How would I make that in a standalone/autorun lua? Or would slapping it in a lua file do fine? Or am I retarted and is my code flawed?
Edit: Changed to timer.Create
Edit: Fixed, took some time but I did it :D
[CODE]function StartTimer()
timer.Create( "metal", 600, 0, function()
for k, v in pairs (player.GetAll()) do
local name = v:GetName()
if !v:IsUserGroup("vip") and !v:IsUserGroup("rarityvip") and !v:IsUserGroup("satvip") and !v:IsUserGroup("zaphervip") then
v:GiveScrapMetal(10, "Thanks for playing! You have been given 10 scrap metal!")
v:PrintMessage( HUD_PRINTCENTER, "Thanks for playing! You have been given 10 scrap metal!" );
else
v:GiveScrapMetal(25, "Thanks for donating! You have been given 25 scrap metal!")
v:PrintMessage( HUD_PRINTCENTER, "Thanks for donating! You have been given 25 scrap metal!" );
end
end
end)
end
hook.Add( "PlayerConnect", "ConcommandTimer", StartTimer )[/CODE]
Is anyone good with animations? They seem to be the least documented feature of Garry's Mod. I need to force a player to play the crowbar swinging animation in third person even when their holdtype is not melee. If anyone can help me out, you will save me hours of troubleshooting.
-snip- im dumb
[QUOTE=samm5506;38203957]Is anyone good with animations? They seem to be the least documented feature of Garry's Mod. I need to force a player to play the crowbar swinging animation in third person even when their holdtype is not melee. If anyone can help me out, you will save me hours of troubleshooting.[/QUOTE]
if you are inside a swep (IE PrimaryAttack) use:
[lua]
self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER);
[/lua]
else you can force it on the player by using
[lua]
ply:GetActiveWeapon():SendWeaponAnim(ACT_VM_HITCENTER)
[/lua]
Sorry, you need to Log In to post a reply to this thread.