Is there any possible way to do something like... on a non-automatic swep, if i hold the attack1 button for like 3 seconds, and then RELEASE, the attack will be different, and then, right after that, it becomes back to normal until i hold it again.
I thought about creating a timer to check about this, and if the statment was true, it changes the SWEP properties of the Primary Attack, then after release, it comes back to normal. but i kind of wasn't able to make it work.
The idea is make a "charging" attack. Any hints? Thanks.
Come on guys, i can't believe no one have at least a hint.
Okay, i'll show you all what i've tried so far:
[lua]
function SWEP:Think()
if self.Owner:KeyDown(IN_ATTACK) then
timer.Create("charge_timer", 3, 1, charged_shot)
end
if self.Owner:KeyReleased(IN_ATTACK) then
timer.Destroy("charge_timer")
end
SWEP.Primary.Damage = 10
end
function charged_shot()
SWEP.Primary.Damage = 40
end
[/lua]
I'll explain again, what i want is:
- If the player hold the attack button for 3 seconds, it changes the damage of the weapon. (as well as other properties that i might put there)
- When he releases, the attack is powerful, but i haven't found a way to make it shoot. Then, the damage goes back to normal, until he charges again.
Does anyone have any hint? Please, i'm begging you. I'm not totally dumb, i'll understand most of the hints you people send me.
Do you have ammo for it? If so, make it use up ammo on the way of charging like..3 a second out of a clip of 15 so it will make 5 seconds to charge, but you can do something like
[lua]
if ammo<7 and if self.Owner:KeyDown(IN_ATTACK) then
timer.Create("timer1", 10, 1, charged_shot())
function charged_shot()
SWEP.Primary.Damage = 40
end
[/lua]
Probably not the best or anywhere near correct but I hope you understand what I'm trying to suggest :v:
[QUOTE=Chad Mobile;19587780]Do you have ammo for it? If so, make it use up ammo on the way of charging like..3 a second out of a clip of 15 so it will make 5 seconds to charge, but you can do something like
[lua]
if ammo<7 and if self.Owner:KeyDown(IN_ATTACK) then
timer.Create("timer1", 10, 1, charged_shot())
function charged_shot()
SWEP.Primary.Damage = 40
end
[/lua]
Probably not the best or anywhere near correct but I hope you understand what I'm trying to suggest :v:[/QUOTE]
First of all, really thanks for replying.
Hmm... I kind of understand your point, but no, the swep ammo is -1, it's not supposed to use any ammo, it's a kind of beam blaster weapon. Sorry, i forgot to mention that. XD
To simplify matters, see that part where i use the KeyReleased? I want to make it shoot right there, at the beginning, or else, it'll just change the damage back to 10 and nothing will happen. That would be at least a start.
Hey guys, i've been working a little bit more on this issue. Here what i've made so far:
[lua]
// Charged Shot
function charged_shot()
self.Primary.Sound = "weapons/weapon_test_cannon/mega_shot.mp3"
self.Primary.Damage = 50
self.Primary.Recoil = 5
charged = true
end
// SWEP A.I.
function SWEP:Think()
if self.Owner:KeyDown(IN_ATTACK) then
timer.Create("charge_timer", 3, 1, charged_shot)
end
if self.Owner:KeyReleased(IN_ATTACK) then
if ( charged ) then
self:PrimaryAttack()
timer.Destroy("charge_timer")
charged = false
end
end
// Reseting the original values
self.Primary.Sound = "weapons/weapon_test_cannon/normal_shot.mp3"
self.Primary.Damage = 5
self.Primary.Recoil = 0
end
//SWEP:Initialize()
function SWEP:Initialize()
util.PrecacheSound(self.Primary.Sound)
util.PrecacheSound(self.Secondary.Sound)
if ( SERVER ) then
self:SetWeaponHoldType( self.HoldType )
end
end
//SWEP:PrimaryFire()
function SWEP:PrimaryAttack()
if ( !self:CanPrimaryAttack() ) then return end
local bullet = {}
bullet.Num = self.Primary.NumberofShots
bullet.Src = self.Owner:GetShootPos()
bullet.Dir = self.Owner:GetAimVector()
bullet.Spread = Vector( self.Primary.Spread * 0.1 , self.Primary.Spread * 0.1, 0)
bullet.Tracer = 1
bullet.Force = self.Primary.Force
bullet.Damage = self.Primary.Damage
bullet.AmmoType = self.Primary.Ammo
local rnda = self.Primary.Recoil * -1
local rndb = self.Primary.Recoil * math.random(-1, 1)
self:ShootEffects()
self.Owner:FireBullets( bullet )
self.Weapon:EmitSound(Sound(self.Primary.Sound), 100, 100)
self.Owner:ViewPunch( Angle( rnda,rndb,rnda ) )
self:TakePrimaryAmmo(self.Primary.TakeAmmo)
self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
end
[/lua]
Still don't seem to work. What the hell am i doing wrong there? Please people, i know that most of you have solid knowledge about such a issue like this... I'm begging your help. This SWEP can be just a start of an excellent gamemode.
Set the PrimaryAttack to Automatic and then next. Primary fire to CurTime()+0.1 and add some value each time it its called.
[QUOTE=SilverBladeTH;19525879]Come on guys, i can't believe no one have at least a hint.[/QUOTE]
Your avatar scared the shit out of me, i did not dare to answer.
[editline]24:44pm[/editline]
I'll whip something up when i get home.
[QUOTE=commander204;19606195]Set the PrimaryAttack to Automatic and then next. Primary fire to CurTime()+0.1 and add some value each time it its called.[/QUOTE]
I thought about do something like that but... the problem is... the primary attack will also be a non-automatic one. It will only charge if the player HOLD the button down for 3 seconds.
[QUOTE=aualin;19606533]Your avatar scared the shit out of me, i did not dare to answer.
I'll whip something up when i get home.[/QUOTE]
You mean the old one with big eyes, right? Yeah, i agree. Well, i've seen scarier avatars around here so i thought people wouldn't mind. XD Maybe i should change my avvie to one of those pink and black textures error so people would at least have a giggle.
Anyway, thanks man, anything you can tell me will be helpful.
By the way, if anyone is interested to check the others variables, here they are:
[lua]
//Spawn Variables
SWEP.AdminSpawnable = false
SWEP.Spawnable = true
//Boolean Variables
SWEP.DrawCrosshair = true
SWEP.AutoSwitchFrom = false
SWEP.AutoSwitchTo = true
SWEP.FiresUnderwater = true
SWEP.DrawAmmo = false
//Other Info Variables
SWEP.ViewModelFOV = 64
SWEP.Slot = 0
SWEP.Weight = 20
SWEP.SlotPos = 0
SWEP.HoldType = "pistol"
// Custom Models made by a friend of mine.
SWEP.ViewModel = "models/weapons/v_cannonrifle.mdl"
SWEP.WorldModel = "models/weapons/v_cannonrifle.mdl"
// Default to everything else.
SWEP.base = "weapon_base"
//Primary Fire Variables
SWEP.Primary.Sound = "weapons/weapon_test_cannon/normal_shot.mp3"
SWEP.Primary.Damage = 5
SWEP.Primary.TakeAmmo = 0
SWEP.Primary.ClipSize = 1
SWEP.Primary.Ammo = "AR2"
SWEP.Primary.DefaultClip = 1
SWEP.Primary.Spread = 0.0
SWEP.Primary.NumberofShots = 1
SWEP.Primary.Automatic = false
SWEP.Primary.Recoil = 0
SWEP.Primary.Delay = 0.0
SWEP.Primary.Force = 5
[/lua]
What you would like to do is something like this.
[lua]
local HoldingSince = CurTime()
function SWEP:Think()
if self.Owner:KeyDown(IN_ATTACK) then
self.Owner:PrintMessage(HUD_PRINTTALK, "Holdin down")
if(CurTime() > HoldingSince) then
-- Damage stuff here
end
else
HoldingSince = CurTime() + 3
end
end
[/lua]
It'd be better to use SWEP.HoldingSince then reference it with self.HoldingSince, because that would keep it in the realm of the SWEP and wouldn't cause any conflicts with other players.
[QUOTE=aualin;19626584]What you would like to do is something like this.
[lua]
local HoldingSince = CurTime()
function SWEP:Think()
if self.Owner:KeyDown(IN_ATTACK) then
self.Owner:PrintMessage(HUD_PRINTTALK, "Holdin down")
if(CurTime() > lastTime) then
-- Damage stuff here
end
else
HoldingSince = CurTime() + 3
end
end
[/lua][/QUOTE]
Wow, that's really interesting man, thanks for providing me a hand. But huh... just a question, where that "lastTime" var came from?
[QUOTE=JIAC;19626974]It'd be better to use SWEP.HoldingSince then reference it with self.HoldingSince, because that would keep it in the realm of the SWEP and wouldn't cause any conflicts with other players.[/QUOTE]
Well remembered man. Thanks, i'll fix it.
[lua]
// Reseting the original values
self.Primary.Sound = "weapons/weapon_test_cannon/normal_shot.mp3 --I dont think you can play .mp3"
self.Primary.Damage = 5
self.Primary.Recoil = 0
end
[/lua]
Not sure if you can play .mp3s, as I can't. Use Audacity to convert it to .wav just in case.
[QUOTE=Chad Mobile;19651043][lua]
// Reseting the original values
self.Primary.Sound = "weapons/weapon_test_cannon/normal_shot.mp3 --I dont think you can play .mp3"
self.Primary.Damage = 5
self.Primary.Recoil = 0
end
[/lua]
Not sure if you can play .mp3s, as I can't. Use Audacity to convert it to .wav just in case.[/QUOTE]
Well, actually, i can. It works fine for me, as well for every beta tester.
Now you mention it, i remember of myself having a little of trouble with that. i solved it by editing it on audacity itself, exporting to mp3, but i put the sound at 22050 Hz. The engine had trouble to play it at 44100 Hz. Just change the Hz at the left-bottom corner before exporting. I also remember to use a plugin that allows me to export mp3 using audacity (Don't worry, audacity itself will tell you where to get it once you try to export to mp3)
[QUOTE=aualin;19626584]What you would like to do is something like this.
[lua]
local HoldingSince = CurTime()
function SWEP:Think()
if self.Owner:KeyDown(IN_ATTACK) then
self.Owner:PrintMessage(HUD_PRINTTALK, "Holdin down")
if(CurTime() > lastTime) then
-- Damage stuff here
end
else
HoldingSince = CurTime() + 3
end
end
[/lua][/QUOTE]
Well, i tested it, and it didn't work well... I even tried to put the real "last time" inside the var "lastTime", and put the increased damage stats over there. But it loops like 5 times. Not only mentioning it starts RIGHT as i press the Attack button. As i said, there's also a normal shoot as primary attack. When someone holds the key down for over 3 seconds, then yeah, it should change the stats, shoot, and then come back to normal.
[QUOTE=SilverBladeTH;19660997]Well, i tested it, and it didn't work well... I even tried to put the real "last time" inside the var "lastTime", and put the increased damage stats over there. But it loops like 5 times. Not only mentioning it starts RIGHT as i press the Attack button. As i said, there's also a normal shoot as primary attack. When someone holds the key down for over 3 seconds, then yeah, it should change the stats, shoot, and then come back to normal.[/QUOTE]
I made a typo, lastTime is supposed to be HoldingSince
Horray!! I've also added some changes and now it's working pretty accurate as i wanted to! Really thanks for everyone who helped me, i'll add all your names on the Thanks section once i release the whole project. Here's the code i'm using right now, if anyone has any improvment suggestions, feel free to tell me.
[lua]
// Reference variables
SWEP.HoldingSince = CurTime()
SWEP.charged = false
// SWEP A.I.
function SWEP:Think()
if self.Owner:KeyDown(IN_ATTACK) then
if(CurTime() > self.HoldingSince) then
self.Primary.Sound = "weapons/weapon_test_cannon/mega_shot.mp3"
self.Primary.Damage = 50
self.Primary.Recoil = 5
self.charged = true
end
else
self.HoldingSince = CurTime() + 3
end
// If he releases the button, and the attack is charged, blast, and change back to normal
if self.Owner:KeyReleased(IN_ATTACK) and self.charged == true then
self:PrimaryAttack()
self.Primary.Sound = "weapons/weapon_test_cannon/normal_shot.mp3"
self.Primary.Damage = 5
self.Primary.Recoil = 0
self.charged = false
end
end
[/lua]
Now i'm gonna add some charging sounds just to make it cooler and tell the player when the cannon is ready or not. Once again, really thanks you all. I knew that there were still a lot of good people around here. [b]You guys rock big time.[/b]
No problem mate :v:
Sorry, you need to Log In to post a reply to this thread.