Clusterbomb cannon-suggestions

Here’s where you give me suggestions/help for my first SWEP.

How about you give us a little more specifics than just a name?

For example, what do you mean by a “clusterbomb cannon”? Like a bunch of oldstyle cannonballs going through the air?

Spawn the entity sent_ball where the player is looking. ( That’s the bouncy ball. )
Would be easy, and would most likely give you a better understanding of how SWEP’s work before making more complex things.

I just thought of it as something that shoots a cluster bomb. Perhaps clusterbomb launcher would be better?

/facepalm

First of all… this is a FAIL thread. You need to atleast give us something to work with. You just dont say “Hey! Give me suggestions!”

You need to have a problem or actual QUESTION to post in this section, not a command!!!

Now, here is where I ask YOU to come up with a piece of sample code that shows us you atleast even have an idea on how to code as well as even have an idea on how the weapon you are making is going to work.

I’m still a noob at all this. The only thing I know of how to code at the moment is look at things that have been made, figure out what code parts do what, and put things together from there. I haven’t really studied up on lua or any language other than beginning java. Basically, I only know what it does if i can understand what it says, and testing confirms my ideas.

Here’s the code for one of the canisters in the middle of the sequence, and what I’ve been able to figure out in the code. (in )

AddCSLuaFile(“cl_init.lua”)
AddCSLuaFile(“shared.lua”)
include(‘shared.lua’)

[bring information from those two other files]

function ENT:Activate()

end

function ENT:Freeze()
self.Entity:SetMoveType(MOVETYPE_NONE)
end

[doesn’t look like this part is needed.]

function ENT:Explode()
local Ent = ents.Create(“env_explosion”)
Ent:SetPos(self.Entity:GetPos())
Ent:Spawn()
Ent:Activate()
Ent:SetKeyValue(“iMagnitude”, 1)
Ent:SetKeyValue(“iRadiusOverride”, 400)
Ent:Fire(“explode”, “”, 0)

[creates the explosions used during making new canisters/bomblets]

for i = 1, 2 do
	local clustercannon_B = ents.Create("clustercannon_C")

[creates two of the next level canister]

	clustercannon_B:SetModel("models/props_junk/propane_tank001a.mdl")
	clustercannon_B:SetPos(self.Entity:GetPos())
	clustercannon_B:Spawn()

[sets model and position of next canister and spawns it]

	local Phys = clustercannon_B:GetPhysicsObject()
	
	if Phys:IsValid() then
		Phys:Wake()
		Phys:ApplyForceCenter(Vector(math.random(5-500, 500), math.random(5-500, 500), math.random(5-500, 500)) * Phys:GetMass())
	end
end

[not sure. looking at it now, this noob here thinks that this may be what tosses the canisters out from their spawn point, not the env_explosion above. I’ll have to test that. Wish I had noticed that earlier. From what I can tell, it chooses three random forces for each axis for which to propel the canister, but i’m unsure of what a 5-500 and a 500 each do.]

self.Entity:Fire("kill", "", "0.2")

end

[removes the old canister]

function ENT:OnRemove()
end

function ENT:Think()

end

function ENT:OnTakeDamage(Dmg)
end

[looks like three unused functions I don’t feel like removing]

function ENT:Initialize()
self.Entity:SetModel(“models/props_c17/canister02a.mdl”)
self.Entity:PhysicsInit(SOLID_VPHYSICS)
self.Entity:SetMoveType(MOVETYPE_VPHYSICS)
self.Entity:SetSolid(SOLID_VPHYSICS)

[does stuff when the canister spawns]

local Phys = self.Entity:GetPhysicsObject()
if Phys:IsValid() then
	Phys:Wake()
end

timer.Simple(1, self.Explode, self)

end
[makes a delay between being spawned to exploding and moving on to the next level.

I’ll try looking in the code of various “use” command entities to see if I can figure out how to make a separate bomb that is triggerable, and usable for aircraft. I’ll post some more questions if I have any.

PERFECT! That is EXACTLY what you need to do to learn LUA. I know a little bit about java, but only enough to make things do simple stuff. As I cannot focus because I am VERY sick, I will attempt to look at your code and see what works and what dosent.

From what i see this is the canister that the weapon is launching correct?



timer.Simple(1, self.Explode, self)
end


This should be somewhere else. Again I cant focus on my monitor very well but That is supposed to delay the cluster portion AFTER it hits? If so you need to make ANOTHER entity and put this timer into some sort of check to see when it hits the ground or howerver youre making it blow up. Also the End is not needed for a timer and is not a function of its own. It should be in the ENT:Explode function before the For loop.

You also need an “end” to close the For loop. From what I see it shold be next to the other 2 ends.

Those 3 functions that you said you dont need, unless your planning to run something each frame (or is it Tick???), you do not need any of those. If you DO need to run something each frame/tick then you need to keep the ENT:Think

Also Comments in LUA is – for each line. so if i wanted to make a comment it would be

–this is a comment.

That piece of code is the init for one oc the canisters in the middle of the explosions. Here’s what’s for the final piece, the bomblet. Those comments I put in the first code part aren’t actually in the code, I just put them in while writing the post. I noticed the – before things that looked like comments.

AddCSLuaFile(“cl_init.lua”)
AddCSLuaFile(“shared.lua”)
include(‘shared.lua’)

function ENT:Activate()
end

function ENT:Freeze()
self.Entity:SetMoveType(MOVETYPE_NONE)
end

function ENT:Explode()
local Ent = ents.Create(“env_explosion”)
Ent:SetPos(self.Entity:GetPos())
Ent:Spawn()
Ent:Activate()
Ent:SetKeyValue(“iMagnitude”, 1000)
Ent:SetKeyValue(“iRadiusOverride”, 400)
Ent:Fire(“explode”, “”, 0)
self.Entity:Fire(“kill”, “”, “0”)
end

function ENT:PhysicsCollide( data, physobj )
if data.Speed > 1 and data.DeltaTime > 0.1 then – if it hits an object at over 1 speed
self:Explode()
self.Entity:Remove()
end
end
function ENT:OnRemove()
end

function ENT:Think()
end

function ENT:Initialize()
self.Entity:SetModel(“models/weapons/w_eq_fraggrenade.mdl”)
self.Entity:SetColor(50, 50, 50, 255)
self.Entity:PhysicsInit(SOLID_VPHYSICS)
self.Entity:SetMoveType(MOVETYPE_VPHYSICS)
self.Entity:SetSolid(SOLID_VPHYSICS)

local Phys = self.Entity:GetPhysicsObject()
if Phys:IsValid() then
	Phys:Wake()
end

end

[editline]11:46PM[/editline]

Okay, I played around with the 5-500, 500 numbers, and I think it changed how the canisters fly out, i’m not sure. I also took a look at the cactus SENT, and I think I may have an idea on how to make a version of the main bomb part that is spawnable, and won’t blow up until it’s used. Later, i’ll try to display the countdown timer. The next step after making it spawnable is making some kind of ground-based launcher for it-- a real clusterbomb cannon. First, i’ll have to figure out how to make the launcher activate it. My new plans are, as I come up with these things, the first one, already mostly done, is the SWEP I have out now. next would be the launcher. The final thing I hope to make is something I can put onto an airplane or other object that spawns the main clusterbomb, to be dropped below. I’ll take a look at propflight or something, and see how it makes bombs.

[editline]11:50PM[/editline]

I learned a very basic amount of java, from t noncredit class, basically how to make animations and a simple paint program (both of which I have forgotten how to do). Hope you get well again. Don’t feel that you need to push yourself just to help with my code. I tested it until it worked to my satisfaction before I uploaded it, so I know it works, but I had been looking for help on how to make those expansions I mentioned.

By the way, If you put your code in [ lua][ /lua] or [ code][ /code] tags, things will appear much nicer and hold all the tabs and formatting you put in the code. I forgot to tell you about that.

It seems like you are using some sort of template correct? Because you have blank functions up there that you do not need. You dont need Think or Freeze. :slight_smile:

If Im right, that apply force function that you had in the middle sequence, is wrong. I missed it earlier cuz I was drugged up on antibiotics lol. But the actual math.random function is:

math.random( Start Range, End Range )

So if I put 1 in start range, and 30 in end range it would give me a random number between 1 and 30.
If by 5-500 as you were not sure what number to put in there, then nevermind, but if that is the way you are keeping it, I have no idea how you managed to get that code to work… UNLESS its thinking 5 minus 500 and making a random between -455 and 500.

As for the expansions, Its really easy! all you need to do is make an entity create the clusterbomb entity and apply force in the direction its facing. As for setting it off, I dont know how to use numpad, but I can look up how to use Wire inputs to launch it. As for the bombs for planes, simply have a player weld it to the bottom of thier plane and get the position of the entity and spawn the bomb say… 15 units below it? Then just let gravity do its job :wink:

That -455 to 500 must be it. I think the vectors are given with xyz coordinates, and so with the random numbers, it allows the canisters to be tossed in any direction. if it were just vector(math.random(0,500) for the three numbers, they would all go in the same general direction. That’s probably why when just made it go to vector 5,5,5, the bombs all spread out in a long oval shape, they were all tossed in generally the same direction. I’ll try something like math.random(-5,5) or something. Yeah, I used the code from other bombs and launchers as a base, cut and pasted parts of code into it that I thought it needed, and then changed values, models, and entities to make it work for my weapon.

[editline]11:49AM[/editline]



timer.Simple(1, self.Explode, self)
end


Well, the timer seemed to work fine. It looks like the self.explode function is ignored until it’s called by this timer, so it doesn’t look like it matters whether the timer is before or after the explode.

Okay, I’m almost ready to get the final version of the SWEP out. I have the materials and models all put together now. I have some better sounds chosen (still need to get them). Shooting the bomb doesn’t hurt you unless you’re standing on the ground and looking at a downward angle. Shooting from horizontal to vertical upwards is fine, even while running forward. All that’s left is to tighten the grouping a bit. Anyone know how to change the intensity of an env_explosion?.

Here’s the bit in the code I think I need to change somehow, but so far, I haven’t had any luck.

local Ent = ents.Create(“env_explosion”)
Ent:SetPos(self.Entity:GetPos())
Ent:Spawn()
Ent:Activate()
Ent:SetKeyValue(“iMagnitude”, 1) --Used to be higher
Ent:SetKeyValue(“iRadiusOverride”, 1) --Used to be 400. What is this, anyway?
Ent:Fire(“explode”, “”, 0)

Can you please put your code in lua tags it makes it easier to read.

I haven’t figured that part out yet.

[editline]11:45PM[/editline]

Okay, I think the next version is just about ready to go. I just have a few things to tidy up, and version 1 will be out.

I only noticed that the grouping was tightened when I put in the old version of the gun in to run side-by-side, and I noticed the big difference.