I want to make a recoilless rifle swep,
This is a mounted one:
[url]https://armamentsales.sslpowered.com/photos/albums/userpics/10001/normal_Loading_M20_Recoilless.jpg[/url]
it's basically a tank cannon, but one that doesn't have recoil, hence "recoilless", and I want one as a swep, preferably a multi-barrel one...
you could also call it a railgun with explosive charge :P
but how do I get about doing this... I'd need some kind of base swep, most likely a rocket launcher with an extremely fast rocket that isn't affected by gravity and doesn't leave a trail, can anyone help me with that? :)
and I'd need to know how to import custom models and textures, I plan on making some with 3dsmax and Photoshop cs3...
I would really appreciate it if people would actually comment, I know there's a lot of talented scripters out there who can give me a heads up on a tutorial or base swep of some kind...
download gcfscape. run it. Go To steam/steamaps/accountname/ and open up the garrys mod gcf. Go to addons/counter-strike/lua/weapons and use one of the weapons for a base. Fiddle with the values. and Gmod wiki has a lot of functions.
This will probably not work because I haven't tested it, but anyhoo, this should get you started on the coding.
Make a folder in addons called Rocket Launcher or whatever.
Make another folder called lua.
In that folder make a folder called entities.
In that folder make a folder called rocket.
In that folder 3 lua files called init.lua, cl_init.lua and shared.lua.
Put this code in init.lua
[code]
function ENT:Initialize( )
self.ThinkDelay = 0.10 -- Speed of the rocket (less = faster)
self.BlastDamage = 130
self:SetModel( "myrocket" )
end
function ENT:Think( )
self:SetPos( self:GetPos( ) + self:GetForward( ) ) -- Fly forward
self:NextThink( CurTime( ) + self.ThinkDelay )
return true
end
function ENT:Touch( )
-- Blow up
local exp = ents.Create( "env_explosion" )
exp:SetPos( self:GetPos( ) )
exp:SetKeyValue( "iMagnitude", self.BlastDamage )
exp:Spawn( )
exp:Fire( "Explode", "", 0 )
self:Remove( )
end
[/code]
Put this code in cl_init.lua
[code]
include( "shared.lua" )
[/code]
Put this code in shared.lua
[code]
ENT.Type = "anim"
[/code]
Then go back to the folder addons/Rocket Launcher/lua and make a file called weapons.
In weapons, make a folder called 'rocket_launcher'.
In rocket_launcher, make 1 file called shared.lua
In shared.lua, put this code in:
[code]
if ( CLIENT ) then
SWEP.PrintName = "Rocket Launcher thing"
end
SWEP.WorldModel = "yourrocketlauncherworldmodel.mdl"
SWEP.ViewModel = "yourrocketlauncherviewmodel.mdl"
function SWEP:Initialize( )
if ( SERVER ) then
self:SetHoldType( "ar2" )
end
self:SetDeploySpeed( 1 )
end
function SWEP:PrimaryAttack( )
local vec = self.Owner:GetShootPos( ) + ( self.Owner:GetForward( ) * 25 )
local proj = ents.Create( "rocket" )
proj:SetPos( vec )
proj:SetAngles( self.Owner:EyeAngles( ) )
proj:Spawn( )
self:SetNextPrimaryFire( CurTime( ) + 1 )
end
[/code]
Thank you both, I'll try to make something with this :)
(edit)
_muffin, I got it to work, but it's giving me an error while firing, it says there's an error on line 23 in shared.lua, that line is as follows:
[code] proj:SetPos( vec )[/code]
I'm not very familiar with lua scripting, but is vec a value, or are you calling a variable?
right click is also shotgun fire :P
[QUOTE=Entharion;16412344]
I'm not very familiar with lua scripting, but is vec a value, or are you calling a variable?
right click is also shotgun fire :P[/QUOTE]
Yeah, vec is a variable. Could you give me the full error please?
And for shotgun on right click just put this into init.lua of your weapon:
[code]
function SWEP:SecondaryAttack( )
end
[/code]
[QUOTE=_Muffin;16413036]Yeah, vec is a variable. Could you give me the full error please?
And for shotgun on right click just put this into init.lua of your weapon:
[code]
function SWEP:SecondaryAttack( )
end
[/code][/QUOTE]
I have several errors for you:
when spawned
weapons/recoilless_rifle/shared.lua:12: attempt to call method 'SetHoldType' (a nil value)
while firing
Attempted to create unknown entity type rocket!
weapons/recoilless_rifle/shared.lua:23: Tried to use a NULL entity!
Can't find factory for entity: rocket
and I fixed the rightclick thingie
[QUOTE=Entharion;16413217]
when spawned
weapons/recoilless_rifle/shared.lua:12: attempt to call method 'SetHoldType' (a nil value)
(ok I fixed this I think, instead of self:SetHoldType I made it SWEP:HoldType)[/quote]
Ah, it's supposed to be self:SetWeaponHoldType.
[QUOTE=Entharion;16413217]
while firing
Attempted to create unknown entity type rocket!
weapons/recoilless_rifle/shared.lua:23: Tried to use a NULL entity!
Can't find factory for entity: rocket[/QUOTE]
2 things could've gone wrong here. Either you've placed the rocket entity in the wrong folder or (more likely) is that you've used a different name other than 'rocket' for your entity folder. The name of the folder corresponds to the actual entity made. So.. basically look in your addon folder under lua/entities and replace 'rocket' in init.lua with whatever that folder is called.
[QUOTE=_Muffin;16413490]Ah, it's supposed to be self:SetWeaponHoldType.
2 things could've gone wrong here. Either you've placed the rocket entity in the wrong folder or (more likely) is that you've used a different name other than 'rocket' for your entity folder. The name of the folder corresponds to the actual entity made. So.. basically look in your addon folder under lua/entities and replace 'rocket' in init.lua with whatever that folder is called.[/QUOTE]
hmm, the rocket .lua's are in \recoilless_rifle\lua\entities\rocket\
so the name and location is right... isn't it?
[QUOTE=Entharion;16413674]hmm, the rocket .lua's are in \recoilless_rifle\lua\entities\rocket\
so the name and location is right... isn't it?[/QUOTE]
Does it actually make the rocket?
[QUOTE=_Muffin;16414295]Does it actually make the rocket?[/QUOTE]
No, but I changed the code somewhat, here's what I got now:
[code]if ( CLIENT ) then
SWEP.PrintName = "Recoilless rifle"
SWEP.DrawAmmo = false
SWEP.DrawCrosshair = true
SWEP.ViewModelFOV = 64
SWEP.ViewModelFlip = false
SWEP.CSMuzzleFlashes = false
SWEP.PrintName = "Recoilless Rifle"
SWEP.Author = "Entharion"
SWEP.Slot = 4
SWEP.SlotPos = 3
SWEP.Iconletter = R
end
SWEP.WorldModel = "models/weapons/w_rocket_launcher.mdl"
SWEP.ViewModel = "models/weapons/v_RPG.mdl"
local SecShootSound = Sound("PropAPC.FireRocket")
SWEP.Spawnable = false
SWEP.AdminSpawnable = true
SWEP.Primary.Recoil = 0
SWEP.Primary.Damage = 50
SWEP.Primary.NumShots = 1
SWEP.Primary.Cone = 0
SWEP.Primary.Delay = 1
SWEP.Primary.ClipSize = 1
SWEP.Primary.DefaultClip = 1
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = "shell"
SWEP.Primary.NextFire = 0
local ReloadNextFire = 1
function SWEP:Initialize()
self:SetDeploySpeed( 1 )
if ( SERVER ) then
self:SetWeaponHoldType( self.HoldType )
end
end
function SWEP:PrimaryAttack( )
local spawnpos = self.Owner:GetShootPos() + 32*self.Owner:GetForward() + 32*self.Owner:GetRight()
local ang = self.Owner:GetAimVector():Angle()
local shell = ents.Create( "sent_shell" )
shell:SetPos(spawnpos)
shell:SetAngles(ang)
shell:Spawn()
self:FireRocket(false,ShootSound, self.Owner)
self:SetNextPrimaryFire( CurTime( ) + 1 )
end
function SWEP:SecondaryAttack( )
end[/code]
the error is now
weapons/recoilless_rifle/shared.lua:42: attempt to index global 'owner' (a nil value)
ugh, anyone else know what the problem might be?
[QUOTE=Entharion;16442552]ugh, anyone else know what the problem might be?[/QUOTE]
[code]function SWEP:PrimaryAttack( )
local spawnpos = self.Owner:GetShootPos() + 32*owner:GetForward() + 32*owner:GetRight()
local ang = self.Owner:GetAimVector():Angle()
local proj = ents.Create( "sent_shell" )
rocket:SetPos(spawnpos)
rocket:SetAngles(ang)
rocket:Spawn()
self:FireRocket(false,ShootSound, self.Owner)
self:SetNextPrimaryFire( CurTime( ) + 1 )
end[/code]
You had "owner" instead of "self.Owner".
Hang on a second, self.Owner:GetForward(), why is he taking his current walking speed and multiplying it by 32 to make the rocket speed? Shouldn't it propel itself forward using self:ApplyForce()?
[QUOTE=Unrealomega;16442959][code]function SWEP:PrimaryAttack( )
local spawnpos = self.Owner:GetShootPos() + 32*owner:GetForward() + 32*owner:GetRight()
local ang = self.Owner:GetAimVector():Angle()
local proj = ents.Create( "sent_shell" )
rocket:SetPos(spawnpos)
rocket:SetAngles(ang)
rocket:Spawn()
self:FireRocket(false,ShootSound, self.Owner)
self:SetNextPrimaryFire( CurTime( ) + 1 )
end[/code]
You had "owner" instead of "self.Owner".[/QUOTE]
thank you! still do have errors in there
these:
weapons/weapon_base/init.lua:36: attempt to concatenate local 't' (a nil value)
Attempted to create unknown entity type sent_shell!
weapons/recoilless_rifle/shared.lua:46: Tried to use a NULL entity!
Can't find factory for entity: sent_shell
I updated the code, but I want to know is... what's the right syntaxes for lua, I can't seem to get it right :S
[editline]11:56PM[/editline]
[QUOTE=Killer_Steel;16443151]Hang on a second, self.Owner:GetForward(), why is he taking his current walking speed and multiplying it by 32 to make the rocket speed? Shouldn't it propel itself forward using self:ApplyForce()?[/QUOTE]
Actually, self.owner:getforward() is the position, not the speed... I dunno how or where to implement a fix for this... I'm a total newb xD
No new suggestions? bummer.
Sorry, you need to Log In to post a reply to this thread.