[QUOTE=serfma;46085683]May I ask why the changes were needed? Just curious so I know in the future. :)
Thanks a lot, by the way, it all works great![/QUOTE]
It takes less bytes to send (on average).
4 bytes for sending an entity vs ~1-30+ bytes for nick to send
1-4 bytes for sending an integer vs ~1-12 bytes for level to send
It's also a better coding style. You know that net.ReadInt() returns an integer while
you don't necessarily know what the content of a string is.
[QUOTE=syl0r;46085714]It takes less bytes to send (on average).
4 bytes for sending an entity vs ~1-30+ bytes for nick to send
4 bytes for sending an integer vs ~1-12 bytes for level to send
It's also a better coding style. You know that net.ReadInt() returns an integer while
you don't necessarily know what the content of a string is.[/QUOTE]
Ahh thanks!
-snip- Ignore that if you saw it already. Forgot to add parenthesis. :)
Order of operations - you're adding 20 to their level.
( plylvl + 1 ) * 20
Oh god shoot me now. My bullet callback function doesn't work?
This code is gonna look VERY MESSY to you, I'm sure.
[code] local bullet = {}
bullet.Num = self.Primary.NumShots
bullet.Src = self.FirePos
bullet.Dir = self.FireVec
if self.UseOffBase then bullet.Dir = self.FireVec + self.Owner:GetRight() * math.cos( OffBase ) * self.OffMul * SecOffMul * (1+VelM*100) + self.Owner:GetUp() * math.sin( OffBase ) * self.OffMul * SecOffMul * (1+VelM*100) end
if self:GetSpecial() then
bullet.Spread = Vector( self.Primary.SpecialSpread*self.AntiRelax*SpMul, self.Primary.SpecialSpread*self.AntiRelax*SpMul, 0 )
else
bullet.Spread = Vector( self.Primary.BaseSpread*self.AntiRelax*SpMul, self.Primary.BaseSpread*self.AntiRelax*SpMul, 0 )
end
bullet.Tracer = self.Primary.TraceInterval
bullet.TracerName = self.Primary.TracerName
bullet.Force = math.random( self.Primary.ForceMin, self.Primary.ForceMax )
if self:GetSpecial() then
bullet.Damage = math.random( self.Primary.SpclDMGMin, self.Primary.SpclDMGMax )
else
bullet.Damage = math.random( self.Primary.RegDMGMin, self.Primary.RegDMGMax )
end
bullet.AmmoType = self.Primary.AmmoType
bullet.Callback = function( plr, tr, dmg )
if tr.HitGroup == HITGROUP_HEAD then
local d = DamageInfo()
d:SetDamage( bullet.Damage * 5 )
d:SetAttacker( self.Owner )
d:SetDamageForce( tr.Normal * 200 )
d:SetDamageType( DMG_BULLET )
end
print( "Callback" )
end[/code]
[editline]don't you love editline? This was not an auto-merge.[/editline]
It does not print "Callback" to the console, meaning the function is not even being called!
Are you actually calling Entity:FireBullets() somewhere?
[QUOTE=syl0r;46086144]Are you actually calling Entity:FireBullets() somewhere?[/QUOTE]
Indeed I am. It's in a messy function a little lower in the PrimaryAttack(), paired with code that enables my suicide sweps :smile:
[code] if SERVER then
self.Owner:LagCompensation( true )
if self.Suicide && self:GetIronsights() then
local dmginfo = DamageInfo()
-- print( self.Owner:LookupAttachment( "eyes" ) )
local vPoint = self.Owner:GetAttachment( self.Owner:LookupAttachment( "eyes" ) ).Pos
local vPoint = vPoint + self.Owner:GetAttachment( self.Owner:LookupAttachment( "eyes" ) ).Ang:Forward()*-5
local effectdata = EffectData()
effectdata:SetOrigin(vPoint)
effectdata:SetStart(vPoint)
effectdata:SetEntity(self.Owner)
effectdata:SetColor( self.Owner:GetBloodColor() )
for n = 0, 3 do
util.Effect( "BloodImpact", effectdata )
end
self.Owner:SetVelocity( self.Owner:GetAimVector():Angle():Right() * -420 )
dmginfo:SetDamage( 10000 ) -- Definitely an instant kill
dmginfo:SetDamageType( DMG_BULLET )
dmginfo:SetAttacker( self )
dmginfo:SetDamageForce( Vector( 0, 0, -1000 ) ) -- Slam to the ground
sound.Play( "containment/celebrate2.wav", self:GetPos(), 150, 117, 1 ) -- Celebrate the fact that YOU JUST KILLED YOUR MOTHER FUCKING SELF!!! YEA-AHHH!!!
timer.Simple( 0.11, function() if self:IsValid() && self.Owner:IsValid() then self.Owner:TakeDamageInfo( dmginfo ) end end )
else
self.Owner:FireBullets( bullet )
end
self.Owner:LagCompensation( false )
end[/code]
Old version of the FIRST suicide gun I made, just in case you're curious!
[video=youtube;VtMj3sOjvTo]http://www.youtube.com/watch?v=VtMj3sOjvTo[/video]
[editline]Self inserted editlines[/editline] Self inserted editlines [editline]Self inserted editlines[/editline]
There were a few reasons I wanted to make a suicide gun... including the fact that it has less consequences than actually committing suicide... :suicide:
HOWEVER, this problem is in NO WAY RELATED to the suicide guns.
After noticing some problems with how view model animations were playing on my weapon base (sometimes weren't playing, a bit jittery as well here and there), I decided to do a few tests. This is the code I worked with:
[CODE]
--[[---------------------------------------------------------
Name: SWEP:PrimaryAttack( )
Desc: +attack1 has been pressed
-----------------------------------------------------------]]
function SWEP:PrimaryAttack( )
if ( not IsFirstTimePredicted() ) then return end
if ( not self:CanPrimaryAttack() ) then return end
self:EmitSound( self.Primary.Sound )
self:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
self.Owner:MuzzleFlash()
self.Owner:SetAnimation( PLAYER_ATTACK1 )
self:TakePrimaryAmmo( 1 )
self:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
end
[/CODE]
This was pretty much all that was in the shared file, so no other SWEP functions, just this one.
Anyways, basically, when using this code with a weapon, whenever I fire the gun, the view model fire animation is not always played correctly. What I mean by this is sometimes it plays properly, but sometimes it doesn't play at all or plays in a weird way such as jittering a bit. I ended up checking for prediction errors and I got a fair few which I'll provide down below. Furthermore, after removing IsFirstTimePredicted from the code, all of the issues were fixed (no prediction errors) and the view model animations played fine.
So ultimately I'm not sure why using IsFirstTimePredicted is causing these problems. Am I not using it right or something? Is it a known issue? Any help would be much appreciated. Thanks in advance.
Prediction errors with IsFirstTimePredicted:
[CODE]
001 CBaseViewModel::m_nSequence - int differs (net 8 pred 10) diff(2)
003 CBaseViewModel::m_nAnimationParity - int differs (net 0 pred 7) diff(7)
005 C_BaseAnimating::m_nMuzzleFlashParity - int differs (net 2 pred 1) diff(-1)
001 C_BaseAnimating::m_nMuzzleFlashParity - int differs (net 2 pred 1) diff(-1)
001 C_BaseAnimating::m_nMuzzleFlashParity - int differs (net 2 pred 1) diff(-1)
001 CBaseCombatWeapon::m_flNextPrimaryAttack - float differs (net 2047.221558 pred 2043.282104) diff(-3.939453)
002 CBaseCombatWeapon::m_flTimeWeaponIdle - float differs (net 2047.601563 pred 2043.662109) diff(-3.939453)
003 CBaseCombatWeapon::m_iClip1 - int differs (net 10 pred 11) diff(1)
005 CBaseCombatWeapon::m_flTimeWeaponIdle - float differs (net 2047.601563 pred 2043.662109) diff(-3.939453)
006 C_BaseAnimating::m_nMuzzleFlashParity - int differs (net 0 pred 3) diff(3)
[/CODE]
[QUOTE=syl0r;46086144]Are you actually calling Entity:FireBullets() somewhere?[/QUOTE]
Oh no, it's actually running the callback function now after I restarted the single-player session.
How do i bring a derma window to the top of everything?
[QUOTE=rebel1324;46086725]How do i bring a derma window to the top of everything?[/QUOTE]Top as in the front of everything or literally to the top/above? [url]http://wiki.garrysmod.com/page/Panel/MoveToFront[/url]
Trying to do a quick death ragdoll model swap but it doesn't seem to be working as intended. Rather, the switched model spazzes out something awful. Am I doing something wrong? How on earth do I even start to fix this?
[lua]
local deadModel = "models/Humans/Charple01.mdl"
hook.Add("CreateClientsideRagdoll","ChangeDeadModel",function( owner, ragdoll )
ragdoll:SetModel(deadModel)
end)
[/lua]
I've fixed the problem I had previously but now my weapon isn't doing anything besides playing the primary fire sound.
[lua]function SWEP:PrimaryAttack()
// Make sure we can shoot first
if ( !self:CanPrimaryAttack() ) then return end
self.Weapon:EmitSound( self.Primary.Sound );
if ( SERVER ) then
local pBall = ents.Create( "prop_combine_ball" )
pBall:SetOwner( pOwner );
pBall:SetPhysicsAttacker( pOwner );
pBall:SetPos( Vector( 0, 0, 32 ) );
pBall:SetVelocity( Vector ( 0, 0, 500 ) );
pBall:Spawn();
pBall:GetPhysicsObject():AddGameFlag( FVPHYSICS_DMG_DISSOLVE );
pBall:GetPhysicsObject():AddGameFlag( FVPHYSICS_WAS_THROWN );
pBall:GetPhysicsObject():SetVelocity( Vector( 0, 0, 500 ) );
pBall:SetModel( "models/Effects/combineball.mdl" );
end
end[/lua]
There's no Lua error either.
How would I change someone's in-game name like in DarkRP? (Not that I'm using DarkRP :v:)
I'm 90% sure there isn't a native function for this on the wiki, but please correct me if I'm wrong.
Would I just need to painstakingly go through each iteration of the name (i.e. on every hud object) and change it there?
I think I missed something
Does anyone know what's wrong with my code?
code: [url]http://pastebin.com/Gz5zafij[/url]
[media]http://www.youtube.com/watch?v=0PSeWGj6VS4&feature=youtu.be[/media]
[QUOTE=roachdaripper;46087513]I've fixed the problem I had previously but now my weapon isn't doing anything besides playing the primary fire sound.
[lua]function SWEP:PrimaryAttack()
// Make sure we can shoot first
if ( !self:CanPrimaryAttack() ) then return end
self.Weapon:EmitSound( self.Primary.Sound );
if ( SERVER ) then
local pBall = ents.Create( "prop_combine_ball" )
pBall:SetOwner( pOwner );
pBall:SetPhysicsAttacker( pOwner );
pBall:SetPos( Vector( 0, 0, 32 ) );
pBall:SetVelocity( Vector ( 0, 0, 500 ) );
pBall:Spawn();
pBall:GetPhysicsObject():AddGameFlag( FVPHYSICS_DMG_DISSOLVE );
pBall:GetPhysicsObject():AddGameFlag( FVPHYSICS_WAS_THROWN );
pBall:GetPhysicsObject():SetVelocity( Vector( 0, 0, 500 ) );
pBall:SetModel( "models/Effects/combineball.mdl" );
end
end[/lua]
There's no Lua error either.[/QUOTE]
You are setting the position of the ball to Vector(0,0,32). I am guessing that might be outside of the map or
far away from where you are when you fire the weapon.
[QUOTE=zeaga;46087964]How would I change someone's in-game name like in DarkRP? (Not that I play DarkRP :v:)
I'm 90% sure there isn't a native function for this on the wiki, but please correct me if I'm wrong.
Would I just need to painstakingly go through each iteration of the name (i.e. on every hud object) and change it there?[/QUOTE]
[LUA]
ply:getDarkRPVar("rpname")
[/LUA]
[QUOTE=rebel1324;46088162]I think I missed something
Does anyone know what's wrong with my code?
code: [url]http://pastebin.com/Gz5zafij[/url]
[media]http://www.youtube.com/watch?v=0PSeWGj6VS4&feature=youtu.be[/media][/QUOTE]
I am guessing that you mean the text overlaps other text?
I am pretty sure the problem is in this line.
[LUA]
v[3] = Lerp(frameTime * 5, v[3], ty * (k - 1))
[/LUA]
You are multiplying the height of the old text section times the position in the queue.
The thing is though if the previous entry has 3 lines and all others don't then it goes too high.
What you could do is this:
[LUA]
v[3] = Lerp(frameTime * 5, v[3], ty)
...
ty = ty + object:getHeight() -- (or -object:getHeight() depending on the order of the queue)
[/LUA]
[QUOTE=syl0r;46088321]You are setting the position of the ball to Vector(0,0,32). I am guessing that might be outside of the map or
far away from where you are when you fire the weapon.[/quote]
How do I get it to fire from my position? Is it 0, 0, 0?
I suggest [url=http://wiki.garrysmod.com/page/Player/GetShootPos]self.Owner:GetShootPos()[/url]
Super quick thing; I'm making a server menu thing and this is the code I'm using to connect the player:
[code]ply:SendLua([[RunConsoleCommand("connect", "IP AND PORT HERE")]])[/code]
It sort of works, like there doesn't seem to be any errors. Basically, it'll start loading you and then drop you to the main gmod menu. I noticed this occurred before when we made some !chat based commands for it.
Like, am I doing it wrong? I'd appreciate some assistance
[QUOTE=NiandraLades;46089192]Super quick thing; I'm making a server menu thing and this is the code I'm using to connect the player:
[code]ply:SendLua([[RunConsoleCommand("connect", "IP AND PORT HERE")]])[/code]
It sort of works, like there doesn't seem to be any errors. Basically, it'll start loading you and then drop you to the main gmod menu. I noticed this occurred before when we made some !chat based commands for it.
Like, am I doing it wrong? I'd appreciate some assistance[/QUOTE]
Check console output. Try to avoid using SendLua at all costs.
Yeah, I've heard it's bad to use that, but if I recall, I've tried doing just RunConsoleCommand but connect is blocked or something
[QUOTE=NiandraLades;46089192]Super quick thing; I'm making a server menu thing and this is the code I'm using to connect the player:
[code]ply:SendLua([[RunConsoleCommand("connect", "IP AND PORT HERE")]])[/code]
It sort of works, like there doesn't seem to be any errors. Basically, it'll start loading you and then drop you to the main gmod menu. I noticed this occurred before when we made some !chat based commands for it.
Like, am I doing it wrong? I'd appreciate some assistance[/QUOTE]
It appears that it is a bit buggy since that doesn't work for me either.
Try using ply:ConCommand(command) instead.
[QUOTE=syl0r;46088321]ply:getDarkRPVar("rpname")[/QUOTE]
[QUOTE=zeaga;46087964]Not that I'm using DarkRP :v:[/QUOTE]
Thanks, but that doesn't help me. It's for a standalone addon which isn't specific to any one gamemode.
[QUOTE=zeaga;46090218]Thanks, but that doesn't help me. It's for a standalone addon which isn't specific to any one gamemode.[/QUOTE]
Like in [url]https://github.com/FPtje/DarkRP/blob/2a1d53d6370c8942c303c5ad64c6f70abbefb737/gamemode/modules/base/cl_entityvars.lua#L97[/url].
override the :Name() and such functions
[QUOTE=zeaga;46090218]Thanks, but that doesn't help me. It's for a standalone addon which isn't specific to any one gamemode.[/QUOTE]
You'd have to override the Nick() Name() methods to return what you want instead, I guess.
[QUOTE=Giraffen93;46090265]override the :Name() and such functions[/QUOTE]
[QUOTE=Internet1001;46090311]You'd have to override the Nick() Name() methods to return what you want instead, I guess.[/QUOTE]
I didn't even think about trying that. Thanks!
When networking with lua, does the networking need to be inside the hook you're calling the send function from, or can it be outside of it?
[QUOTE=serfma;46090711]When networking with lua, does the networking need to be inside the hook you're calling the send function from, or can it be outside of it?[/QUOTE]
The function attached to the net.Receive as your callback will be called regardless of where it is, as long as your code is run, the callback will be called when the client (or server) receives the message.
[QUOTE=Internet1001;46090808]The function attached to the net.Receive as your callback will be called regardless of where it is, as long as your code is run, the callback will be called when the client (or server) receives the message.[/QUOTE]
[CODE]hook.Add("DoPlayerDeath", "KilledByMsg", function(ply, killer, dmginfo)
local wep = killer:GetActiveWeapon()
if not IsValid(wep) then return end
wep = wep:GetClass()
role = killer:GetRole()
if ( SERVER ) then
util.AddNetworkString( "DeathMsg" )
function DeathMsgPly()
net.Start( "DeathMsg" )
net.WriteEntity( killer )
net.WriteString( wep )
net.WriteString( role )
net.Send( ply )
end
end
if ( CLIENT ) then
net.Receive( "DeathMsg", function()
local killer = net.ReadEntity()
local wep = net.ReadString()
local role = net.ReadString()
local nick = killer:Nick()
local orange = "Color(243, 156, 18)"
local blue = "Color(52, 152, 219)"
local green = "Color(46, 204, 113)"
local red = "Color(231, 76, 60)"
local rColor = role == ROLE_TRAITOR && red or role == ROLE_DETECTIVE && blue or role == ROLE_INNOCENT && green
chat.AddText( orange, "You've been killed by ", rColor, nick, orange, " with a: ", rColor, wep, orange, "." )
end)
end
if GetRoundState() == ROUND_ACTIVE and dmginfo:IsDamageType(DMG_BULLET) then
DeathMsgPly()
end
end )[/CODE]
Then what in the world am I doing wrong here? It's supposed to print the message when a player dies. It would work, I'd restart the map, and it would stop working. I can't figure out what's wrong.
The problem is that you've got the net.Receive in a hook which is not run client side, like I said, as long as the net.Receive is run, it'll work. Take the net.Receive out of the hook so that it runs when the file is loaded and it should work.
[QUOTE=serfma;46090882][CODE]hook.Add("DoPlayerDeath", "KilledByMsg", function(ply, killer, dmginfo)
local wep = killer:GetActiveWeapon()
if not IsValid(wep) then return end
wep = wep:GetClass()
role = killer:GetRole()
if ( SERVER ) then
util.AddNetworkString( "DeathMsg" )
function DeathMsgPly()
net.Start( "DeathMsg" )
net.WriteEntity( killer )
net.WriteString( wep )
net.WriteString( role )
net.Send( ply )
end
end
if ( CLIENT ) then
net.Receive( "DeathMsg", function()
local killer = net.ReadEntity()
local wep = net.ReadString()
local role = net.ReadString()
local nick = killer:Nick()
local orange = "Color(243, 156, 18)"
local blue = "Color(52, 152, 219)"
local green = "Color(46, 204, 113)"
local red = "Color(231, 76, 60)"
local rColor = role == ROLE_TRAITOR && red or role == ROLE_DETECTIVE && blue or role == ROLE_INNOCENT && green
chat.AddText( orange, "You've been killed by ", rColor, nick, orange, " with a: ", rColor, wep, orange, "." )
end)
end
if GetRoundState() == ROUND_ACTIVE and dmginfo:IsDamageType(DMG_BULLET) then
DeathMsgPly()
end
end )[/CODE]
Then what in the world am I doing wrong here? It's supposed to print the message when a player dies. It would work, I'd restart the map, and it would stop working. I can't figure out what's wrong.[/QUOTE]
Move the net.Receive and the util.AddNetworkedString out of the hook
Sorry, you need to Log In to post a reply to this thread.