Wednesday, October 6, 2010

Sword

I found another sword that we could use for the game. This time it actually inflicts damage! I've also noticed that many of these weapons are programmed in LUA. They are called SWEPs (Scripted Weapons). I took a peak at the LUA source file and it actually seems pretty simple to modify. Here are some snippets from the code:
SWEP.Primary.Delay = 0.9 --In seconds
SWEP.Primary.Recoil = 0 --Gun Kick
SWEP.Primary.Damage = 15 --Damage per Bullet
SWEP.Primary.NumShots = 1 --Number of shots per one fire
SWEP.Primary.Cone = 0 --Bullet Spread
SWEP.Primary.ClipSize = -1 --Use "-1 if there are no clips"
SWEP.Primary.DefaultClip = -1 --Number of shots in next clip
SWEP.Primary.Automatic = true --Pistol fire (false) or SMG fire (true)
SWEP.Primary.Ammo = "none" --Ammo Type

It's very simple to modify certain attributes of the weapon such as it's rate of fire, damage, recoil, etc.

If you take a look at the code snippet below, you can see that we have easy control over what sounds the weapon can make, depending on the scenario. The first paragraph of code precaches or "loads" the sound files into memory. This is required so the sounds are available and can be played on demand.
util.PrecacheSound("weapons/knife/knife_deploy1.wav")
util.PrecacheSound("weapons/knife/knife_hitwall1.wav")
util.PrecacheSound("weapons/knife/knife_hit1.wav")
util.PrecacheSound("weapons/knife/knife_hit2.wav")
util.PrecacheSound("weapons/knife/knife_hit3.wav")
util.PrecacheSound("weapons/knife/knife_hit4.wav")
util.PrecacheSound("weapons/iceaxe/iceaxe_swing1.wav")

In this paragraph we can control which sounds are played. We can customize the sounds it makes when you hit a wall or the ground, and you can modify/add sounds it makes when hitting flesh (Applies to Players and NPCs).
self.Hit = {
Sound( "weapons/knife/knife_hitwall1.wav" )};
self.FleshHit = {
Sound( "weapons/knife/knife_hit1.wav" ),
Sound( "weapons/knife/knife_hit2.wav" ),
Sound( "weapons/knife/knife_hit3.wav" ),
Sound( "weapons/knife/knife_hit4.wav" ) };

The code is very organized and they even had the courtesy to comment next to their code. We may not know how to build code from scratch, but we can use the provided scripts as templates and learning tools for LUA.


Once again if anyone is interested in working on this project, please contact me at Popko37197@gmail.com. Even if you don't want any obligations or you just want to play around with Garry's Mod, feel free to contact me. Every little bit of help matters.

No comments:

Post a Comment