I am currently making a gamemode and you spawn with a throwing knife weapon. In singleplayer, the animations for the knife are at normal speed, but in multiplayer, it is about 5x as fast. Can anyone help? Thanks!
There's nothing anybody can do if they can't use their magical abilities to see the script.
Here is the script:
[CODE]
if( SERVER ) then
AddCSLuaFile( "shared.lua" );
end
if( CLIENT ) then
SWEP.PrintName = "Knife";
SWEP.Slot = 1;
SWEP.SlotPos = 1;
SWEP.DrawAmmo = false;
SWEP.DrawCrosshair = true;
end
SWEP.Author = "XKalamitous"
SWEP.Instructions = "Left click to stab, right click to throw!"
SWEP.Contact = ""
SWEP.Purpose = ""
SWEP.ViewModelFOV = 64
SWEP.ViewModelFlip = false
SWEP.Spawnable = false
SWEP.AdminSpawnable = true
SWEP.NextStrike = 0;
SWEP.ViewModel = "models/weapons/v_knife_t.mdl"
SWEP.WorldModel = "models/weapons/w_knife_t.mdl"
SWEP.Primary.Delay = 0
SWEP.Primary.Recoil = 0
SWEP.Primary.Damage = 100
SWEP.Primary.NumShots = 1
SWEP.Primary.Cone = 0
SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = -1
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = "none"
SWEP.Secondary.Delay = 0
SWEP.Secondary.Recoil = 0
SWEP.Secondary.Damage = 50
SWEP.Secondary.NumShots = 1
SWEP.Secondary.Cone = 0
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = "none"
util.PrecacheSound("weapons/knife/knife_deploy1.wav")
util.PrecacheSound("weapons/knife/knife_hitwall1.wav")
util.PrecacheSound("weapons/knife/knife_hit1.wav")
util.PrecacheSound("weapons/knife/knife_hit2.wav")
util.PrecacheSound("weapons/knife/knife_hit3.wav")
util.PrecacheSound("weapons/knife/knife_hit4.wav")
util.PrecacheSound("weapons/iceaxe/iceaxe_swing1.wav")
function SWEP:Initialize()
if( SERVER ) then
self:SetWeaponHoldType( "melee" );
end
self.Hit = {
Sound( "weapons/knife/knife_hitwall1.wav" )};
self.FleshHit = {
Sound( "weapons/knife/knife_hit1.wav" ),
Sound( "weapons/knife/knife_hit2.wav" ),
Sound( "weapons/knife/knife_hit3.wav" ),
Sound( "weapons/knife/knife_hit4.wav" ) };
end
function SWEP:Precache()
end
function SWEP:Deploy()
self.Weapon:SendWeaponAnim(ACT_VM_DRAW)
self.Weapon:SetNextPrimaryFire(CurTime() + 1)
self.Owner:EmitSound( "weapons/knife/knife_deploy1.wav" );
return true;
end
function SWEP:PrimaryAttack()
if( CurTime() < self.NextStrike ) then return; end
self.NextStrike = ( CurTime() + .5 );
local trace = self.Owner:GetEyeTrace();
if trace.HitPos:Distance(self.Owner:GetShootPos()) <= 75 then
if( trace.Entity:IsPlayer() or trace.Entity:IsNPC() or trace.Entity:GetClass()=="prop_ragdoll" ) then
self.Owner:EmitSound( self.FleshHit[math.random(1,#self.FleshHit)] );
else
self.Owner:EmitSound( self.Hit[math.random(1,#self.Hit)] );
end
self.Owner:SetAnimation( PLAYER_ATTACK1 );
self.Weapon:SendWeaponAnim( ACT_VM_HITCENTER )
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 = 1
bullet.Damage = 50
self.Owner:FireBullets(bullet)
else
self.Owner:SetAnimation( PLAYER_ATTACK1 );
self.Weapon:SendWeaponAnim( ACT_VM_HITCENTER );
self.Weapon:EmitSound("weapons/iceaxe/iceaxe_swing1.wav")
end
end
function SWEP:SecondaryAttack()
if( CurTime() < self.NextStrike ) then return; end
self.NextStrike = ( CurTime() + 1 );
self.Owner:SetAnimation( PLAYER_ATTACK1 );
self.Weapon:SendWeaponAnim( ACT_VM_DRAW );
self.Weapon:EmitSound("weapons/iceaxe/iceaxe_swing1.wav")
self.Owner:EmitSound( "weapons/knife/knife_deploy1.wav" )
local tr = self.Owner:GetEyeTrace();
if (!SERVER) then return end;
local ent = ents.Create ("knife_proj");
ent:SetPos (self.Owner:EyePos() + (self.Owner:GetAimVector() * 16));
ent:SetAngles (self.Owner:EyeAngles());
ent:Spawn();
ent.Thrower = self.Owner;
local phys = ent:GetPhysicsObject();
local shot_length = tr.HitPos:Length();
phys:ApplyForceCenter (self.Owner:GetAimVector():GetNormalized() * math.pow (shot_length, 3));
cleanup.Add (self.Owner, "props", ent);
undo.Create ("Knife");
undo.AddEntity (ent);
undo.SetPlayer (self.Owner);
undo.Finish();
end
[/CODE]
Try SetVelocity instead of applyforce?
[editline]15th March 2014[/editline]
Shit, misread the issue
[editline]15th March 2014[/editline]
Here, try this
[code]self:SetPlaybackRate(1)[/code]
Put it directly after whenever you do SendWeaponAnim and see if it helps
It still doesn't work, but I appreciate you help.
Can anyone please help?:smile:
[url]http://facepunch.com/showthread.php?t=1072263[/url]
This guy has the same problem, but I don't know what they meant by playing the animations serverside.
Wait, how are you testing in Multiplayer?
By a scrds server.
Bump
Use IsFirstTimePredicted( ).. You're not using that, meaning it'll be called repeatedly giving you, the LocalPlayer( ) the illusion that the animation is nuts. The other players around you should see it normally.
That also explains why in single-player ( when the client acts as the server ) you see it normally. The way SWEPs work in multiplayer is the CLIENT SPAMS Primary / SecondaryAttack( ) until it syncs with the server ( add a print statement to see what I mean ), while the SERVER calls it once. Use IsFirstTimePredicted( ) to have certain code only execute once on the CLIENT.
Thanks for the reply, but where do you put this?
[lua]if ( IsFirstTimePredicted( ) ) then
// ... Put anything in here that you only want ran once per click
end[/lua]
It is still not working. Here is what I did.
[CODE]
if( SERVER ) then
AddCSLuaFile( "shared.lua" );
end
if( CLIENT ) then
SWEP.PrintName = "Knife";
SWEP.Slot = 1;
SWEP.SlotPos = 1;
SWEP.DrawAmmo = false;
SWEP.DrawCrosshair = true;
end
SWEP.Author = "XKalamitous"
SWEP.Instructions = "Left click to stab, right click to throw!"
SWEP.Contact = ""
SWEP.Purpose = ""
SWEP.Base = "weapon_base"
SWEP.ViewModelFOV = 64
SWEP.ViewModelFlip = false
SWEP.Spawnable = false
SWEP.AdminSpawnable = true
SWEP.NextStrike = 0;
SWEP.ViewModel = "models/weapons/v_knife_t.mdl"
SWEP.WorldModel = "models/weapons/w_knife_t.mdl"
SWEP.Primary.Delay = 0
SWEP.Primary.Recoil = 0
SWEP.Primary.Damage = 100
SWEP.Primary.NumShots = 1
SWEP.Primary.Cone = 0
SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = -1
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = "none"
SWEP.Secondary.Delay = 0
SWEP.Secondary.Recoil = 0
SWEP.Secondary.Damage = 50
SWEP.Secondary.NumShots = 1
SWEP.Secondary.Cone = 0
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = "none"
util.PrecacheSound("weapons/knife/knife_deploy1.wav")
util.PrecacheSound("weapons/knife/knife_hitwall1.wav")
util.PrecacheSound("weapons/knife/knife_hit1.wav")
util.PrecacheSound("weapons/knife/knife_hit2.wav")
util.PrecacheSound("weapons/knife/knife_hit3.wav")
util.PrecacheSound("weapons/knife/knife_hit4.wav")
util.PrecacheSound("weapons/iceaxe/iceaxe_swing1.wav")
function SWEP:Initialize()
if( SERVER ) then
self:SetWeaponHoldType( "melee" );
end
self.Hit = {
Sound( "weapons/knife/knife_hitwall1.wav" )};
self.FleshHit = {
Sound( "weapons/knife/knife_hit1.wav" ),
Sound( "weapons/knife/knife_hit2.wav" ),
Sound( "weapons/knife/knife_hit3.wav" ),
Sound( "weapons/knife/knife_hit4.wav" ) };
end
function SWEP:Precache()
end
function SWEP:Deploy()
if ( IsFirstTimePredicted() ) then
self.Weapon:SendWeaponAnim(ACT_VM_DRAW)
self.Weapon:SetNextPrimaryFire(CurTime() + 1)
self.Owner:EmitSound( "weapons/knife/knife_deploy1.wav" );
return true;
end
end
function SWEP:PrimaryAttack()
if ( IsFirstTimePredicted() ) then
if( CurTime() < self.NextStrike ) then return; end
self.NextStrike = ( CurTime() + .5 );
local trace = self.Owner:GetEyeTrace();
if trace.HitPos:Distance(self.Owner:GetShootPos()) <= 75 then
if( trace.Entity:IsPlayer() or trace.Entity:IsNPC() or trace.Entity:GetClass()=="prop_ragdoll" ) then
self.Owner:EmitSound( self.FleshHit[math.random(1,#self.FleshHit)] );
else
self.Owner:EmitSound( self.Hit[math.random(1,#self.Hit)] );
end
self.Owner:SetAnimation( PLAYER_ATTACK1 );
self.Weapon:SendWeaponAnim( ACT_VM_HITCENTER );
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 = 1
bullet.Damage = 50
self.Owner:FireBullets(bullet)
else
self.Owner:SetAnimation( PLAYER_ATTACK1 );
self.Weapon:SendWeaponAnim( ACT_VM_HITCENTER );
self.Weapon:EmitSound("weapons/iceaxe/iceaxe_swing1.wav")
end
end
end
function SWEP:SecondaryAttack()
if ( IsFirstTimePredicted() ) then
if( CurTime() < self.NextStrike ) then return; end
self.NextStrike = ( CurTime() + 1 );
self.Owner:SetAnimation( PLAYER_ATTACK1 );
self.Weapon:SendWeaponAnim( ACT_VM_DRAW );
self.Weapon:EmitSound("weapons/iceaxe/iceaxe_swing1.wav")
self.Owner:EmitSound( "weapons/knife/knife_deploy1.wav" )
local tr = self.Owner:GetEyeTrace();
if (!SERVER) then return end;
local ent = ents.Create ("knife_proj");
ent:SetPos (self.Owner:EyePos() + (self.Owner:GetAimVector() * 16));
ent:SetAngles (self.Owner:EyeAngles());
ent:Spawn();
ent.Thrower = self.Owner;
local phys = ent:GetPhysicsObject();
local shot_length = tr.HitPos:Length();
phys:ApplyForceCenter (self.Owner:GetAimVector():GetNormalized() * math.pow (shot_length, 3));
cleanup.Add (self.Owner, "props", ent);
undo.Create ("Knife");
undo.AddEntity (ent);
undo.SetPlayer (self.Owner);
undo.Finish();
end
end
[/CODE]
Bump again. :v:
Help please!
Sorry, you need to Log In to post a reply to this thread.