That wierd, it works for me.
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;
}
}