Author Topic: Support_AmmoReserve - Ammo System  (Read 2904 times)

I believe it actually works now.
Code: [Select]
package AmmoReserve
{
function ItemData::onCollision(%this, %obj, %col, %a, %b, %c, %d, %e, %f)
{
if(%obj.weaponReserveLoaded >= 1 && (%col.getType() & $TypeMasks::PlayerObjectType))
{
echo("ONCOLLISION");
%col.pickup(%obj);
}
else
Parent::onCollision(%this, %obj, %col, %a, %b, %c, %d, %e, %f);
}
function ItemData::onPickup(%this,%obj,%user,%amt)
{
echo("hi");
%data = %obj.dataBlock;
%dropReserve = %obj.weaponReserveLoaded;
%p = %dropReserve / 100;
%addslot0 = %user.maxReserve[0] * %p;
%addslot1 = %user.maxReserve[1] * %p;
%addslot2 = %user.maxReserve[2] * %p;
%addslot3 = %user.maxReserve[3] * %p;
%addslot4 = %user.maxReserve[4] * %p;
if(%dropReserve >= 1)
{
//if(%user.tool[0].getID() !$= "" && %user.toolReserve[%user.tool[0]] !$= "")
//if(%user.getID[%user.tool[0]] !$= "" && %user.toolReserve[%user.tool[0]] !$= "")
if(%user.toolReserve[0] !$= "")
%user.toolReserve[0] += %addslot0;

if(%user.toolReserve[1] !$= "")
%user.toolReserve[1] += %addslot1;

if(%user.toolReserve[2] !$= "")
%user.toolReserve[2] += %addslot2;

if(%user.toolReserve[3] !$= "")
%user.toolReserve[3] += %addslot3;

if(%user.toolReserve[4] !$= "")
%user.toolReserve[4] += %addslot4;

echo("err");
%user.playAudio(0,ErrorSound);
%obj.delete();
schedule(10,0,ResetReserve,%user);
schedule(10,0,DisplayAmmo,%user);
return;
}
else
Parent::OnPickup(%this,%obj,%user,%amt);
}
function ItemData::onAdd(%this,%obj)
{
if($weaponReserveLoaded !$= "")
{
%obj.weaponReserveLoaded = $weaponReserveLoaded;
$weaponReserveLoaded = "";
echo("lol");
}
Parent::onAdd(%this,%obj);
}
function WeaponImage::onMount(%this, %obj, %slot)
{
if(%obj.currTool == -1 || %obj.toolReserve[%obj.currTool] $= "")
{
%obj.maxReserve[%obj.currTool] = %this.item.maxReserve;
%obj.dropReserve[%obj.currTool] = %this.item.dropReserve;
%obj.toolReserve[%obj.currTool] = %this.item.spawnReserve;
echo("onmount");
}
Parent::onMount(%this, %obj, %slot);
}
function servercmdDropTool(%client,%slot)
{
if(!isObject(%client.player))
return Parent::servercmdDropTool(%client,%slot);

//if(!isObject(%client.player.tool[%slot]) || %client.player.tool[%slot].maxReserve <= 0)
// return Parent::servercmdDropTool(%client,%slot);

//$weaponAmmoLoaded = %client.player.dropReserve[%client.player.currTool];
//if(%client.player.tool[%slot].dropReserve >= 0)
//if(%client.player.maxReserve[%client.player.currTool] == 800)
//$WeaponReserveLoaded = 1;
if(%client.player.dropReserve[%client.player.currTool] !$= "")
$WeaponReserveLoaded = %client.player.dropReserve[%client.player.currTool];

%client.player.maxReserve[%client.player.currTool] = "";
%client.player.dropReserve[%client.player.currTool] = "";
%client.player.toolReserve[%client.player.currTool] = "";
return Parent::servercmdDropTool(%client,%slot);
}
function ResetReserve(%this)
{
if(%this.toolReserve[0] > %this.maxReserve[0])
%this.toolReserve[0] = %this.MaxReserve[0];

if(%this.toolReserve[1] > %this.maxReserve[1])
%this.toolReserve[1] = %this.MaxReserve[1];

if(%this.toolReserve[2] > %this.maxReserve[2])
%this.toolReserve[2] = %this.MaxReserve[2];

if(%this.toolReserve[3] > %this.maxReserve[3])
%this.toolReserve[3] = %this.MaxReserve[3];

if(%this.toolReserve[4] > %this.maxReserve[4])
%this.toolReserve[4] = %this.MaxReserve[4];

if(%this.toolReserve[0] < 0)
%this.toolReserve[0] = 0;

if(%this.toolReserve[1] < 0)
%this.toolReserve[1] = 0;

if(%this.toolReserve[2] < 0)
%this.toolReserve[2] = 0;

if(%this.toolReserve[3] < 0)
%this.toolReserve[3] = 0;

if(%this.toolReserve[4] < 0)
%this.toolReserve[4] = 0;
}
function DisplayAmmo(%this)
{
%this.client.bottomprint("<just:right><color:FFFF00>Ammo <color:FFFFFF>:<color:FF0000>" SPC %this.toolReserve[%this.currTool], 3);
}
};activatePackage(AmmoReserve);
« Last Edit: September 03, 2010, 03:29:33 PM by The Titanium »

Space, is there a way to make a model produce emitters via function/script instead of using states?
For example, if I wanted an image to produce an emitter at WeaponImage::OnFire without using states?
« Last Edit: September 03, 2010, 04:04:49 PM by The Titanium »

Not that I know of. You can spawn a projectile with an explosion near the barrel but that won't follow the barrel if the particle effect lasts for more than half a second or you're moving fast.

Hm. Because I don't really want to use ImageAmmo to prevent weapons from firing, because that'd interfere with other mods, such as Support_AmmoGuns.

I guess I'd have to do with what I've got.

Well, not really. setImageAmmo only applies to Support_AmmoGuns if you actually set the stateScript parts to some of the functions I added e.g. "onLoadCheck", "onReloadCheck", "onReloaded". The idea is that you can script your weapon's reloading method to however you want. (all at once, single shells)

Well, yeah, but like, do you mean it can work with both using ImageAmmo for both AmmoGuns (Reloading) and AmmoReserve?

If you make the state system cleverly enough, yes.

I use setImageAmmo in three places - to go from "ready" to "reloading" when you press the Light, from "fire" or "smoke" etc. to a check if you're out of ammo and in the middle of a single-shells reload to check if the gun is full yet. If you added another few before the reloading to check that you do have reserve ammo and somehow disabled reloading with the light if you have no reserve ammo at all, it'll work.

Would this still be possible with a rapid fire weapon?
It wouldn't slow it down at all?

I've been trying to do the above idea but I seem to be limited to 9 states.
Is this normal?
Or am I doing something wrong?


I think it works now.

But I can't get it to fire any faster.

Code: [Select]
stateName[0] = "Activate";
stateTimeoutValue[0] = 0.15;
stateTransitionOnTimeout[0] = "ReserveCheckA";
stateSound[0] = weaponSwitchSound;

stateName[1] = "ReserveCheckA";
stateScript[1] = "OnReserveCheck";
stateTimeoutValue[1] = 0.001;
stateTransitionOnTimeout[1] = "ReserveCHeckB";

stateName[2] = "ReserveCheckB";
stateTransitionOnAmmo[2] = "LoadCheckA";
stateTransitionOnNoAmmo[2] = "ReadyNoReserve";

stateName[3] = "ReadyNoReserve";
stateScript[3] = "OnReserveCheck";
stateTransitionOnAmmo[3] = "LoadCheckA";
stateTransitionOnTriggerDown[3] = "ReserveCheckA";

stateName[4] = "Ready";
stateTransitionOnNoAmmo[4] = "ReloadStart";
stateTransitionOnTriggerDown[4] = "ReserveCheckAFire";
stateAllowImageChange[4] = true;
stateSequence[4] = "Ready";

stateName[5] = "ReserveCheckAFire";
stateScript[5] = "OnReserveCheck";
stateTimeoutValue[5] = 0.001;
stateTransitionOnTimeout[5] = "ReserveCheckBFire";

stateName[6] = "ReserveCheckBFire";
stateTransitionOnAmmo[6] = "LoadCheckAFire";
stateTransitionOnNoAmmo[6] = "ReadyNoReserve";

stateName[7] = "LoadCheckAFire";
stateScript[7] = "OnLoadCheck";
stateTransitionOnTimeout[7] = "LoadCheckBFire";

stateName[8] = "LoadCheckBFire";
stateTransitionOnAmmo[8] = "Fire";
stateTransitionOnNoAmmo[8] = "Ready";

stateName[9] = "Fire";
stateTransitionOnTimeout[9] = "Smoke";
stateTimeoutValue[9] = 0.03;
stateFire[9] = true;
stateAllowImageChange[9] = false;
stateScript[9] = "onFire";
stateSequence[9] = "Fire";
stateWaitForTimeout[9] = true;
stateEmitter[9] = gunFlashEmitter;
stateEmitterTime[9] = 0.05;
stateEmitterNode[9] = "muzzleNode";
stateSound[9] = TF2PistolFireSound;

stateName[10] = "Smoke";
stateEmitter[10] = gunSmokeEmitter;
stateEmitterTime[10] = 0.1;
stateTimeoutValue[10] = 0.05;
stateTransitionOnTimeout[10] = "Wait";

stateName[11] = "Wait";
stateTimeoutValue[11] = 0.001;
//stateScript[11]                   = "onBounce";
stateTransitionOnTimeout[11] = "ReserveCheckA";

//Torque switches states instantly if there is an ammo/noammo state, regardless of stateWaitForTimeout
stateName[12] = "LoadCheckA";
stateScript[12] = "onLoadCheck";
stateTimeoutValue[12] = 0.001;
stateTransitionOnTimeout[12] = "LoadCheckB";

stateName[13] = "LoadCheckB";
stateTransitionOnAmmo[13] = "Ready";
stateTransitionOnNoAmmo[13] = "ReloadWait";

stateName[14] = "ReloadWait";
stateTimeoutValue[14] = 0.01;
stateScript[14] = "";
stateTransitionOnTimeout[14] = "ReloadStart";
stateWaitForTimeout[14] = true;

stateName[15] = "ReloadStart";
stateTimeoutValue[15] = 1;
stateScript[15] = "onReloadStart";
stateTransitionOnTimeout[15] = "Reloaded";
stateWaitForTimeout[15] = true;
stateSound[15] = Block_MoveBrick_Sound;

stateName[16] = "Reloaded";
stateTimeoutValue[16] = 0.25;
stateScript[16] = "onReloaded";
stateTransitionOnTimeout[16] = "Ready";
stateSound[16] = Block_PlantBrick_Sound;

Reorganized it.
Code: [Select]
stateName[0] = "Activate";
stateTimeoutValue[0] = 0.15;
stateTransitionOnTimeout[0] = "ReserveCheckA";
stateSound[0] = weaponSwitchSound;

stateName[1] = "Ready";
stateTransitionOnNoAmmo[1] = "ReloadStart";
stateTransitionOnTriggerDown[1] = "ReserveCheckAFire";
stateAllowImageChange[1] = true;
stateSequence[1] = "Ready";

stateName[2] = "Fire";
stateTransitionOnTimeout[2] = "Smoke";
stateTimeoutValue[2] = 0.03;
stateFire[2] = true;
stateAllowImageChange[2] = false;
stateScript[2] = "onFire";
stateSequence[2] = "Fire";
stateWaitForTimeout[2] = true;
stateEmitter[2] = gunFlashEmitter;
stateEmitterTime[2] = 0.05;
stateEmitterNode[2] = "muzzleNode";
stateSound[2] = TF2PistolFireSound;

stateName[3] = "Smoke";
stateEmitter[3] = gunSmokeEmitter;
stateEmitterTime[3] = 0.1;
stateTimeoutValue[3] = 0.05;
stateTransitionOnTimeout[3] = "Wait";

stateName[4] = "Wait";
stateTimeoutValue[4] = 0.001;
//stateScript[4]                   = "onBounce";
stateTransitionOnTimeout[4] = "ReserveCheckA";

//Torque switches states instantly if there is an ammo/noammo state, regardless of stateWaitForTimeout
stateName[5] = "ReserveCheckA";
stateScript[5] = "OnReserveCheck";
stateTimeoutValue[5] = 0.001;
stateTransitionOnTimeout[5] = "ReserveCHeckB";

stateName[6] = "ReserveCheckB";
stateTransitionOnAmmo[6] = "LoadCheckA";
stateTransitionOnNoAmmo[6] = "ReadyNoReserve";

stateName[7] = "ReadyNoReserve";
stateScript[7] = "OnReserveCheck";
stateTransitionOnAmmo[7] = "LoadCheckA";
stateTransitionOnTriggerDown[7] = "ReserveCheckA";

stateName[8] = "ReserveCheckAFire";
stateScript[8] = "OnReserveCheck";
stateTimeoutValue[8] = 0.001;
stateTransitionOnTimeout[8] = "ReserveCheckBFire";

stateName[9] = "ReserveCheckBFire";
stateTransitionOnAmmo[9] = "LoadCheckAFire";
stateTransitionOnNoAmmo[9] = "ReadyNoReserve";

stateName[10] = "LoadCheckAFire";
stateScript[10] = "OnLoadCheck";
stateTransitionOnTimeout[10] = "LoadCheckBFire";

stateName[11] = "LoadCheckBFire";
stateTransitionOnAmmo[11] = "Fire";
stateTransitionOnNoAmmo[11] = "Ready";

//Torque switches states instantly if there is an ammo/noammo state, regardless of stateWaitForTimeout
stateName[12] = "LoadCheckA";
stateScript[12] = "onLoadCheck";
stateTimeoutValue[12] = 0.001;
stateTransitionOnTimeout[12] = "LoadCheckB";

stateName[13] = "LoadCheckB";
stateTransitionOnAmmo[13] = "Ready";
stateTransitionOnNoAmmo[13] = "ReloadWait";

stateName[14] = "ReloadWait";
stateTimeoutValue[14] = 0.01;
stateScript[14] = "";
stateTransitionOnTimeout[14] = "ReloadStart";
stateWaitForTimeout[14] = true;

stateName[15] = "ReloadStart";
stateTimeoutValue[15] = 1;
stateScript[15] = "onReloadStart";
stateTransitionOnTimeout[15] = "Reloaded";
stateWaitForTimeout[15] = true;
stateSound[15] = Block_MoveBrick_Sound;

stateName[16] = "Reloaded";
stateTimeoutValue[16] = 0.25;
stateScript[16] = "onReloaded";
stateTransitionOnTimeout[16] = "Ready";
stateSound[16] = Block_PlantBrick_Sound;
Code: [Select]
//Check if your weapon has no 'reserve' ammo. Use this to trigger state changes.
function WeaponImage::OnReserveCheck(%this,%obj,%slot)
{
if($AmmoReserve::Disable)
%obj.setImageAmmo(%slot,1);

if(%obj.toolReserve[%obj.currtool] <= 0)
%obj.setImageAmmo(%slot,0);
else
%obj.setImageAmmo(%slot,1);
}

//Use this to prevent the weapon from checking if you have 'reserve' ammo when AmmoReserve::Disable is on.
function WeaponImage::OnReserveDisableCheck(%this,%obj,%slot)
{
if($AmmoReserve::Disable)
%obj.setImageAmmo(%slot,1);
else
%obj.setImageAmmo(%slot,0);
}
« Last Edit: September 06, 2010, 03:44:44 PM by The Titanium »