16
Modification Help / Ammo snippet
« on: March 12, 2010, 09:50:49 PM »
A resource of mine. This lets a weapon do 3 things:
1) Use a limited ammo supply refueled by events
2) Hold a certain number of shots at once in a clip
3) Reload that clip
This script originated from a very old script of mine; there are useless and pointless additional lines and probably some fallacies here and there but the main thing is that it works and some benevolent scripter will probably come through here and tell me everything I've been doing wrong for the past few years (yes, this script is that old).
That or someone will have it deleted.
Enjoy it while you can.
Example: Shotgun
OnFire
Reload
Automatic reload on mount
Ammo Event
Important notes:
- You have to change basically everything that has "shotgun" in it. On top of that, the onfire must be modified heavily to produce the kind of firing you want.
- Each weapon must have its own reload, mount, and onfire modifications.
- The add ammo event does not have to be added to each weapon. Once is enough.
- $bulletloadedmax["weapon"]=max ammo carried at one time;
- Each weapon must have one of the above
1) Use a limited ammo supply refueled by events
2) Hold a certain number of shots at once in a clip
3) Reload that clip
This script originated from a very old script of mine; there are useless and pointless additional lines and probably some fallacies here and there but the main thing is that it works and some benevolent scripter will probably come through here and tell me everything I've been doing wrong for the past few years (yes, this script is that old).
That or someone will have it deleted.
Enjoy it while you can.
Example: Shotgun
OnFire
Code: [Select]
function SshotgunImage::onFire(%this,%obj,%slot)
{
//ReloadTimeMS: 2500 Next line
%reloadtime="2500";
//ClipSize: 7 Next line
if(!%obj.bulletloaded["shotgun"]){%obj.bulletloaded["shotgun"]=7;}
if(!%obj.shotguncritchance){%obj.shotguncritchance=4;}
if(%obj.shotgunreloading){
%obj.cancelshotgunreloading=1;
%obj.shotgunreloading=0;
cancel($shotgunreload[%obj]);
$shotgunreload[%obj]=0;
}
if(1 > %obj.bulletloaded["shotgun"]-1){
%obj.playThread(2, shiftdown);
//centerprint(%obj.client,"Reloading...\c1" SPC %obj.bulletloaded["shotgun"]-1 @ "\c0/\c1" @ $bulletloadedmax["shotgun"] - %obj.bulletexpended["shotgun"],200);
%obj.shotgunreloading=1;
$shotgunreload[%obj]=schedule(%reloadtime,0,"Sshotgunreload",%obj);
return;
}
if(%obj.getDamagePercent() < 1.0)
%obj.playThread(2, shiftAway);
%projectile = %this.projectile;
%typer="SshotgunProjectile";
%a=getrandom(1,%obj.shotguncritchance+2);
%spread = 0.0028;
%pvec = %obj.client.player.getvelocity();
//if you move, spread goes up
if(getword(%pvec,0) + getword(%pvec,1) + getword(%pvec,2) > 1 || getword(%pvec,0) + getword(%pvec,1) + getword(%pvec,2) < -1){
%spread += 0.0008;
}else{
%spread -= 0.0008;
}
%shellcount=6;
%scale="1 1 1";
%obj.bulletloaded["shotgun"]-=1;
centerprint(%obj.client,"\c0Shots left:\c1" SPC %obj.bulletloaded["shotgun"]-1 @ "\c0/\c1" @ $bulletloadedmax["shotgun"] - %obj.bulletexpended["shotgun"],400);
//I'm sure Ephi has some comments on how I stole this from him because I did
for(%shell=0; %shell<%shellcount; %shell++)
{
%vector = %obj.getMuzzleVector(%slot);
%objectVelocity = %obj.getVelocity();
%vector1 = VectorScale(%vector, %projectile.muzzleVelocity+%bonus);
%vector2 = VectorScale(%objectVelocity, %projectile.velInheritFactor);
%velocity = VectorAdd(%vector1,%vector2);
%x = (getRandom() - 0.5) * 10 * 3.1415926 * %spread;
%y = (getRandom() - 0.5) * 10 * 3.1415926 * %spread;
%z = (getRandom() - 0.5) * 10 * 3.1415926 * %spread;
%mat = MatrixCreateFromEuler(%x @ " " @ %y @ " " @ %z);
%velocity = MatrixMulVector(%mat, %velocity);
%p = new (%this.projectileType)()
{
dataBlock = %typer;
initialVelocity = %velocity;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
};
%p.setscale(%scale);
MissionCleanup.add(%p);
}
//ClipSize: 7 Next line
if(1 > %obj.bulletloaded["shotgun"]-1 || %obj.bulletloaded["shotgun"] < 7){
if(!%obj.shotgunreloading&&$shotgunreload[%obj]==0){
%obj.playThread(2, shiftdown);
centerprint(%obj.client,"Reloading...\c1" SPC %obj.bulletloaded["shotgun"]-1 @ "\c0/\c1" @ $bulletloadedmax["shotgun"] - %obj.bulletexpended["shotgun"],200);
%obj.shotgunreloading=1;
$shotgunreload[%obj]=schedule(%reloadtime,0,"Sshotgunreload",%obj);
}
}
return %p;
}
Reload
Code: [Select]
function Sshotgunreload(%obj){
if(!isobject(%obj)||%obj.getdamagelevel() >= %obj.getdatablock().maxdamage){
return;
}
if(%obj.cancelshotgunreloading){
%obj.cancelshotgunreloading=0;
}
if(%obj.getmountedimage(0)!$=nametoid("Sshotgunimage")){
%obj.cancelshotgunreloading=1;
%obj.shotguncritchance-=2;
if(%obj.shotguncritchance<4){
%obj.shotguncritchance=4;
}
%obj.shotgunreloading=0;
cancel($shotgunreload[%obj]);
$shotgunreload[%obj]=0;
return;
}
if(%obj.bulletexpended["shotgun"] >= $bulletloadedmax["shotgun"]){
%obj.cancelshotgunreloading=1;
%obj.shotguncritchance-=2;
if(%obj.shotguncritchance<4){
%obj.shotguncritchance=4;
}
%obj.shotgunreloading=0;
cancel($shotgunreload[%obj]);
$shotgunreload[%obj]=0;
centerprint(%obj.client,"No ammo...\c1" SPC %obj.bulletloaded["shotgun"]-1 @ "\c0/\c1" @ $bulletloadedmax["shotgun"] - %obj.bulletexpended["shotgun"],200);
return;
}
%obj.playThread(2, shiftright);
//ReloadTimeMS: 2500 Next line
%reloadtime="1200";
%obj.bulletloaded["shotgun"]+=1;
%obj.bulletexpended["shotgun"]++;
%obj.shotgunshellsfired--;
if(%obj.shotgunshellsfired<0){
%obj.shotgunshellsfired=0;
}
centerprint(%obj.client,"Reloading...\c1" SPC %obj.bulletloaded["shotgun"]-1 @ "\c0/\c1" @ $bulletloadedmax["shotgun"] - %obj.bulletexpended["shotgun"],200);
//ClipSize: 7 Next line
if(%obj.bulletloaded["shotgun"] < 7){
$shotgunreload[%obj]=schedule(%reloadtime,0,"Sshotgunreload",%obj);
}else{
%obj.shotguncritchance-=6;
if(%obj.shotguncritchance<4){
%obj.shotguncritchance=4;
}
%obj.shotgunreloading=0;
$shotgunreload[%obj]=0;
}
}
Automatic reload on mount
Code: [Select]
package shotgunmountreload
{
function SshotgunImage::onMount(%this,%obj,%slot)
{
//ClipSize: 7 Next line
if(!%obj.client.player.bulletloaded["shotgun"]){%obj.client.player.bulletloaded["shotgun"]=7;}
centerprint(%obj.client,"Ammo...\c1" SPC %obj.client.player.bulletloaded["shotgun"]-1 @ "\c0/\c1" @ $bulletloadedmax["shotgun"] - %obj.client.player.bulletexpended["shotgun"],200);
//ClipSize: 7 Next line
if(1 > %obj.client.player.bulletloaded["shotgun"]-1 || %obj.client.player.bulletloaded["shotgun"] < 7){
if(!%obj.client.player.shotgunreloading&&$shotgunreload[%obj.client.player]==0){
%obj.client.player.playThread(2, shiftdown);
centerprint(%obj.client,"Reloading...\c1" SPC %obj.client.player.bulletloaded["shotgun"]-1 @ "\c0/\c1" @ $bulletloadedmax["shotgun"] - %obj.client.player.bulletexpended["shotgun"],200);
%obj.client.player.shotgunreloading=1;
//ReloadTimeMS: 2500 Next line
$shotgunreload[%obj.client.player]=schedule(2500,0,"Sshotgunreload",%obj.client.player);
}
}
parent::onMount(%this,%obj,%slot);
}
};
activatepackage(shotgunmountreload);
Ammo Event
Code: [Select]
$bulletloadedmax["shotgun"]=18;
registerOutputEvent("Player", "Scav_add_ammo", "string 32 100" TAB "int 1 2000 1", 0);
function Player::Scav_add_ammo(%player,%type,%amount){
if(firstword(%type) $= "hp"){//i.e hp fallen
if(getword(%type,1) $= %player.client.curclass){
%player.addhealth(%amount);
}
return;
}
%oldamount=%player.bulletexpended[%type];
%player.bulletexpended[%type] -= %amount;
if(%player.bulletexpended[%type] < 0){
%player.bulletexpended[%type]=0;
}
if(%player.bulletexpended[%type] > $bulletloadedmax[%type]){
%player.bulletexpended[%type]=$bulletloadedmax[%type];
}
%obj=%player;
if(%obj.bulletloaded[%type]-1 >= 0 && %player.bulletexpended[%type] != %oldamount){
centerprint(%obj.client,"Ammo recieved...\c1" SPC %obj.bulletloaded[%type]-1 @ "\c0/\c1" @ $bulletloadedmax[%type] - %obj.bulletexpended[%type],200);
}
}
Important notes:
- You have to change basically everything that has "shotgun" in it. On top of that, the onfire must be modified heavily to produce the kind of firing you want.
- Each weapon must have its own reload, mount, and onfire modifications.
- The add ammo event does not have to be added to each weapon. Once is enough.
- $bulletloadedmax["weapon"]=max ammo carried at one time;
- Each weapon must have one of the above