Author Topic: Editing existing code for weapons and player-types  (Read 2250 times)

Well, I've decided that in order to balance my TDM efficiently, I need to edit the damage, spray & accuracy, and some other things about the weapons I'm using in it.  I need to know if I got this all right.

I think I know how to change the damage.  You have directDamage, which presumably is how much damage is applied when the projectile hits a player.  You have radiusDamage, also self-explanatory, and damageRadius, which is how far out the damage reaches from the explosion.



Then, if I wanted to edit the deviance in the direction of the projectiles coming out of the weapon, I presume the code is this (just using the mac10 as an example):
Code: [Select]
function mac10Image::onFire(%this,%obj,%slot)
{


%projectile = %this.projectile;
%spread = 0.0012;
%shellcount = 1;

for(%shell=0; %shell<%shellcount; %shell++)
{
%vector = %obj.getMuzzleVector(%slot);
%objectVelocity = %obj.getVelocity();
%vector1 = VectorScale(%vector, %projectile.muzzleVelocity);
%vector2 = VectorScale(%objectVelocity, %projectile.velInheritFactor);
%velocity = VectorAdd(%vector1,%vector2);
%x = (getRandom() - 0.5) * 5 * 3.1415926 * %spread;
%y = (getRandom() - 0.5) * 5 * 3.1415926 * %spread;
%z = (getRandom() - 0.5) * 5 * 3.1415926 * %spread;
%mat = MatrixCreateFromEuler(%x @ " " @ %y @ " " @ %z);
%velocity = MatrixMulVector(%mat, %velocity);

For a second, while looking through the code, I thought that the bullet spread would be like the deviance coordinates from the shell casing ejecting.  But I knew it just had to be more complicated than that.

So how would I increase the spread here?  Would I just increase the percentage on %spread?



On weapons like the M9, where you can fire a couple shots, then reload, then fire again, how would I change how many shots you get in each "clip"?

Code: [Select]
stateName[13]                    = "Ammo6";
stateTransitionOnTimeout[13]     = "Ammo6Ready";
stateTimeoutValue[13]            = 0.54;
stateFire[13]                    = true;
stateAllowImageChange[13]        = false;
stateSequence[13]                = "Fire";
stateScript[13]                  = "onFire";
stateWaitForTimeout[13] = true;
stateEmitter[13] = gunFlashEmitter;
stateEmitterTime[13] = 0.02;
stateEmitterNode[13] = "muzzleNode";
stateSound[13] = M9ShotSound;

stateName[14]                     = "Ammo6Ready";
stateTransitionOnTriggerDown[14]  = "Ammo7";
stateAllowImageChange[14]         = true;
stateSequence[14] = "Ready";

Would I just be able to copy this piece of code which repeats in sequential numbers, and then when I get to how many bullets I want in each clip, I would set the TransitionOnTimeout to Reload?  I would then have this code repeated for x amount of times, each time increasing like "Ammo 3, Ammo 4, etc.:  Then, if I wanted 9 bullets, I would set the TransitionOnTimeout to Reload on the 9th repetition, and remove the "Ammo X Ready" state.

If any of the above are incorrect, please tell me.

Thanks for the help, guys.
« Last Edit: April 27, 2009, 04:07:27 PM by Duckmeister »


For the first one: Increase %spread for more spread. Increase %shellcount for more bullets each shot.

For the second one: You can do that, but if you're having more than two or three projectiles per clip it might be better to make a dynamic ammo system then have it counted when you fire. For instance, have the "Activate" state go to a "Reload Check" state which checks how many bullets you currently have loaded and then either to "Ready" or "Reload" depending on whether you have enough. Whenever you fire, it decreases the count by one then goes through this state again - this makes it much easier to change how much ammo the weapon has as all you need is a "item.maxAmmo = 20" sort of thing.

For the first one: Increase %spread for more spread. Increase %shellcount for more bullets each shot.

For the second one: You can do that, but if you're having more than two or three projectiles per clip it might be better to make a dynamic ammo system then have it counted when you fire. For instance, have the "Activate" state go to a "Reload Check" state which checks how many bullets you currently have loaded and then either to "Ready" or "Reload" depending on whether you have enough. Whenever you fire, it decreases the count by one then goes through this state again - this makes it much easier to change how much ammo the weapon has as all you need is a "item.maxAmmo = 20" sort of thing.

Ah, so that's what you've been talking about in the DB Shotgun and Lupara threads!  That way you dont have to reload each time you pull out the gun.  Right now, I'm not really worried about that, I just need to make some basic edits.

Anyways, so if I wanted to add the spread system to another gun that didn't have it, would I just copy and paste it into the same place in the script? Only, instead of "mac10Image" it would be the current image set up in the script, correct? (also, if the function isn't "Fire", I'd have to change that as well)

Thank you so much for your help.

EDIT:  Also, if I wanted to make a copy of the original weapon, put my edits in the copy only, and the have the copy under a different name, both in the .zip and and in the game (the icon name and everything), what would I have to change to do that?
« Last Edit: April 22, 2009, 04:56:14 PM by Duckmeister »


M9s in real life contain about 15 bullets in each round

M9s in real life contain about 15 bullets in each round

Who the heck cares?

At least I got a bump, I'd really apreciate it if someone answered my second set of questions.

Change the:
Datablock names- As to not over write the previous ones (or end up with duplicates taking up datablocks)
UI names - So it appears differently in the menu
.Zip file name - Obvious reasons
I'm not exactly sure on this one but you might have to change the model names and other things and then put them in the zip file and change them in the script (probably not.) My advice would be to do the other ones above then, if it doesn't work, change all that.

Is there anything else that I'm missing people?

Change the:
Datablock names- As to not over write the previous ones (or end up with duplicates taking up datablocks)
UI names - So it appears differently in the menu
.Zip file name - Obvious reasons
I'm not exactly sure on this one but you might have to change the model names and other things and then put them in the zip file and change them in the script (probably not.) My advice would be to do the other ones above then, if it doesn't work, change all that.

Is there anything else that I'm missing people?

Alright, thank you very much, I'm going to try that out now.

EDIT: If I have the original weapon disabled, can I just leave the datablocks alone?  Then, I would just have to change the UI name and the zip file.  Having the original enabled while the copy is enabled isn't important for me, so I guess I could just do that.

Now, with the whole bullet spread system, if I wanted to add that in a gun that didn't have it, I would just copy and paste it into the same place, and change the function to the appropriate one, correct?
« Last Edit: April 22, 2009, 07:54:47 PM by Duckmeister »

Maybe, trial and error, try it out and tell us.

I tried making an edit of a copy of the Mac10, but I also had to change the filepaths in some of the coding (because I had to rename the zip).  I disabled the original, copy loaded fine, and worked perfectly, with my very noticeable (just for test) changes being...very noticeable.

Thank you, GlassOfMilk, and you, Space Guy, for all the help.

Now, to put the spray feature into a gun that doesn't have it yet.  I'll give you an update on that soon.

Woot.  Just successfully put in the katana leap code (with relevant sound datablocks and files, everything) from the katana to the bat.  Works great.  Just forgot to change the namecheck the first time.

That was easier than I thought.  That means adding in this bullet spread code should be even easier.

Ah, so that's what you've been talking about in the DB Shotgun and Lupara threads!  That way you dont have to reload each time you pull out the gun.  Right now, I'm not really worried about that, I just need to make some basic edits.
Yes. In the end I did this myself for the Double Barrelled Shotgun in my server :cookieMonster:

Anyways, so if I wanted to add the spread system to another gun that didn't have it, would I just copy and paste it into the same place in the script? Only, instead of "mac10Image" it would be the current image set up in the script, correct? (also, if the function isn't "Fire", I'd have to change that as well)
Correct. Most guns use 'onFire' as an automatically generated onFire script is set up in Blockland's source somewhere for weapons without a special one defined. The important line to check is the one stateScript[whatever] = "onFire" - this is what makes the fire function happen when it gets to that state.

EDIT:  Also, if I wanted to make a copy of the original weapon, put my edits in the copy only, and the have the copy under a different name, both in the .zip and and in the game (the icon name and everything), what would I have to change to do that?
Change all the file paths in the .cs files of your new one from "./files" to "Add-Ons/Weapon_OLDGUN/files" as this will reduce server downloads. You then won't need the dts/sound files in the new folder and they'll download to the "original" place with only the script edited. You can then choose to enable either Weapon_OLDGUN or Weapon_EDITEDGUN when you start the server. This won't work if you release the weapon, though. (as they'll need the original installed to have the files in the right place)
« Last Edit: April 23, 2009, 11:46:23 AM by Space Guy »

Hmm. Will this result in a new Add-On?

Hopefully not yes. (shivers)
If it does, I hope it might be original and not like the "generic machineguns" Spaceguy once mentioned...

EDIT: Ignore this post if you want. =/

Well, if you do it my method, you'd end up with something like this:
(This is for a fictional edit of the HE-Grenade to a "Fire Grenade")

Weapon_HEGrenade.zip
server.cs
Weapon_HEGrenade.cs
description.txt
hegrenade.dts
hegrenadeProjectile.dts
hegrenadeFire.wav
hegrenadeBounce.wav
icon_hegrenade
ci_hegrenade

Weapon_FireGrenade (optional packaging into .zip, or just as a folder)
server.cs
Weapon_FireGrenade.cs
description.txt

The Fire Grenade would use all the sounds, textures and icons from the HE-Grenade you already have installed. If somebody joining the server already has the HE-Grenade installed, they get no downloads. If they don't, then they only get the downloads once for that - the Fire Grenade has no downloads on top of that.

When you start your server, you could enable either type of grenade or both together, assuming you changed the "hegrenade" Item/Projectile/Emitter/etc. datablocks to "firegrenade".

If you were releasing the Fire Grenade as an Add-On, then you would have to tell people that the HE Grenade is required to be installed before it's used (for instance, RTB's "Required Add-On" field) - otherwise, the weapon wouldn't work correctly as it'd have no sound, no model and no icons.