Well hello there, I looked onto a bit of code to make an adrenaline swep, which you can only use once. Here's what I have up to now:
[Lua]function SWEP:PrimaryAttack()
if ( !self:CanPrimaryAttack() ) then return end
self.Weapon:SendWeaponAnim(ACT_SLAM_DETONATOR_DETONATE)
self.Weapon:Remove()
self.Weapon:EmitSound( self.Primary.Sound )
timer.Create( "Execute"..tostring(self.Weapon), 1, 1, function()
self:EmitSound( self.Primary.Sound )
end )
timer.Create( "Meanwhile"..tostring(self.Weapon), 45, 1, function()
self.Owner:SetJumpPower(240)
self.Owner:SetRunSpeed(450)
self.Owner:SetWalkSpeed(380)
end )
timer.Create( "Cooldown"..tostring(self.Weapon), 20, 1, function()
self.Owner:SetJumpPower(160)
self.Owner:SetRunSpeed(300)
self.Owner:SetWalkSpeed(200)
self:EmitSound( self.Primary.Sound )
end )
end[/lua]
But it doesn't seems to work, What I want it to do is :
To be effective for 45 seconds, and have a light cooldown of 20 seconds.
But it seem I failed on it, and now, I'm coming here to ask for some advice.
What does it do when you try to use it assuming it shows up, if not is there any errors?
Also, what is "self.Weapon:Remove() " on line 4 for...
It's here so it can remove the swep after you fire. I use that on most of my special weapons
Also it just doesn't do anything, just click and nothing happen.
[QUOTE=WolvesSoulZ;21356045]It's here so it can remove the swep after you fire. I use that on most of my special weapons
Also it just doesn't do anything, just click and nothing happen.[/QUOTE]
Wouldn't it remove the swep before it can do anything else (Sorry I don't really like Sweps or know much about them)
[QUOTE=DocDoomsday;21356074]Wouldn't it remove the swep before it can do anything else (Sorry I don't really like Sweps or know much about them)[/QUOTE]
Nah, it work like it should on my other special sweps, just that this one in particular just doesn't do anything.
Woah woah, i wouldnt dare use timer.simple in a swep.
Thats just errors waiting to happen, You should only use timer.Simple if its EXTREMELY neccesary.
i would use.
self.InjectSelf = CurTime() + 1
then in the think function
if self.InjectSelf and CurTime() >= self.InjectSelf then
self.InjectSelf = nil
Stuff here
end
Untested, but I think it should work.
[lua]
if SERVER then
local buffed_jumppower = 240
local buffed_runspeed = 750
local buffed_walkspeed = 375
local cooldown_jumppower = 120
local cooldown_runspeed = 375
local cooldown_walkspeed = 187
local default_jumppower = 160
local default_runspeed = 500
local default_walkspeed = 250
-- Start the adrenaline effect (increased speed and jump power)
local function AdrenalineStart(pl)
pl:SetJumpPower(buffed_jumppower)
pl:SetRunSpeed(buffed_runspeed)
pl:SetWalkSpeed(buffed_walkspeed)
pl.AdrenalineActive = true
pl.NextAdrenalineCooldown = CurTime() + 45
pl.NextAdrenalineStop = nil
end
-- Cooldown effect (decreased speed and jump power)
local function AdrenalineCooldown(pl)
pl:SetJumpPower(cooldown_jumppower)
pl:SetRunSpeed(cooldown_runspeed)
pl:SetWalkSpeed(cooldown_walkspeed)
pl.NextAdrenalineCooldown = nil
pl.NextAdrenalineStop = CurTime() + 20
end
-- Stop the adrenaline effect (reset speed and jump power)
local function AdrenalineStop(pl)
pl:SetJumpPower(default_jumppower)
pl:SetRunSpeed(default_runspeed)
pl:SetWalkSpeed(default_walkspeed)
pl.AdrenalineActive = false
pl.NextAdrenalineCooldown = nil
pl.NextAdrenalineStop = nil
end
-- Reset the adrenaline start timer
-- This makes sure the adrenaline effect will never start if the player switches weapons before the animation has finished playing
function SWEP:Deploy()
self.NextAdrenalineStart = nil
return true
end
end
function SWEP:PrimaryAttack()
if not self:CanPrimaryAttack() then return end
self:SendWeaponAnim(ACT_SLAM_DETONATOR_DETONATE)
self:EmitSound(self.Primary.Sound)
if CLIENT then return end
-- Start the adrenaline effect when the animation has finished playing
self.NextAdrenalineStart = CurTime() + self:SequenceDuration()
end
if SERVER then
function SWEP:Think()
if self.NextAdrenalineStart and CurTime()>self.NextAdrenalineStart then
AdrenalineStart(self.Owner)
-- switch to the last weapon
self.Owner:ConCommand("lastinv")
self.NextAdrenalineStart = nil
self:Remove()
end
end
-- Monitor the adrenaline effect every tick here
hook.Add("Tick", "AdrenalineThink", function()
for _,pl in ipairs(player.GetAll()) do
if pl.AdrenalineActive then
if pl.NextAdrenalineCooldown and CurTime()>pl.NextAdrenalineCooldown then
AdrenalineCooldown(pl)
end
if pl.NextAdrenalineStop and CurTime()>pl.NextAdrenalineStop then
AdrenalineStop(pl)
end
end
end
end)
-- If the player dies, stop the adrenaline effect
hook.Add("DoPlayerDeath", "AdrenalineDeath", function(pl)
AdrenalineStop(pl)
end)
end
[/lua]
It's a bit more complicated than I thought, but if it works, it should work perfectly. I'm using CurTime() instead of timers, because then, you are 100% sure nothing weird will happen if you keep giving adrenaline to yourself before the initial adrenaline effect is over.
I can't bother explaining everything right now, so if something looks weird to you, feel free to ask.
It look pretty good, tho I get this :
[QUOTE]
Hook 'AdrenalineDeath' Failed: weapons/killstreak_adrenaline/shared.lua:144: attempt to call field 'AdrenalineStop' (a nil value)
[/QUOTE]
Edit -> AdrenalineStop(pl)
[QUOTE]-- If the player dies, stop the adrenaline effect
hook.Add("DoPlayerDeath", "AdrenalineDeath", function(pl)
AdrenalineStop(pl)
end) [/QUOTE]
Edit : Also that :
[QUOTE]
weapons/killstreak_adrenaline/shared.lua:117: attempt to call global 'AdrenalineStart' (a nil value)
[/QUOTE]
-snip.
Mhmh basicaly, no mather what I try to fix, it just pop random errors.
Are those errors blue or yellow? Also, can you show me the entire code of your weapon?
[lua]if ( SERVER ) then
AddCSLuaFile( "shared.lua" )
SWEP.Weight = 5
SWEP.AutoSwitchTo = false
SWEP.AutoSwitchFrom = false
SWEP.HoldType = "grenade"
elseif ( CLIENT ) then
SWEP.PrintName = "Killstreak Adrenaline"
SWEP.Slot = 4
SWEP.SlotPos = 4
SWEP.DrawAmmo = false
SWEP.DrawCrosshair = true
end
SWEP.Author = "Wolvessoulz"
SWEP.Contact = "N/A"
SWEP.Purpose = "Boost your speed for a moment, but has a great cooldown"
SWEP.Instructions = "Click to use."
SWEP.Spawnable = false
SWEP.AdminSpawnable = true
SWEP.ViewModel = "models/weapons/v_slam.mdl"
SWEP.WorldModel = "models/weapons/w_slam.mdl"
SWEP.ViewModelFlip = true
SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = -1
SWEP.Primary.Sound = ("weapons/airsoft/fire5.mp3")
SWEP.Primary.Automatic = true
SWEP.Primary.Ammo = "none"
if SERVER then
local buffed_jumppower = 240
local buffed_runspeed = 750
local buffed_walkspeed = 375
local cooldown_jumppower = 120
local cooldown_runspeed = 375
local cooldown_walkspeed = 187
local default_jumppower = 160
local default_runspeed = 500
local default_walkspeed = 250
-- Start the adrenaline effect (increased speed and jump power)
local function AdrenalineStart(pl)
pl:SetJumpPower(buffed_jumppower)
pl:SetRunSpeed(buffed_runspeed)
pl:SetWalkSpeed(buffed_walkspeed)
pl.AdrenalineActive = true
pl.NextAdrenalineCooldown = CurTime() + 45
pl.NextAdrenalineStop = nil
end
-- Cooldown effect (decreased speed and jump power)
local function AdrenalineCooldown(pl)
pl:SetJumpPower(cooldown_jumppower)
pl:SetRunSpeed(cooldown_runspeed)
pl:SetWalkSpeed(cooldown_walkspeed)
pl.NextAdrenalineCooldown = nil
pl.NextAdrenalineStop = CurTime() + 20
end
-- Stop the adrenaline effect (reset speed and jump power)
local function AdrenalineStop(pl)
pl:SetJumpPower(default_jumppower)
pl:SetRunSpeed(default_runspeed)
pl:SetWalkSpeed(default_walkspeed)
pl.AdrenalineActive = false
pl.NextAdrenalineCooldown = nil
pl.NextAdrenalineStop = nil
end
-- Reset the adrenaline start timer
-- This makes sure the adrenaline effect will never start if the player switches weapons before the animation has finished playing
function SWEP:Deploy()
self.Weapon:SendWeaponAnim(ACT_SLAM_DETONATOR_DRAW)
self.NextAdrenalineStart = nil
return true
end
end
function SWEP:PrimaryAttack()
self:SendWeaponAnim(ACT_SLAM_DETONATOR_DETONATE)
self:EmitSound(self.Primary.Sound)
if CLIENT then return end
-- Start the adrenaline effect when the animation has finished playing
self.NextAdrenalineStart = CurTime() + self:SequenceDuration()
end
if SERVER then
function SWEP:Think()
if self.NextAdrenalineStart and CurTime()>self.NextAdrenalineStart then
AdrenalineStart(self.Owner)
-- switch to the last weapon
self.Owner:ConCommand("lastinv")
self.NextAdrenalineStart = nil
self:Remove()
end
end
-- Monitor the adrenaline effect every tick here
hook.Add("Tick", "AdrenalineThink", function()
for _,pl in ipairs(player.GetAll()) do
if pl.AdrenalineActive then
if pl.NextAdrenalineCooldown and CurTime()>pl.NextAdrenalineCooldown then
AdrenalineCooldown(pl)
end
if pl.NextAdrenalineStop and CurTime()>pl.NextAdrenalineStop then
AdrenalineStop(pl)
end
end
end
end)
-- If the player dies, stop the adrenaline effect
hook.Add("DoPlayerDeath", "AdrenalineDeath", function(pl)
AdrenalineStop(pl)
end)
end[/lua]
The whole code.
Errors are either blue, or yellow sometimes, but for the most, they are blue.
Sorry, you need to Log In to post a reply to this thread.