PewPew
The Name
I've renamed it from GCombat to PewPew. Bull's idea 
Why?
I need to practice lua so that I can become better at it, but to do that I need ideas on what to make.
I thought I'd make my own version of GCombat and make it better than the normal GCombat 
This is my dev thread. I'm posting it here because wm.com is better than facepunch.
In this thread you people can post suggestions to my code (how I can make it better and neater) and suggestions for functions.
What?
How is this different from the normal GCombat?
In the normal GCombat, each weapon and each bullet is its own entity. This means each of them add an extra 3 lua files to the server. I thought: Why?
With my GCombat, each bullet uses only 1 lua file (Or you can put all bullets in the same lua file if you'd rather want that, although that might get a little messy
) and there is only 1 cannon (and only 1 bullet entity). I then change the model, sounds, material, color, trails, effects... just about everything on the bullet and the cannon depending on which weapon you choose.
I have no idea on how this affects performance... it may even be suckier than the normal GCombat's way of doing it.. but I'm doing it this way anyway.
The best thing about this is that it makes it ridiculously easy for people who are not lua pros to code their own bullets!
Sample bullet code:
Code:
-- Basic Cannon
local BULLET = {}
-- General Information
BULLET.Name = "Example"
BULLET.Category = "Cannons" -- This is the weapon Category. This is used in the Weapons Menu to choose weapons more easily.
BULLET.Author = "Divran"
BULLET.Description = "Aim away from face."
BULLET.AdminOnly = false
BULLET.SuperAdminOnly = false
-- Appearance
BULLET.Model = "put your model here"
BULLET.Material = nil -- if you want to change the material of the bullet, put the material here instead of "nil" Example: "phoenix_storms/gear"
BULLET.Color = nil -- if you want to change the color of the bullet, put the color here instead of "nil" Example: Color(255,0,0)
BULLET.Trail = nil -- if you want to set a trail on your turret, put a table with the necessary contents. Example: { StartSize = 40, EndSize = 0, Length = 4, Texture = "trails/laser.vmt", Color = Color( 255, 0, 0) }
-- Effects / Sounds
BULLET.FireSound = {"sound1", "sound2","sound3","and so on"} -- use as many sounds as you want
BULLET.ExplosionSound = {"sound1", "sound2","sound3","and so on"} -- use as many sounds as you want
BULLET.FireEffect = "cannon_flare" -- find an effect in the effects folder
BULLET.ExplosionEffect = "big_splosion" -- find an effect in the effects folder
-- Movement
BULLET.Speed = 50
BULLET.PitchChange = 0.2
BULLET.RecoilForce = 500
BULLET.Spread = 0
-- Damage
BULLET.DamageType = "BlastDamage" -- Look in gcombat_damagecontrol.lua for available damage types
BULLET.Damage = 250
BULLET.Radius = 800
BULLET.RangeDamageMul = 0.3 -- This is only used with "BlastDamage". It determines how much less damage it deals depending on the distance from the center of the blast.
BULLET.NumberOfSlices = nil -- this is only used with "SliceDamage". It determines how many props in a line you want to deal damage to.
BULLET.PlayerDamage = 150
BULLET.PlayerDamageRadius = 300
-- Reloading/Ammo
BULLET.Reloadtime = 3.5
BULLET.Ammo = 0 -- If you set this to 0, it will have infinite ammo
BULLET.AmmoReloadtime = 0
-- Custom Functions
-- (If you set the override var to true, the cannon/bullet will run these instead. Use these functions to do stuff which is not possible with the above variables)
-- Wire Input
BULLET.WireInputOverride = false
function BULLET:WireInput( inputname, value )
-- Nothing
end
-- Fire (Is called before the cannon is about to fire)
BULLET.FireOverride = false
function BULLET:Fire( self )
-- Nothing
end
-- Initialize (Is called when the bullet initializes)
BULLET.InitializeOverride = false
function BULLET:InitializeFunc( self )
-- Nothing
end
-- Think (Is called a lot of times :p)
BULLET.ThinkOverride = false
function BULLET:ThinkFunc( self )
-- Nothing
end
-- Explode (Is called when the bullet explodes) Note: this will not run if you override the think function (unless you call it from there as well)
BULLET.ExplodeOverride = false
function BULLET:Explode( self, trace )
-- Nothing
end
-- This is called when the bullet collides (Advanced users only. It only works if you first override initialize and change it to vphysics)
BULLET.PhysicsCollideOverride = false
function BULLET:PhysicsCollideFunc(CollisionData, PhysObj)
-- Nothing
end
-- Client side overrides:
BULLET.CLInitializeOverride = false
function BULLET:CLInitializeFunc()
-- Nothing
end
BULLET.CLThinkOverride = false
function BULLET:CLThinkFunc()
-- Nothing
end
BULLET.CLDrawOverride = false
function BULLET:CLDrawFunc()
-- Nothing
end
pewpew:AddBullet( BULLET ) Isn't it simple? I will of course add more variables to that later on, such as material and color, but this is just for debugging right now.
How?
How do you code your own weapons?
You can make anything cannon-like using only the variables, without even touching the function overrides at the bottom (leave them all on false).
However, if you want to make "custom" weapons such as timed bombs, bouncy mines, sticky bombs, homing missiles, then you'd have to use the functions.
There is an example file on the first post in this thread (it is also located in PewPew/lua/PewPewBullets/Example Bullet.txt) which explains all those variables that are not self-explanatory, and gives examples to those which need examples.
A tip for you: To code, do this:
1: Create your bullet's lua file. (Create it in PewPew/lua/PewPewBullets/)
2: Copy/paste the Example Bullet code
3: Change the variables to something which you THINK might be what you want.
4: Launch GMod in windowed mode, create server or single player (Note: I haven't tested PewPew in single player yet ...)
5: Spawn the weapon. Try it out. Not good enough?
6: Alt-Tab out to Notepad/notepad ++ and edit your weapon's lua file some more.
7: Instead of restarting the map, you can now simply type:
Code:
lua_run pewpew:LoadBullets()
and PewPew will re-load your bullet.
8: Now simply get out the PewPew tool and Update the cannon to apply the changes. Doing it this way, with the console command instead of changing map, saves a LOT of time.
9: Repeat 6-8 until you like the feel of the weapon.
10: Spawn one of my "Basic" weapons which resemble your weapon (if you weapon is a machinegun, spawn the Basic Machinegun, and so on)
11: Spawn a prop, and increase its weight slightly so that it isn't killed instantly.
12: Dupe the prop so that you have 2
13: Point your weapon on one and my weapon on the other
14: Fire them both at the same time.
15: Check to make sure your weapon does not kill it WAY before mine does or too late. If it does, edit the damage/reload time/etc until it's good and balanced (2 seconds give or take should be close enough)
Also, if you make a weapon, post it here and I might commit it if it's good enough 
When?
It's done when it's done 
Pictures/Videos!
TIP: Use fullscreen!



Download
You must use SVN to download this addon. I am NOT going to post it on Gmod.org. SVN Tutorial is in my signature.
My SVN Link:
Code:
http://divranspack.googlecode.com/svn/trunk/%20divranspack/
or direct link:
http://divranspack.googlecode.com/svn/trunk/%20divranspack/PewPew/
Milestones
Here are some of my bigger achievements.
- Ability to update weapons (Something very useful which GCombat doesn't have!)
- Use Menu (Hold Use on a weapon to see info about it)
- Weapons Menu (Makes it a lot easier to select weapons)
- E2 Functions
- Cores (Makes all entities in a contraption share health)
- The Repair Tool
- Numpad support (Something useful which GCombat doesn't have!)
- Ability to update Numpads (This is something not a lot of entities can do!)
- Over 30 weapons!
- GCombat compability (All GCombat (Note: remove the GCombat damage control code first) and SBEP/SBMP weapons will (should!) now work with PewPew)
- SB3/LS3/RD3 compability (All PewPew weapons can now use energy if you have the required addons and if you don't disable ToggleEnergyUsage).
- The Weapons Menu is now built into the Q/C menu. (And is separate as well)
- Admin Tool (Damage Log, Owner Display, Menu controls)
- Prop Protection Damage check thingy 
- Weapons are now better sorted in a folder structure.
- Death notices changed
- PewPew Weapon Designer
Admining
Useful admin-only console commands:
Code:
Command Argument Default Description
sbox_maxpewpew [Number] 6 Maximum amount of PewPew Cannons
sbox_maxpewpew_cores [Number] 6 Maximum amount of PewPew Cores
sbox_maxpewpew_safezones [Number] 2 Maximum amount of PewPew Safe Zones
PewPew_ToggleDamage 1/0 1 Toggles all PewPew Damage
PewPew_ToggleCoreDamageOnly 1/0 0 Toggles damage vs cores only
PewPew_ToggleFiring 1/0 1 Toggles firing. With this disabled, no PewPew cannons can shoot
PewPew_ToggleNumpads 1/0 1 Toggles numpads. With this disabled, no one can use the numpad inputs. You must use the wire inputs instead.
PewPew_ToggleEnergyUsage 1/0 - Toggles energy usage if you have the required addons installed (SB3). If you have the required addons, it defaults to 1, otherwise to 0.
PewPew_DamageMul [Number] 1 All damage is multiplied by this number
PewPew_CoreDamageMul [Number] 1 All damage vs cores is multiplied by this number
PewPew_RepairToolHeal [Number] 75 The repair rate of the repair tool
PewPew_RepairToolHealCores [Number] 200 The repair rate of the repair tool vs cores
PewPew_ToggleDamageLogSending 1/0 1 Toggles damage log sending (ie, sending the data to clients). If your server is lagging a lot, try turning this off. Once you turn it on again, it will re-send the recent loggings to all players.
PewPew_TogglePP 1/0 0 Toggles Prop Protection Damage (If this is enabled, weapons will only deal damage if the owner of the damaged entity has the owner of the weapon in their PP Friends list)
PewPew_ToggleWeaponDesigner 1/0 0 Toggles the usage of the Weapon Designer. If disabled, no one can create their own weapons. Since the weapon designer can be abused, this is disabled by default.
So! Tell me what you think. 
Thanks To
Free Fall for helping me out with a lot of different things.
Seth for helping me a couple of times.
Everyone with cool ideas
Everyone who made cool weapons
Everyone who has this on their server
Bookmarks