Single Projectile Weapon Base: "Weapon Maker"

Moderator: NADEO

Post Reply
10000370
Posts: 15
Joined: 11 Aug 2014, 09:37

Single Projectile Weapon Base: "Weapon Maker"

Post by 10000370 »

Weapon base for making weapons with one Projectile

Features

AutoAim - Set a distance to scan for targets and get pinpoint aiming
(if No target is found it will fire Normally)
BrustFire - Set number of shots and time inbetween shots for Burstfire weapons
SpreadShot - Set Number of Bullets and Angle (in degrees) for horizontal Spread
(if # of Bullets*Angle > 360 degrees, the code will adjust to make # of Bullets evenly Spread around 360 degrees )
MultiHit - Set Blast Radius to allow your weapon to deal Damage to Multiple Targets
(Doesnt have to be the same as bullet size or Damage Radius to work)
ChainHit - Set Arc Radius to get your Shots to Jump between targets on Hits
(Will Fire Forever untill all the Bullets miss a target )
(Will AutoAim to Nearest Target)
(Works with the SpreadShot)
Charging - Delay the Firing of your Shot
(Great for Firing Animations)
Ground Only Firing - Limits shooting to only fire while on the Ground
AirCanceling for Charging - Allows you to cancel by jumping for Ground Charging

All the features work with eachother

Big Thank you to Phil13hebert and his BurstFire Weapon Base.
Using that code I was more easily understand the ManiaScript for controlling weapons.

Have Fun

P.S. the SpreadShot used with the ChainHit will turn your Frames per sec to Frames Per Min if you over do it

P.P.S If anyone finds any bugs, please share and i'll try to fix them

Download
https://www.dropbox.com/s/e28rrawthp4sn ... Action.Gbx
Last edited by 10000370 on 17 Aug 2014, 04:12, edited 2 times in total.
User avatar
TitiShu
Posts: 372
Joined: 27 Feb 2012, 23:31
Location: Belgique

Re: Single Projectile Weapon Base: "Weapon Maker"

Post by TitiShu »

You could maybe explain what is it... and how it's working ???

I've download it in Maniaplanet/Actions folder... and in action maker i can't open it
OS:Windows 8.1 x64
CPU: i5 2500k
RAM: 2x4Go G.Skill Ares
GPU: MSI GTX570
Board: Asus P8Z68-V LX
HDD: WD Green + WD Black
SSD: Crucial M4 64Go
Sound: Realtek (onboard)
Peripherals: Mouse G700 - Keyboard G19 - Headset Roccat Kave
10000370
Posts: 15
Joined: 11 Aug 2014, 09:37

Re: Single Projectile Weapon Base: "Weapon Maker"

Post by 10000370 »

TitiShu wrote:You could maybe explain what is it... and how it's working ???

I've download it in Maniaplanet/Actions folder... and in action maker i can't open it
Its just a weapon base, you got to make the projectile visuals and use the settings to controll its behavior.

You should be able to to just download it to the Actions Folder and open it in Action maker.
if you dont see it when you click open try renaming it and making sure the extensions are right(becase of (filename).action.gbx gets mixed up a lot for me).
User avatar
TitiShu
Posts: 372
Joined: 27 Feb 2012, 23:31
Location: Belgique

Re: Single Projectile Weapon Base: "Weapon Maker"

Post by TitiShu »

I've renamed it and it's still not show in the ingame explorer
OS:Windows 8.1 x64
CPU: i5 2500k
RAM: 2x4Go G.Skill Ares
GPU: MSI GTX570
Board: Asus P8Z68-V LX
HDD: WD Green + WD Black
SSD: Crucial M4 64Go
Sound: Realtek (onboard)
Peripherals: Mouse G700 - Keyboard G19 - Headset Roccat Kave
10000370
Posts: 15
Joined: 11 Aug 2014, 09:37

Re: Single Projectile Weapon Base: "Weapon Maker"

Post by 10000370 »

TitiShu wrote:I've renamed it and it's still not show in the ingame explorer
That wierd, it works for me.

Try this:

copy this code
make a new projectile in action maker
turn on custom mode
click edit script
Delete whats there and copy and paste the code
Save

Code: Select all

#RequireContext CSmAction

#Include "TextLib" as TextLib
#Include "MathLib" as MathLib
#Setting C_Cooldown				300
#Setting C_EnergyCost			1600
#Setting C_EnergyMax				6400
#Setting C_EnergyReload		True
#Setting S_AutoAim					False
#Setting S_AimRange				5.0
#Setting S_BurstMode				False
#Setting S_BulletPerBurst		3
#Setting S_BurstBulletsDelay	150
#Setting S_SpreadMode			False
#Setting S_SpreadNum			3
#Setting S_SpreadAng				5.0
#Setting S_ChargeMode			False
#Setting S_ChargeDelay			150
#Setting S_Grounded				False
#Setting S_AirCancel				False
#Setting S_MultiHit					False
#Setting S_BlastRadius			3.0
#Setting S_ChainHit					False
#Setting S_ArcLength				5.0
#Const C_ProjectileName1 		"Projectile 1"
#Const C_AnimName 				"Anim1"


Void MakeChain(Ident _Projectile, Boolean _SpreadMode, Integer _SpreadNum, Real _SpreadAng, CSmActionEvent _Event){

	declare CSmPlayer Target;
			
	declare Closest = 20.0;
			
	foreach(Victim in Players){
					
		if(!(Victim == Owner) && !(Victim == _Event.Player) && !(Victim.CurrentClan == Owner.CurrentClan)){
					
			declare Real Dist;	
			Dist = MathLib::Distance(_Event.Position, Victim.Position);
					
			if (Dist < Closest){
					
				Target <=> Victim;
				Closest = Dist;
			}
		}
	}
				
	if(!(Target == Null)){
		
		declare dx = _Event.Player.Position.X - Target.Position.X;
		declare dy = _Event.Player.Position.Y - Target.Position.Y;
		declare dz = _Event.Player.Position.Z - Target.Position.Z;
				
		declare Azi = MathLib::Atan2(dx,dz) - (MathLib::PI());
		declare Pol = MathLib::Asin(dy/(MathLib::Sqrt((dz * dz) + (dx * dx))));
			
		if(!_SpreadMode){	
				
			declare nX = MathLib::Cos(Pol) * MathLib::Sin(Azi);
			declare nY = MathLib::Sin(-Pol);
			declare nZ = MathLib::Cos(Pol) * MathLib::Cos(-(Azi));
				
			declare Vec3 Aim = <nX,nY,nZ>;
			declare Vec3 Speed = <0.0,0.0,0.0>;
				
			CreateProjectile(Owner, _Projectile, _Event.Position, Aim, Speed);
			
		} else if(_SpreadMode){
		
			declare Vec3[] FireAngles;
				
			declare Real nX;
			declare Real nY;
			declare Real nZ;
	
			declare Real mX;
			declare Real mY;
			declare Real mZ;
		
			declare Real lX;
			declare Real lY;
			declare Real lZ;
		
			if(_SpreadNum%2 == 0){

				declare Integer iter = (_SpreadNum/2);	
		
				for(i,1,iter){
					
					declare Vec3 nAim;
					declare Vec3 mAim;
					
					declare Multi = -0.5 + i;
					
					declare AngAdd = _SpreadAng*Multi;
		
					nX = MathLib::Cos(Pol) * MathLib::Sin(Azi + AngAdd);
					nY = MathLib::Sin(-Pol);
					nZ = MathLib::Cos(Pol) * MathLib::Cos(-(Azi + AngAdd));
					
					mX = MathLib::Cos(Pol) * MathLib::Sin(Azi - AngAdd);
					mY = MathLib::Sin(-Pol);
					mZ = MathLib::Cos(Pol) * MathLib::Cos(-(Azi - AngAdd));
					
					nAim = <nX,nY,nZ>;
					mAim = <mX,mY,mZ>;
									
					FireAngles.add(nAim);	
					FireAngles.add(mAim);
				}
			} else if(_SpreadNum%2 == 1){

				declare Integer iter = _SpreadNum/2;	
	
				declare Vec3 lAim;
	
				lX = MathLib::Cos(Pol) * MathLib::Sin(Azi);
				lY = MathLib::Sin(-Pol);
				lZ = MathLib::Cos(Pol) * MathLib::Cos(-(Azi));
			
				lAim = <lX,lY,lZ>;
									
				FireAngles.add(lAim)	;
				
				for(i,1,iter){
					
					declare Vec3 nAim;
					declare Vec3 mAim;
					
					declare Multi = 1 + i;
					
					declare AngAdd = _SpreadAng*Multi;
		
					nX = MathLib::Cos(Pol) * MathLib::Sin(Azi + AngAdd);
					nY = MathLib::Sin(-Pol);
					nZ = MathLib::Cos(Pol) * MathLib::Cos(-(Azi + AngAdd));
					
					mX = MathLib::Cos(Pol) * MathLib::Sin(Azi - AngAdd);
					mY = MathLib::Sin(-Pol);
					mZ = MathLib::Cos(Pol) * MathLib::Cos(-(Azi - AngAdd));
					
					nAim = <nX,nY,nZ>;
					mAim = <mX,mY,mZ>;
									
					FireAngles.add(nAim);
					FireAngles.add(mAim);
				}
			}			
			
			declare Vec3 View = _Event.Position;
			declare Vec3 Speed = <0.0,0.0,0.0>;
				
			foreach(Aim in FireAngles){
				CreateProjectile(Owner, _Projectile,View,Aim,Speed);
			}
		}
	}
}

Void MakeBullets(Ident _Projectile, Boolean _SpreadMode, Integer _SpreadNum, Real _SpreadAng, Boolean _AutoAim, Real _AimRange){
		
	declare Vec3 View = Owner.Position;
	View.Y += 1.6;
	declare Vec3 Speed = <0.0,0.0,0.0>;	
		
	if(!_SpreadMode){
	
		if(!_AutoAim){
		
			CreateShoot(Owner, _Projectile);
			SendRulesEvent("fire", Text[], Owner, Null);
			
		}else if(_AutoAim){
		
			declare Nearest = _AimRange;
		
			declare CSmPlayer Target;
		
			foreach(PotTar in Players){
		
				if(!(PotTar == Owner) && !(PotTar.CurrentClan == Owner.CurrentClan)){
			
					declare Real Dist;	
					Dist = MathLib::Distance(View, PotTar.Position);
					
					if (Dist < Nearest){
					
						Target <=> PotTar;
						Nearest = Dist;
					}
				}
			}	
			
			declare Real Azi;	
			declare Real Pol;
			
			if(!(Target == Null)){
			
				declare dx = View.X - Target.Position.X;
				declare dy = View.Y - Target.Position.Y;
				declare dz = View.Z - Target.Position.Z;
	
				
				Azi = MathLib::Atan2(dx,dz) - (MathLib::PI());	
				Pol = MathLib::Asin(dy/(MathLib::Sqrt((dz * dz) + (dx * dx))));
				
			} else if (Target == Null){
			
				Azi = Owner.AimYaw;
				Pol = Owner.AimPitch;
				
			}
			
				declare aX = MathLib::Cos(Pol) * MathLib::Sin(Azi);
				declare aY = MathLib::Sin(-Pol);
				declare aZ = MathLib::Cos(Pol) * MathLib::Cos(-(Azi));
			
				declare Aim = <aX,aY,aZ>;
			
			CreateProjectile(Owner, _Projectile,View,Aim,Speed);
		}
			
	} else {

		declare Vec3[] FireAngles;
		
		declare Pol =Owner.AimPitch;
		declare Azi = Owner.AimYaw;
		
		if(!_AutoAim){
			Pol = Owner.AimPitch;
			Azi = Owner.AimYaw;
		} else if(_AutoAim){
		
			declare Nearest = _AimRange;
		
			declare CSmPlayer Target;
			
			foreach(PotTar in Players){
		
				if(!(PotTar == Owner) && !(PotTar.CurrentClan == Owner.CurrentClan)){
			
					declare Real Dist;	
					Dist = MathLib::Distance(View, PotTar.Position);
					
					if (Dist < Nearest){
					
						Target <=> PotTar;
						Nearest = Dist;
					}
				}
			}
			
			if(!(Target == Null)){
				declare dx = View.X - Target.Position.X;
				declare dy = View.Y - Target.Position.Y;
				declare dz = View.Z - Target.Position.Z;
			
				declare Azi = MathLib::Atan2(dx,dz) - (MathLib::PI());	
				declare Pol = MathLib::Asin(dy/(MathLib::Sqrt((dz * dz) + (dx * dx))));
			} else if(Target == Null){
				Pol = Owner.AimPitch;
				Azi = Owner.AimYaw;
			}
		}
		declare Real nX;
		declare Real nY;
		declare Real nZ;
	
		declare Real mX;
		declare Real mY;
		declare Real mZ;
		
		declare Real lX;
		declare Real lY;
		declare Real lZ;
		
		if(_SpreadNum%2 == 0){

			declare Integer iter = (_SpreadNum/2);	
		
			for(i,1,iter){
					
				declare Vec3 nAim;
				declare Vec3 mAim;
					
				declare Multi = -0.5 + i;
					
				declare AngAdd = _SpreadAng*Multi;
		
				nX = MathLib::Cos(Pol) * MathLib::Sin(Azi + AngAdd);
				nY = MathLib::Sin(-Pol);
				nZ = MathLib::Cos(Pol) * MathLib::Cos(-(Azi + AngAdd));
					
				mX = MathLib::Cos(Pol) * MathLib::Sin(Azi - AngAdd);
				mY = MathLib::Sin(-Pol);
				mZ = MathLib::Cos(Pol) * MathLib::Cos(-(Azi - AngAdd));
					
				nAim = <nX,nY,nZ>;
				mAim = <mX,mY,mZ>;
									
				FireAngles.add(nAim);	
				FireAngles.add(mAim);
			}
		} else if(_SpreadNum%2 == 1){

			declare Integer iter = _SpreadNum/2;	
	
			declare Vec3 lAim;
	
			lX = MathLib::Cos(Pol) * MathLib::Sin(Azi);
			lY = MathLib::Sin(-Pol);
			lZ = MathLib::Cos(Pol) * MathLib::Cos(-(Azi));
			
			lAim = <lX,lY,lZ>;
									
			FireAngles.add(lAim)	;
				
			for(i,1,iter){
					
				declare Vec3 nAim;
				declare Vec3 mAim;
					
				declare Multi = 1 + i;
					
				declare AngAdd = _SpreadAng*Multi;
		
				nX = MathLib::Cos(Pol) * MathLib::Sin(Azi + AngAdd);
				nY = MathLib::Sin(-Pol);
				nZ = MathLib::Cos(Pol) * MathLib::Cos(-(Azi + AngAdd));
					
				mX = MathLib::Cos(Pol) * MathLib::Sin(Azi - AngAdd);
				mY = MathLib::Sin(-Pol);
				mZ = MathLib::Cos(Pol) * MathLib::Cos(-(Azi - AngAdd));
					
				nAim = <nX,nY,nZ>;
				mAim = <mX,mY,mZ>;
									
				FireAngles.add(nAim);
				FireAngles.add(mAim);
			}
		}			
				
		foreach(Aim in FireAngles){
			CreateProjectile(Owner, _Projectile,View,Aim,Speed);
		}
		SendRulesEvent("fire", Text[], Owner, Null);	
	}
}


main(){

if(S_ChargeMode){
	Cooldown = C_Cooldown + S_ChargeDelay;
} else {
	Cooldown = C_Cooldown;
}
EnergyMax = C_EnergyMax;
EnergyCost = C_EnergyCost;
EnergyReload = C_EnergyReload;

declare AnimId0 = GetAnimModelId(C_AnimName);
declare ProjectileId1 = GetProjectileModelId(C_ProjectileName1);

declare AimRange = S_AimRange;

declare BulletPerBurst = S_BulletPerBurst;
declare BurstBulletsDelay = S_BurstBulletsDelay;

declare ChargeDelay = S_ChargeDelay;

declare BlastRadius = S_BlastRadius;
declare ArcLength = S_ArcLength;

declare SpreadNum = S_SpreadNum;
declare SpreadAng = S_SpreadAng *  0.0174532925;

declare BulletShooted = 0;
declare CurrentTime = 0;
declare Burst = False;
declare Bursting = False;
declare Shooted = False;

declare GroundCheck = False;
declare AirCheck = False;

declare Charge = False;
declare Charging = False;
declare StartTime = 0;

// Checks for wrong values for the settings


	if (BulletPerBurst <= 0) BulletPerBurst = 1;
	if (BurstBulletsDelay <= 0) BurstBulletsDelay = 1;
	if (SpreadNum <= 0) SpreadNum = 1;
	if (SpreadAng < 0.0) SpreadAng = 0.0;
	if ((SpreadNum*SpreadAng) > (MathLib::PI()*2)) SpreadAng = (MathLib::PI()*2)/ SpreadNum ;
	if (ChargeDelay <= 0) ChargeDelay = 1;
	if (BlastRadius <= 0) BlastRadius = 0.15;
	if (ArcLength <= 0 ) ArcLength = 1.0;
	if (AimRange <=0) AimRange = 1.0;
	
	while (True) {
		foreach (Event in PendingEvents) {
			switch (Event.Type) {
				case CSmActionEvent::EType::OnHitPlayer : {
					if(S_MultiHit){		
						foreach(Victim in Players){				
							declare Real Dist;				
							Dist = MathLib::Distance(Event.Position, Victim.Position);		
							if (Dist <= BlastRadius){		
								SendRulesEvent("damage", [TextLib::ToText(Event.Damage)], Owner, Victim);
							}
						}
					} else {
						SendRulesEvent("damage", [TextLib::ToText(Event.Damage)], Owner, Event.Player);
					}
					
					if(S_ChainHit){
						MakeChain(ProjectileId1, S_SpreadMode, SpreadNum, SpreadAng, Event);
					}
				}
			}
		}
	
		if(  !S_Grounded || (Owner.IsTouchingGround && S_Grounded) ){
			GroundCheck = True;
		} else{
			GroundCheck = False;
		}
	
		if( !S_AirCancel || (Owner.IsTouchingGround && S_AirCancel)){
			AirCheck = False;
		} else{	
			AirCheck = True;
		}

		if (Owner.SpawnStatus == CSmPlayer::ESpawnStatus::Spawned && IsActive && (Energy >= EnergyCost) && Cooldown_IsReady(Now) && GroundCheck) {
			Cooldown_Start();
			Energy -= EnergyCost;
			PlayAnimOnPlayer(AnimId0, Owner);
			
			Burst = S_BurstMode;
			Charge = S_ChargeMode;
			StartTime = Now;
		
			if(!Burst && !Charge){
				MakeBullets(ProjectileId1,  S_SpreadMode, SpreadNum, SpreadAng, S_AutoAim, AimRange);
			} 
		
			if (Burst){
				Bursting = True;
			}
		
			if(Charge){
				Charging = True;
			}
		}

		if (Owner.SpawnStatus == CSmPlayer::ESpawnStatus::Spawned) {
			if (Charging){
				
				if(AirCheck){
					Charging = False;
					Bursting = False;
				}
				
				
				if (Now >= StartTime + ChargeDelay) {
			
					if (!Bursting){
							MakeBullets(ProjectileId1,  S_SpreadMode, SpreadNum, SpreadAng, S_AutoAim, AimRange);
							Charging = False;
					}
			
					 if (Bursting && BulletShooted < BulletPerBurst) {
						if (!Shooted) {
								MakeBullets(ProjectileId1,  S_SpreadMode, SpreadNum, SpreadAng, S_AutoAim, AimRange);
								CurrentTime = Now;
							Shooted = True;
						} else {
							if (Now >= CurrentTime + BurstBulletsDelay) {
								Shooted = False;
								BulletShooted += 1;
							}
						}
					} else { 
						Bursting = False;
						BulletShooted = 0;
						Charging = False;
					}
				
				
				}
			
			} else if(!Charging){
		
				if (Bursting && BulletShooted < BulletPerBurst) {
					if (!Shooted) {
						MakeBullets(ProjectileId1,  S_SpreadMode, SpreadNum, SpreadAng, S_AutoAim, AimRange);
						CurrentTime = Now;
						Shooted = True;
					} else {
						if (Now >= CurrentTime + BurstBulletsDelay) {
							Shooted = False;
							BulletShooted += 1;
						}
					}
				} else { 
					Bursting = False;
					BulletShooted = 0;
				}
				
		
			}
		}
		yield;
	}
}
User avatar
TitiShu
Posts: 372
Joined: 27 Feb 2012, 23:31
Location: Belgique

Re: Single Projectile Weapon Base: "Weapon Maker"

Post by TitiShu »

Looks that it works...

I'll test that... it looks really promising


Don't know all the possibilities, but do you think it'll be possible to make some Fragmentation weapon/grenade in the futur, with this script ?
OS:Windows 8.1 x64
CPU: i5 2500k
RAM: 2x4Go G.Skill Ares
GPU: MSI GTX570
Board: Asus P8Z68-V LX
HDD: WD Green + WD Black
SSD: Crucial M4 64Go
Sound: Realtek (onboard)
Peripherals: Mouse G700 - Keyboard G19 - Headset Roccat Kave
10000370
Posts: 15
Joined: 11 Aug 2014, 09:37

Re: Single Projectile Weapon Base: "Weapon Maker"

Post by 10000370 »

TitiShu wrote: Don't know all the possibilities, but do you think it'll be possible to make some Fragmentation weapon/grenade in the futur, with this script ?
No, not with this Script. Fragementation would require one of the projectiles to spawn a differnt projectile.
I made this script with features that would work best if you're only using one Projectile.

However I am working on some scripts that will have two stage firing like AirStrikes, Missle Barrages, and your Frag Grenade.

as of right now, I dont have them working yet.
I do plan on sharing as i get these things working.
User avatar
Dommy
Translator
Translator
Posts: 1866
Joined: 25 Aug 2011, 21:45
Location: Poland
Contact:

Re: Single Projectile Weapon Base: "Weapon Maker"

Post by Dommy »

Code for multihit :shock: .
.
.
.
.
You noticed "damage radius" somewhere in bullet gameplay options?

There is also homing on first gameplay options tab btw...
Ryzen 7 2700X, GTX 1070 Ti, 16 GB RAM, Windows 10 Insider Build
FORUM MODERATOR • CREATOR OF SHOOTMANIA GALAXY & TRACKMANIA² PURSUIT

Contact me via GALAXY & PURSUIT DISCORD
10000370
Posts: 15
Joined: 11 Aug 2014, 09:37

Re: Single Projectile Weapon Base: "Weapon Maker"

Post by 10000370 »

domino54 wrote:Code for multihit :shock: .
.
.
.
.
You noticed "damage radius" somewhere in bullet gameplay options?

There is also homing on first gameplay options tab btw...

Yea I noticed it. the reason I added the MultiHit is because of my testing with Damage Radius

I was testing a nuke type weapon with both damage and damage radius set to 1000(Custom mode off) against a cluster of toads.
I was expecting all the toads to die from one hit. however only one toad died per Nuke.
when I went thru the code i found out why.

there is a fucntion called SendRulesEvent that send info to the gamemode script about bullet damage once per when you hit somthing. This fucntion only send info about damage, the player who shot, and the player who got shot.

when i saw this I assumed that the bullets can only "hit" one target. I might be wrong but I added it just in case.

also I use homing in alot of my weapons. Homing and autoAim, although similar, can be used differntly for diffent weapons
novationx
Posts: 2723
Joined: 10 Aug 2013, 22:33

Re: Single Projectile Weapon Base: "Weapon Maker"

Post by novationx »

Is it possible to create a rocket-launcher that after "lock-on" target fires a homing-rocket.
If you didnt lock long enough then its just the normal rocket.

----

Is it possible to create a cookable semtex/grenade? So its like a normal grenade but if you hold down your mouse-button longer then it will explode faster.


Please let me know ^^


If its possible ill try to make smth like this and share it here again.
Cheerz
The neverending waiting game has to stop.
Post Reply

Return to “ActionMaker and Item editor”

Who is online

Users browsing this forum: No registered users and 0 guests