Hi! what I pretend is to switch how I handle my SWEPs, between right and left handed way. I know there's a LUA code known as 'SWEP.ViewModelFlip = true/ false', but what I really need is to bind a key to some console command (that I'd really appreciate if you could tell me) which would do it during gameplay, so I can lean around corners in a more realistic way; I'm not sure if you know what I am talking about.
I'm sorry for being a realism freak by the way :P
Whenever you need to do it, just do Weapon.ViewModelFlip = true/false, save the value before changing it, and restore it after you don't need anything changed.
[editline]3rd February 2014[/editline]
Make sure to sync the variable to the client.
That command didn't work, and what do you mean with 'sync the variable to the client'?
I mean do it on client, because it won't make any difference if you change it on server.
[editline]3rd February 2014[/editline]
Also, it might be sensible to do
local oldval = Weapon.ViewModelFlip
Weapon.ViewModelFlip = !oldval
In case the SWEP has it set to true. It won't work for default HL2 weapons.
I tried these commands on console but they didn't work neither.
And what I gotta do on client? I still don't understand :S
Did you put what Robotboy posted in your code?
[QUOTE=DaOneWhoPwns;43772226]I tried these commands on console but they didn't work neither.
And what I gotta do on client? I still don't understand :S[/QUOTE]
Post exactly what you tried.
Yeah I tried various things like putting what he posted on my SWEP base and also on a new LUA file located on my 'client' folder (as he might meant), and also copied the same with 'weapon' being replaced by 'SWEP' just in case that wasn't a valid code; so this is what there is on my LUAs:
local oldval = Weapon.ViewModelFlip
Weapon.ViewModelFlip = !oldval
Weapon.ViewModelFlip = true/false
local oldval = SWEP.ViewModelFlip
SWEP.ViewModelFlip = !oldval
SWEP.ViewModelFlip = true/false
I did type each one of these lines on console too (alternating between 'false' and 'true') but I can't make it work -.-
If you read the code, then you'd know that !oldval was the command. Also, you can't just make a new file. Post your full weapon code.
Do you have any idea of what you are doing?
Be honest.
Because this is working on this is working on Tool Gun for example.
[code]
sv_allowcslua 1
lua_run_cl local wep = LocalPlayer():GetActiveWeapon() wep.ViewModelFlip = true[/code]
Alright, so I typed that supposed command '!oldval' but didn't work neither. Whatever, here I leave my code:
[url]https://www.mediafire.com/?aqo8fzpkfp32p3k[/url]
Use pastebin for code.
[editline]3rd February 2014[/editline]
Oh my god, are you serious?
/*---------------------------------------------------------
------mmmm---mmmm-aaaaaaaa----ddddddddd---------------------------------------->
mmmmmmmmmmmm aaaaaaaaa dddddddddd Name: Mad Cows Weapons
mmm mmmm mmm aaa aaa ddd ddd Author: Worshipper
mmm mmm mmm aaaaaaaaaaa ddd ddd Project Start: October 23th, 2009
mmm mmm aaa aaa dddddddddd Version: 2.0
---mmm--------mmm-aaa-----aaa-ddddddddd---------------------------------------->
---------------------------------------------------------*/
// Variables that are used on both client and server
local RecoilMul = CreateConVar ("mad_recoilmul", "1", {FCVAR_REPLICATED, FCVAR_ARCHIVE})
local DamageMul = CreateConVar ("mad_damagemul", "1", {FCVAR_REPLICATED, FCVAR_ARCHIVE})
sv_allowcslua 1
lua_run_cl local wep = LocalPlayer():GetActiveWeapon() wep.ViewModelFlip = true
SWEP.Category = "Mad Cows Weapons"
SWEP.Author = "Worshipper"
SWEP.Contact = "Josephcadieux@hotmail.com"
// I have nothing to say here because I'm a prick
SWEP.Purpose = ""
SWEP.Instructions = ""
local oldval = Weapon.ViewModelFlip
Weapon.ViewModelFlip = !oldval
Weapon.ViewModelFlip = true/false
local oldval = SWEP.ViewModelFlip
SWEP.ViewModelFlip = !oldval
SWEP.ViewModelFlip = true/false
SWEP.ViewModelFOV = 60
SWEP.ViewModelFlip = false
SWEP.ViewModel = "models/weapons/v_pistol.mdl"
SWEP.WorldModel = "models/weapons/w_pistol.mdl"
SWEP.AnimPrefix = "python"
SWEP.Spawnable = false
SWEP.AdminSpawnable = false
SWEP.Primary.Sound = Sound("Weapon_AK47.Single")
SWEP.Primary.Recoil = 10
SWEP.Primary.Damage = 10
SWEP.Primary.NumShots = 1
SWEP.Primary.Cone = 0
SWEP.Primary.Delay = 0
SWEP.AutoReload = false
SWEP.Primary.ClipSize = 5 // Size of a clip
SWEP.Primary.DefaultClip = 5 // Default number of bullets in a clip
SWEP.Primary.Automatic = false // Automatic/Semi Auto
SWEP.Primary.Ammo = "none"
SWEP.Secondary.ClipSize = -1 // Size of a clip
SWEP.Secondary.DefaultClip = -1 // Default number of bullets in a clip
SWEP.Secondary.Automatic = false // Automatic/Semi Auto
SWEP.Secondary.Ammo = "none"
SWEP.ActionDelay = CurTime()
// I added this function because some weapons like the Day of Defeat weapons need 1.2 or 1.5 seconds to deploy
SWEP.DeployDelay = 1
SWEP.ShellEffect = "effect_mad_shell_pistol" // "effect_mad_shell_pistol" or "effect_mad_shell_rifle" or "effect_mad_shell_shotgun"
SWEP.ShellDelay = 0
// Is it a pistol, a rifle, a shotgun or a sniper? Choose only one of them or you'll fucked up everything. BITCH!
SWEP.Pistol = false
SWEP.Rifle = false
SWEP.Shotgun = false
SWEP.Sniper = false
SWEP.NearWall = true
SWEP.DryFireAnim = true
SWEP.IronSightsPos = Vector (0, 0, 0)
SWEP.IronSightsAng = Vector (0, 0, 0)
SWEP.RunArmOffset = Vector (0, 0, 5.5)
SWEP.RunArmAngle = Vector (-35, -3, 0)
SWEP.PistolNearWallPos = Vector (1.2394, -6.0719, -4.2309)
SWEP.PistolNearWallAng = Vector (32.7873, 47.4812, -5.8107)
SWEP.NearWallPos = Vector (-5.8808, -6.1505, -8.9126)
SWEP.NearWallAng = Vector (41.5783, -0.0228, 0)
// Burst options
SWEP.Burst = false
SWEP.BurstShots = 3
SWEP.BurstDelay = 0.05
SWEP.BurstCounter = 0
SWEP.BurstTimer = 0
// Custom mode options (Do not put a burst mode and a custom mode at the same time, it will not work)
SWEP.Type = 1 // 1 = Automatic/Semi-Automatic mode, 2 = Suppressor mode, 3 = Burst fire mode
SWEP.Mode = false
SWEP.data = {}
SWEP.data.NormalMsg = "Switched to semi-automatic."
SWEP.data.ModeMsg = "Switched to automatic."
SWEP.data.Delay = 0.5 // You need to wait 0.5 second after you change the fire mode
SWEP.data.Cone = 1
SWEP.data.Damage = 1
SWEP.data.Recoil = 1
SWEP.data.Automatic = false
// Constant accuracy means that your crosshair will not change if you're running, shooting or walking
SWEP.ConstantAccuracy = false
// I don't think it's hard to understand this
SWEP.Penetration = true
SWEP.Ricochet = true
SWEP.MaxRicochet = 1
SWEP.Tracer = 0 // 0 = Normal Tracer, 1 = Ar2 Tracer, 2 = Airboat Gun Tracer, 3 = Normal Tracer + Sparks Impact
SWEP.IdleDelay = 0
SWEP.IdleApply = false
SWEP.AllowIdleAnimation = true
SWEP.AllowPlaybackRate = true
SWEP.BoltActionSniper = false // Use this value if you want to remove the scope view after you shoot
SWEP.ScopeAfterShoot = false // Do not try to change this value
SWEP.IronSightZoom = 1.5
SWEP.ScopeZooms = {10}
SWEP.ScopeScale = 0.4
SWEP.ShotgunReloading = false
SWEP.ShotgunFinish = 0.5
SWEP.ShotgunBeginReload = 0.3
/*---------------------------------------------------------
Name: SWEP:Initialize()
Desc: Called when the weapon is first loaded.
---------------------------------------------------------*/
function SWEP:Initialize()
if (SERVER) then
self:SetWeaponHoldType(self.HoldType)
// Fucking NPCs
self:SetNPCMinBurst(30)
self:SetNPCMaxBurst(30)
self:SetNPCFireRate(self.Primary.Delay)
end
end
/*---------------------------------------------------------
Name: SWEP:Precache()
Desc: Use this function to precache stuff.
---------------------------------------------------------*/
function SWEP:Precache()
util.PrecacheSound("weapons/ClipEmpty_Pistol.wav")
end
/*---------------------------------------------------------
Name: ENT:SetupDataTables()
Desc: Setup the data tables.
---------------------------------------------------------*/
function ENT:SetupDataTables()
self:DTVar("Bool", 0, "Holsted")
self:DTVar("Bool", 1, "Ironsights")
self:DTVar("Bool", 2, "Scope")
self:DTVar("Bool", 3, "Mode")
end
/*---------------------------------------------------------
Name: SWEP:IdleAnimation()
Desc: Are you seriously too stupid to understand the function by yourself?
---------------------------------------------------------*/
function SWEP:IdleAnimation(time)
if not self.AllowIdleAnimation then return false end
self.IdleApply = true
self.ActionDelay = CurTime() + time
self.IdleDelay = CurTime() + time
end
/*---------------------------------------------------------
Name: SWEP:PrimaryAttack()
Desc: +attack1 has been pressed.
---------------------------------------------------------*/
function SWEP:PrimaryAttack()
// Holst/Deploy your fucking weapon
if (not self.Owner:IsNPC() and self.Owner:KeyDown(IN_USE)) then
bHolsted = !self.Weapon:GetDTBool(0)
self:SetHolsted(bHolsted)
self.Weapon:SetNextPrimaryFire(CurTime() + 0.3)
self.Weapon:SetNextSecondaryFire(CurTime() + 0.3)
self:SetIronsights(false)
return
end
if (not self:CanPrimaryAttack()) then return end
self.ActionDelay = (CurTime() + self.Primary.Delay + 0.05)
self.Weapon:SetNextPrimaryFire(CurTime() + self.Primary.Delay)
self.Weapon:SetNextSecondaryFire(CurTime() + self.Primary.Delay)
// If the burst mode is activated, it's going to shoot the three bullets (or more if you're dumb and put 4 or 5 bullets for your burst mode)
if self.Weapon:GetDTBool(3) and self.Type == 3 then
self.BurstTimer = CurTime()
self.BurstCounter = self.BurstShots - 1
self.Weapon:SetNextPrimaryFire(CurTime() + 0.5)
end
self.Weapon:EmitSound(self.Primary.Sound)
self:TakePrimaryAmmo(1)
self:ShootBulletInformation()
end
/*---------------------------------------------------------
Name: SWEP:SecondaryAttack()
Desc: +attack2 has been pressed.
---------------------------------------------------------*/
function SWEP:SecondaryAttack()
if self.Owner:IsNPC() then return end
if not IsFirstTimePredicted() then return end
if (self.Owner:KeyDown(IN_USE) and (self.Mode)) then // Mode
bMode = !self.Weapon:GetDTBool(3)
self:SetMode(bMode)
self:SetIronsights(false)
self.Weapon:SetNextPrimaryFire(CurTime() + self.data.Delay)
self.Weapon:SetNextSecondaryFire(CurTime() + self.data.Delay)
return
end
if (!self.IronSightsPos) or (self.Owner:KeyDown(IN_SPEED) or self.Weapon:GetDTBool(0)) th
:suicide:
Use [code] tags
Learn how to program Lua before trying to do ambitious things.
But that's not useful still :S
[editline]3rd February 2014[/editline]
Oh woah hang there for a second, just tried with
'sv_allowcslua 1'
'lua_run_cl local wep = LocalPlayer():GetActiveWeapon() wep.ViewModelFlip = true'
and my model flips in-game! that's what I just wanted, now I only got to bind the keys. Thanks for your help, let this thread die :D
Sorry, you need to Log In to post a reply to this thread.