[code]
if ( SERVER ) then
AddCSLuaFile( "shared.lua" )
SWEP.HoldType = "grenade"
end
if ( CLIENT ) then
SWEP.PrintName = "Molotov Cocktail"
SWEP.Author = "Pac_187 / Red Dust"
SWEP.Slot = 4
SWEP.DrawAmmo = true
SWEP.DrawCrosshair = false
SWEP.SlotPos = 3
SWEP.Contact = "http://pac187.pytalhost.com/"
SWEP.Purpose = "Used to blow things up"
SWEP.Instructions = "Left click to throw it far away \n Right click to roll it a few meters"
end
SWEP.ViewModel = "models/weapons/v_molotov.mdl"
SWEP.WorldModel = "models/weapons/w_grenade.mdl"
SWEP.ViewModelFOV = 90
SWEP.Weight = 2
SWEP.AutoSwitchTo = false
SWEP.AutoSwitchFrom = false
SWEP.Spawnable = true
SWEP.AdminSpawnable = true
SWEP.Primary.Recoil = 0
SWEP.Primary.Delay = 0
SWEP.Primary.Damage = 0
SWEP.Primary.ClipSize = 1
SWEP.Primary.DefaultClip = 1
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = "grenade"
SWEP.Secondary.Delay = 0
SWEP.Secondary.ClipSize = 1
SWEP.Secondary.DefaultClip = 1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = "grenade"
/*-----DO NOT DO ANYTHING UNDER THIS LINE EXCEPTING YOU KNOW WHAT YOU ARE DOING!!! -----*/
function SWEP:Initialize()
util.PrecacheSound( "WeaponFrag.Throw" )
util.PrecacheModel( "models/props_junk/garbage_glassbottle003a.mdl" )
end
function SWEP:Think()
end
function SWEP:PrimaryAttack()
local Player = self.Owner
local Molotov = ents.Create( "sent_molotov" )
Molotov:SetOwner( Player )
Molotov:SetPos( Player:GetShootPos() )
-- Molotov:SetAngel( Player:GetAimVector() )
Molotov:Spawn()
local mPhys = Molotov:GetPhysicsObject()
local Force = Player:GetAimVector() * 2500
mPhys:ApplyForceCenter( Force )
self.Weapon:EmitSound( "WeaponFrag.Throw" )
self.Weapon:SendWeaponAnim( ACT_VM_THROW )
timer.Simple( 0.3, self.Weapon.SendWeaponAnim, self, ACT_VM_IDLE )
self.Weapon:SetNextPrimaryFire( CurTime() + 2 )
self.Weapon:SetNextSecondaryFire( CurTime() + 2 )
end
function SWEP:SecondaryAttack()
local Player = self.Owner
local Molotov = ents.Create( "sent_molotov_timed" )
Molotov:SetOwner( Player )
Molotov:SetPos( Player:GetShootPos() )
-- Molotov:SetAngel( Player:GetAimVector() )
Molotov:Spawn()
local mPhys = Molotov:GetPhysicsObject()
local Force = Player:GetAimVector() * 500
mPhys:ApplyForceCenter( Force )
self.Weapon:EmitSound( "WeaponFrag.Throw" )
self.Weapon:SendWeaponAnim( ACT_VM_THROW )
timer.Simple( 0.3, self.Weapon.SendWeaponAnim, self, ACT_VM_IDLE )
self.Weapon:SetNextSecondaryFire( CurTime() + 2 )
self.Weapon:SetNextPrimaryFire( CurTime() + 2 )
end
function SWEP:Deploy()
self.Weapon:SendWeaponAnim( ACT_VM_DRAW )
end
function SWEP:Reload()
return false
end
[/code]
This is a molotov cocktail SWEP I use, but I can't get the ammo to work. By default, there is no ammo display and it has infinite ammo. There are two fire modes, left-click to throw it and right-click to roll it. I've messed with the code and still can't get it to use ammo. So, can anyone please edit this code and post it so it starts with one unit of grenade ammo, and uses ammunition rather than having infinite ammo? Minges really screw up the server with infinite ammo... I also have this RPG SWEP with only one firing mode and I'm having the same issue with ammo. Code:
[code]if ( SERVER ) then
AddCSLuaFile( "shared.lua" )
SWEP.HoldType = "rpg"
end
if ( CLIENT ) then
SWEP.PrintName = "RPG-7"
SWEP.Author = "Seenie"
SWEP.Slot = 4
SWEP.SlotPos = 11
SWEP.ViewModelFOV = 60
SWEP.IconLetter = ""
SWEP.DrawAmmo = true
SWEP.CSMuzzleFlashes = false
SWEP.DrawCrosshair = false
SWEP.Category = "Seenie";
SWEP.WepSelectIcon = surface.GetTextureID("materials/weapons/rpgicon");
killicon.AddFont( "weapon_antitank", "CSKillIcons", SWEP.IconLetter, Color( 0, 255, 0, 255 ) )
end
/* DONT DO ANYTHING UNDER THIS LINE UNTIL YOU KNOW WHAT YOU ARE DOING!!!!!!!!*/
-----------------------Main functions----------------------------
SWEP.Base = "weapon_cs_base"
SWEP.IronSightsPos = Vector( -3.74, -5, 0.2 )
----------------------Some difinitions we need-----------------
SWEP.settings = {}
SWEP.settings.loaded = true
SWEP.settings.warhead = "sent_rpgrocket"
SWEP.Ironsights = false
SWEP.SetNextReload = 0
SWEP.reloadtimer = 2.3
SWEP.settings.warheads = {}
SWEP.settings.warheadnumber = 1
SWEP.Warheadsloaded = false
SWEP.settings.warheadchoosing = false
SWEP.settings.warheadpressed = false
SWEP.settings.warheadcount = 0
----------------------Difinitons end-------------------------------
function SWEP:Initialize()
for k,v in pairs(scripted_ents.GetList()) do --Gehn wir mal durch die sent liste
if string.find(v.t.Classname, "sent_rpgrocket") then --Ham wir nen Warhead?
table.insert(self.settings.warheads,v) --Ab in die Warheadliste damit!
end
end
self.settings.warheadcount = table.Count(self.settings.warheads) --Wieviele Warheads haben wir?
self.settings.loaded = true
util.PrecacheSound( "weapons/rpg.wav" )
end
function SWEP:Rocket()
if ( !SERVER ) then return end
local warhead = self.settings.warhead
local rocket = ents.Create( warhead )
rocket:SetOwner( self.Owner )
if ( self.Ironsights == false ) then
local v = self.Owner:GetShootPos()
v = v + self.Owner:GetForward()
v = v + self.Owner:GetRight()
v = v + self.Owner:GetUp()
rocket:SetPos( v )
else
rocket:SetPos( self.Owner:GetShootPos() )
end
rocket:SetAngles( self.Owner:GetAngles() )
rocket:Spawn()
rocket:Activate()
local physObj = rocket:GetPhysicsObject()
--physObj:ApplyForceCenter( self.Owner:GetAimVector() * 100000 )
self.Owner:ViewPunch( Vector( math.Rand( 0, -10 ), math.Rand( 0, 0 ), math.Rand( 0, 0 ) ) )
self.settings.loaded = false
end
function SWEP:Reload()
self.Ironsights = false
self.Weapon:SendWeaponAnim( ACT_VM_RELOAD )
self.Weapon:SetNextPrimaryFire( CurTime() + 2.3 )
self.settings.loaded = true
self:SetIronsights( self.Ironsights )
if ( CLIENT ) then
end
end
function SWEP:PrimaryAttack()
if self.settings.loaded and not self.warheadchoosing then
self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
self:Rocket( self.Owner:GetAimVector() )
self.Weapon:SetNextPrimaryFire( CurTime() + 300 )
self.Weapon:EmitSound( "weapons/rpg.wav" )
if (SERVER) then
self.Owner:SetFOV( 90, 2.3 )
end
end
end
function SWEP:SecondaryAttack()
if not self.warheadchoosing then
if ( SERVER ) then
if ( self.Ironsights == false ) then
self.Ironsights = true
self.Owner:SetFOV( 60, 0.3 )
self.Owner:CrosshairDisable()
else
self.Ironsights = false
self.Owner:SetFOV( 90, 0.3 )
self.Owner:CrosshairEnable()
end
end
self:SetIronsights( self.Ironsights )
end
end
-------------HOLSTER SETTINGS--------------------
function SWEP:Holster()
if ( SERVER ) then
self.Owner:SetFOV( 90, 0.3 )
self.Owner:CrosshairEnable()
self.Ironsights = false
self:SetIronsights( false )
return true
end
self:SetIronsights( self.Irionsights )
end
------------HOLSTER SETTINGS END------------------
------------DEPLOY SETTINGS-----------------------
function SWEP:Deploy()
if not self.Warheadsloaded then
for k,v in pairs(scripted_ents.GetList()) do --Gehn wir mal durch die sent liste
if string.find(v.t.Classname, "sent_rpgrocket") then --Ham wir nen Warhead?
table.insert(self.settings.warheads,v) --Ab in die Warheadliste damit!
end
end
self.settings.warheadcount = table.Count(self.settings.warheads) --Wieviele Warheads haben wir?
self.Warheadsloaded = true
end
if ( SERVER ) then
self.Owner:SetFOV( 90, 0.3 )
self.Owner:CrosshairEnable()
self.Ironsights = false
self:SetIronsights( false )
end
self.settings.loaded = true
self:SetIronsights( self.Ironsights )
end
------------DEPLOY SETTINGS END-------------------
-------------------------------------------------------------------
------------General Swep Info---------------
SWEP.Author = "Seenie"
SWEP.Contact = ""
SWEP.Purpose = "TO PWN SUM NEWBS"
SWEP.Instructions = "Aim and pray :3"
SWEP.Spawnable = true
SWEP.Admi
Sorry, you need to Log In to post a reply to this thread.