[B]init.lua[/B]
[CODE]
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
AddCSLuaFile("round.lua")
include("shared.lua")
function GM:Initialize()
-- TODO:Before starting the round, check if there are at least 3 players.
-- print(GAMEMODEDATA:GetGameState())
print("WARMUP:" .. self.state)
ROUND:RestartRound()
end
local function ServerInit()
GAMEMODE.state = WARMUP
end
hook.Add("Initialize","server_init_hook",ServerInit)
[/CODE]
[B]shared.lua[/B]
[CODE]
--------------------------
--- Gamemode constants ---
--------------------------
--Round States
WARMUP = 1
FIGHTING = 2
FINISHED = 3
--Round time (time is in minutes)
WARMUP_TIME = 0.5
FIGHTING_TIME = 5
FINISHED_TIME = 0.25
include("round.lua")
function GM:PlayerConnect(name, ip)
--This does work
--print("ss" .. GAMEMODE.state)
print(ROUND:GetRemainingTime() .. " " .. self.state)
end
function GM:GetGameState()
return self.state
end
[/CODE]
[B]cl_init.lua[/B]
[CODE]
--TODO:Encapsulate the GAMEMODE so the client doesn't have direct
--access to it. -- Encapsulate for code tidnes actuallly
include("shared.lua")
function GM:PlayerConnect(name, ip)
print("ho")
--PrintMessage( HUD_PRINTTALK, name .. " has joined the game." )
end
function GM:PlayerTick()
--print(" " .. self:GetGameState())
--ROUND:GetRemainingTime()
print(ROUND:GetRemainingTime() .. " ")-- .. self.state)
end
[/CODE]
You're not networking the gamemode's state to the client.
[QUOTE=Willox;47844003]You're not networking the gamemode's state to the client.[/QUOTE]
Oh..umm how do I do that?
I mean like can you give me a pointer into where to look to? Not a solution since I don't want to take up your time :P
To keep it simple you could use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/SetGlobalInt]SetGlobalInt[/url] and [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/GetGlobalInt]GetGlobalInt[/url]
[QUOTE=Willox;47844055]To keep it simple you could use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/SetGlobalInt]SetGlobalInt[/url] and [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/GetGlobalInt]GetGlobalInt[/url][/QUOTE]
Oh that's pretty awesome, thank you for all of your help! I didn't realize you had to network the data between the client and server (even though it makes a lot of sense). Appreciate it :)
Anybody know how to make some sort of script that, every 3 seconds(without using timers), will make the player emit a random sound? I know I have to do something with a think hook and use CurTime()(or is there a different method that doesn't use times?), but I don't know what.
Why can't you use timers?
-snip-
late
[QUOTE=Willox;47844535]Why can't you use timers?[/QUOTE]
Well, I feel a little OCDish about repeated timer use(after all if used in the wrong place they can break prediction), so I wanted to use curtime and think hooks and whatnot. Don't forget that this, if it was a timer, would be repeated forever, basically.
Is there a way to return the finished traces of ShootBullet( )? I need to create tracers that go to the final hitpos.
[QUOTE=A Fghtr Pilot;47844533]Anybody know how to make some sort of script that, every 3 seconds(without using timers), will make the player emit a random sound? I know I have to do something with a think hook and use CurTime()(or is there a different method that doesn't use times?), but I don't know what.[/QUOTE]
Basic setup will look like this:
[code]
local threshold = 3.0
local _lastFired = 0
hook.Add("Think", "SomeName", function()
if CurTime() - _lastFired >= threshold then
_lastFired = CurTime()
-- do something
end
end)
[/code]
[QUOTE=wauterboi;47844653]Is there a way to return the finished traces of ShootBullet( )? I need to create tracers that go to the final hitpos.[/QUOTE]
if you want to use effects, use bullet.TracerName with the name of the effect. effectdata:GetOrigin() is where the bullet hit, and i have startpos set to
[code]
local owner = data:GetEntity():GetOwner()
if owner == LocalPlayer() and owner:GetViewEntity() == owner then
self.StartPos = owner:GetViewModel():GetAttachment(1).Pos
else
if not IsValid(data:GetEntity()) or not data:GetEntity():GetAttachment(1) then return end
self.StartPos = data:GetEntity():GetAttachment(1).Pos
end
[/code]
otherwise, without effects, bullet.Callback = function(attacker, trace, dmginfo)
[QUOTE=skullorz;47844757]if you want to use effects, use bullet.TracerName with the name of the effect. effectdata:GetOrigin() is where the bullet hit, and i have startpos set to
[code]
local owner = data:GetEntity():GetOwner()
if owner == LocalPlayer() and owner:GetViewEntity() == owner then
self.StartPos = owner:GetViewModel():GetAttachment(1).Pos
else
if not IsValid(data:GetEntity()) or not data:GetEntity():GetAttachment(1) then return end
self.StartPos = data:GetEntity():GetAttachment(1).Pos
end
[/code]
otherwise, without effects, bullet.Callback = function(attacker, trace, dmginfo)[/QUOTE]
You're a winner, man. I've been stuck on that for a long while.
Uh, question, is there some sort of version of LocalPlayer() I can use serverside? This is kind of a follow-up to my last question about emitting a sound every 3 seconds, but it can only be done clientside, so I can emit a sound from the player without using player.GetByID().
Entity:EmitSound wiki page:
"Plays a sound on an entity. If run clientside, the sound will only be heard locally."
So, because GM:Think() has no arguments for a local player, what could I use to emit a sound clientside but make it be heard by all players serverside? I'm thinking net messages are the only answer, but I don't want to send one every 10 seconds(unless that's okay to do)
Use PlayerTick instead of Think.
What exactly does physobj:GetStress() output?
I assume it's units of force (kg*source unit/s^2), but it returns 2 numbers that appear to mean slightly different things.
Is there a way to detect if a player is the only one alive? I have a for loop that does an action for each player, if they have a certain steam ID and are alive, but I would like to do it only if they are the [I]only[/I] person alive. Thanks!
[QUOTE=B10H4Z4RD;47846399]Is there a way to detect if a player is the only one alive? I have a for loop that does an action for each player, if they have a certain steam ID and are alive, but I would like to do it only if they are the [I]only[/I] person alive. Thanks![/QUOTE]
If your gamemode utilizes a spectator team, then you could check the number of people on the non-spectator team. If only one person is there, then only one is alive. Other than that, declare a table, loop through player.GetAll and place the player into the table if they are alive. If the length of the table is 1, then the person is the only one alive. Then, you can get the player object by getting the value at the first index.
Anyone know what I could use to recreate use of the "Enter" key with surface.DrawText? If I try to draw more than one thing of text in a HUDPaint hook it simply doesn't show, so I need to make one thing of text that is multiple "paragraphs".
Is there any better way in the menu state to get when the player joins and leaves a game than using a think hook and IsInGame?
[QUOTE=A Fghtr Pilot;47846804]Anyone know what I could use to recreate use of the "Enter" key with surface.DrawText? If I try to draw more than one thing of text in a HUDPaint hook it simply doesn't show, so I need to make one thing of text that is multiple "paragraphs".[/QUOTE]
\n for "" strings or [[]] for multi-line content.
[URL="http://www.lua.org/pil/2.4.html"]Strings in Lua[/URL]
Do matproxies not work on materials in the vgui/ folder or am I doing it wrong?
Trying to put together my first SWEP by basically just studying other SWEPs to figure out how the basics all work. If I'm correct this SHOULD work, but it's not showing up in my Spawn Menu? I'm assuming I'm missing something really simple
[CODE]if SERVER then
AddCSLuaFile ("shared.lua")
SWEP.Weight = 5
SWEP.AutoSwitchTo = false
SWEP.AutoSwitchFrom = false
end
if CLIENT then
SWEP.PrintName = "Caledfwlch"
SWEP.Slot = 2
SWEP.SlotPos = 1
SWEP.DrawAmmo = false
SWEP.DrawCrosshair = true
SWEP.WepSelectIcon = surface.GetTextureID( "icons/weapons/caledfwlch" )
killicon.AddFont( SWEP.ClassName, "Caledfwlch", SWEP.IconLetter, Color( 255, 80, 0, 255 ) )
end
SWEP.Author = "Becomeimp"
SWEP.Contact = "becomeluna@gmail.com"
SWEP.Purpose = "Caledfwlch"
SWEP.Instructions = "Left-Click to Agress!"
SWEP.Category = "Homestuck (Becomeimp)"
SWEP.Spawnable = true
SWEP.AdminSpawnable = true
SWEP.ViewModel = "models/homestuck/weapons/c_caledfwlch.mdl"
SWEP.WorldModel = "models/homestuck/weapons/w_caledfwlch.mdl"
SWEP.HoldType = "melee"
SWEP.Base = "weapon_base"
SWEP.UseHands = true
SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = -1
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = "none"
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = "none"
function SWEP:Initialize()
self:SetWeaponHoldType( self.HoldType )
end
function SWEP:Deploy()
self.Weapon:SendWeaponAnim( ACT_VM_DRAW )
self:SetDeploySpeed( self.Weapon:SequenceDuration() )
self.Weapon:EmitSound("weapons/draw_melee.wav")
return true
end
function SWEP:Reload()
end
function SWEP:Think()
end
function SWEP:PrimaryAttack()
self.Weapon:SendWeaponAnim(ACT_VM_PRIMARYATTACK)
self.Weapon:SetNextPrimaryFire(CurTime() + 0.8)
local trace = self.Owner:GetEyeTrace()
if trace.HitPos:Distance(self.Owner:GetShootPos()) <= 85 then
bullet = {}
bullet.Num = 1
bullet.Src = self.Owner:GetShootPos()
bullet.Dir = self.Owner:GetAimVector()
bullet.Spread = Vector(0, 0, 0)
bullet.Tracer = 0
bullet.Force = 2
bullet.Damage = 65
self.Owner:FireBullets(bullet)
self.Owner:SetAnimation( PLAYER_ATTACK1 );
local randomsounds = {
"weapons/blade_hitworld.wav",
"weapons/blade_slice_2.wav",
"weapons/blade_slice_3.wav",
"weapons/blade_slice_4.wav"
}
local random = math.random(1, #randomsounds)
self.Owner:EmitSound(randomsounds[random])
else
self.Weapon:EmitSound("weapons/cbar_miss1.wav")
self.Weapon:SendWeaponAnim(ACT_VM_PRIMARYATTACK)
self.Owner:SetAnimation( PLAYER_ATTACK1 )
end
end
function SWEP:SecondaryAttack()
end[/CODE]
Gonna take a wild guess: remove the "shared.lua" part from AddCSLuaFile if you named the file what your swep is called (like weapon_hi.lua) instead of putting it in a folder with shared, init, cl_init.lua files.
Shouldn't SWEP.Base = "awb_base" carry over the entire SWEP table from awb_base?
Getting a bug with my SWEP;
[lua]
function SWEP:PrimaryAttack()
self:EmitSound("shoot.wav")
end
[/lua]
The shoot sound is playing in singleplayer but not multiplayer.
All the other sounds for the weapon (like reloading) are working fine however.
Any idea why? I can't seem figure this one out at all.
I'm having trouble with my SWEP. Whenever I kill myself, it shows the following error:
[code]
[ERROR] addons/rebelsvscombine/lua/weapons/dm_base_hl2/shared.lua:126: attempt to perform arithmetic on a nil value
1. unknown - addons/rebelsvscombine/lua/weapons/dm_base_hl2/shared.lua:126
[/code]
This is line 126(it's in SWEP:Deploy, I'll paste the whole code for it)
[code]function SWEP:Deploy()
self:SendWeaponAnim(ACT_VM_DRAW)
self.Weapon:SetNextPrimaryFire( CurTime() + self:SequenceDuration() )
self.Weapon:SetNextSecondaryFire( CurTime() + self:SequenceDuration() )
self:SetNextIdle( CurTime() + self:SequenceDuration() )
self.Primary.Spread = self.IronSightsInactiveSpread
self:SetNWBool( "Reload" .. self:EntIndex(), true )
return true
end
[/code]
I even put
[code]if not self.Owner:Alive() then return end[/code] and it still doesn't work. What's wrong?!
[QUOTE=101kl;47851871]Getting a bug with my SWEP;
[lua]
function SWEP:PrimaryAttack()
self:EmitSound("shoot.wav")
end
[/lua]
The shoot sound is playing in singleplayer but not multiplayer.
All the other sounds for the weapon (like reloading) are working fine however.
Any idea why? I can't seem figure this one out at all.[/QUOTE]
verify it's on the server and check for errors
Reading over my original post, I just realized how vague I was.
[video=youtube;FX8cDFL3ZRQ]https://www.youtube.com/watch?v=FX8cDFL3ZRQ[/video]
8:18 in that video is what I'm trying to accomplish with my gamemode. I want the player be able to make turns like that and allow the camera to follow. Mornedil definitely set me on the right track, but I'm struggling with traces. Is there a reference that anyone knows of besides the Gmod wiki that is actually helpful? Thank you.
[QUOTE=Obswalq;47857142]Reading over my original post, I just realized how vague I was.
[video=youtube;FX8cDFL3ZRQ]https://www.youtube.com/watch?v=FX8cDFL3ZRQ[/video]
8:18 in that video is what I'm trying to accomplish with my gamemode. I want the player be able to make turns like that and allow the camera to follow. Mornedil definitely set me on the right track, but I'm struggling with traces. Is there a reference that anyone knows of besides the Gmod wiki that is actually helpful? Thank you.[/QUOTE]
This is [I]kinda[/I] like the GMod wiki, but it's a mirror of the old one: [url]https://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index5636.html[/url] this is a guide on traces. I've noticed that most stuff on this guide on traces isn't outdated. Hope this helps...
[editline]Edited:[/editline]
So, what you could do is maybe set the player's eyeangles based on the camera? I myself don't know many functions that return which position the camera is at, but maybe GetAimVector or GetShootPos will help? Anyways, here's the example use of setting the player's eye angles(from a SWEP code, but it'll work similarly):
[code] local eyeang = self.Owner:EyeAngles()
eyeang.pitch = eyeang.pitch - self.RecoilUp
self.Owner:SetEyeAngles( eyeang )
[/code]
if you need more of a reference for traces, after you've read the trace tutorial and looked at some structures, here's an example(a swep code that has a pistol whip function; melee attack codes almost ALWAYS use traces and player:LagCompensation(true) and player:LagCompensation(false):
[code]if SERVER then
AddCSLuaFile("shared.lua")
end
SWEP.PrintName = "Pistol"
SWEP.Author = ""
SWEP.Contact = ""
SWEP.Purpose = ""
SWEP.Instructions = ""
SWEP.Base = "dm_base_hl2"
SWEP.UseHands = true
SWEP.Category = "The Rebel SWEPs"
SWEP.Spawnable = true
SWEP.AdminSpawnable = true
SWEP.ViewModelFlip = false
SWEP.ViewModel = "models/weapons/c_pistol.mdl"
SWEP.WorldModel = "models/weapons/w_pistol.mdl"
SWEP.ViewModelFOV = 54
SWEP.AutoSwitchTo = true
SWEP.AutoSwitchFrom = true
SWEP.Slot = 0
SWEP.SlotPos = 0
SWEP.HoldType = "pistol"
SWEP.FiresUnderwater = false
SWEP.Weight = 25
SWEP.ShowViewModel = true
SWEP.ShowWorldModel = true
SWEP.Primary.ClipSize = 18
SWEP.Primary.Ammo = "Pistol"
SWEP.Primary.DefaultClip = 72
SWEP.Primary.Automatic = false
SWEP.Primary.Force = 1
SWEP.Primary.Spread = 1
SWEP.Primary.Recoil = 4
SWEP.Primary.Delay = 0.1
SWEP.Primary.NumberofShots = 1
SWEP.Primary.Cone = 0.1
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.Ammo = "none"
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Damage1 = 20
SWEP.Damage2 = 30
SWEP.RecoilUp = 3
SWEP.RecoilDown = -3
SWEP.RecoilSideLeft = 2
SWEP.RecoilSideRight = -2
SWEP.PrimSpread = 0.50
SWEP.WalkSpread = 1
SWEP.Primary.WalkSpread = 1.25
SWEP.Primary.WepSpread = 0.75
SWEP.Primary.IdleSpread = 0.75
SWEP.SwepSound = "Weapon_Pistol.NPC_Single"
SWEP.FireRate = 0.10
if SERVER then
SWEP.Name = "pistol"
end
if CLIENT then
killicon.AddFont( "dm_pistol", "HL2MPTypeDeath", "-", Color( 255, 80, 0, 255 ) )
end
--pistol whip functionality
function SWEP:SecondaryAttack()
self.Weapon:EmitSound( "WeaponFrag.Throw" )
self.Owner:ViewPunch( Angle( 15, 15, 15 ) )
self.Owner:DoCustomAnimEvent( PLAYERANIMEVENT_ATTACK_GRENADE , 123 )
self.Weapon:SendWeaponAnim( ACT_VM_LOWERED_TO_IDLE )
self:SetNextIdle( CurTime() + self:SequenceDuration() )
local tracedata = {}
tracedata.start = self.Owner:GetShootPos()
tracedata.endpos = self.Owner:GetShootPos() + self.Owner:GetAimVector() * 75
tracedata.filter = self.Owner
tracedata.mins = Vector( -8 , -8 , -8 )
tracedata.maxs = Vector( 8 , 8 , 8 )
if ( self.Owner:IsPlayer() ) then
self.Owner:LagCompensation( true )
end
local tr = util.TraceHull( tracedata )
if ( self.Owner:IsPlayer() ) then
self.Owner:LagCompensation( false )
end
if tr.Hit then
print( tr.Entity ) --your code here
self.Weapon:EmitSound( "Flesh.ImpactHard" )
if ( tr.Entity:IsPlayer() ) then
if SERVER then
tr.Entity:TakeDamage( 40 )
end
end
end
self:SetNextSecondaryFire( CurTime() + 0.40 )
self:SetNextPrimaryFire( CurTime() + 0.60 )
end
hook.Add( "DoAnimationEvent" , "AnimEventTest" , function( ply , event , data )
if event == PLAYERANIMEVENT_ATTACK_GRENADE then
if data == 123 then
ply:AnimRestartGesture( GESTURE_SLOT_ATTACK_AND_RELOAD, ACT_HL2MP_GESTURE_RANGE_ATTACK_MELEE, true )
end
return ACT_INVALID
end
end )
[/code]
Sorry, you need to Log In to post a reply to this thread.