Dear forum users! In compliance with the new European GDPR regulations, we'd just like to inform you that if you have an account, your email address is stored in our database. We do not share your information with third parties, and your email address and password are encrypted for security reasons.

New to the forum? Say hello in this topic! Also make sure to read the rules.

One Survival and one SuperPower script

Custom scripts
Forum rules
By using the forum you agree to the following rules.
Post Reply
User avatar
Mighty Spirit the 2
Superfighter
Superfighter
Posts: 187
Joined: Mon Jun 25, 2018 5:02 pm
Title: Wasted potential
SFD Account: ake004
SFD Alias: Retired SFD player
Started SFD: When melee was good
Location: SFD Veteran trauma hospital
Gender:
Age: 22

One Survival and one SuperPower script

Post by Mighty Spirit the 2 » Sat Feb 18, 2023 1:17 pm

Two scripts i wanted to share. And the scripts aren't important enough to merit 2 separate posts imo.

#Fantastic Four
This script was inspired from a request on Forums one year ago. Originally I had never intended to make the script, not because I thought it would be impossible, but because it would be so broken. Lately my scripting has been getting much better, and because I had recently worked with using Area's, I had some experience and to be honest I once again thought it probably wouldn't take much time. I was wrong.
Script works like this:
Array NeverDestroy - Add what should not be affected by the Powers. I'm sure there's things I missed. Static objects are ignored by Default.
BotA - Has a forcefield that causes anything in radius to be Destroyed.
BotB - Has a forcefield that causes anything in radius to Explode. I added in a Fake-explode option because I couldn't make a good real one at first. Less game breaking than real.
BotC - Can deflect everything launched at it. Undodgable projectiles need to be removed before impact though.
BotD - Need to manually hold walk if you want to shoot fireballs when melee attacking. That's why it doesn't work for bots.

I added in 3 ways to choose how to manually assign who gets the powers. And if it is just players with users, or all who are eligible. I'm not sure if it works as it should. Let's call it experimental.

Here are some clips to demonstrate

Code: Select all

/*
* author: Mighty Spirit the 2.
* description: Gives 4 players powers beyond.
* mapmodes: versus, custom, survival, campaign
*/

//========================< #Fantastic Four - settings >========================//
//============================<	Arrays that can be modified >=============================//
//The first Array of things that shouldn't be affected by the SuperPowers, Add things if you encounter problems.
private String[] Never_Remove_Array= {
	"HangingCrate00", "HangingCrate01", "SubwayTrain00", "Giblet00", "Giblet01", "Giblet02", "Giblet03", "Giblet04", "SuspendedScaffold00", "SteamshipWheel00", "BridgePlank00"
	, "BridgePlank01", "ShellGLauncher"

                                                  };

//Add the Guns/ProjectileItem in string format, for later use.
private String[] UnDogableProjectiles= {
	"FLAREGUN", "GRENADE_LAUNCHER", "BAZOOKA"

};

//============================<general>=============================//
private bool UsersOnly = false;		//If you only want Users to get SuperPowers
private const bool BotA = true;
private const bool BotB = true;
	//Choose which you want, but FakeExplosion is less game breaking.
	private bool ActualExplosion = true;
	private bool FakeExplosion = true;
private const bool Bot_C = true;
private const bool BotD = true;

//Chooses how the Superpowers are assigned. Only PickRandom guarantees that someone is chosen.
private bool PickRandom = true;	//In this mode -> If PLayer dies or leaves at start of round, the script will reasign the Superpower.
private bool byName = false;	//In this mode -> Worst option, last player found by name. Unlike above, won't reasign the Superpower.
private bool byArray = false;	//In this mode -> You assign the Player manually by index. If null, the script will not reasign the Superpower.
	private const int BotA_Array = 0;
	private const int BotB_Array = 0;
	private const int BotC_Array = 0;
	private const int BotD_Array = 0;


//==================================================================//
//=================< DO NOT TOUCH ANYTHING IN BELOW >===============//
//==============< IF YOU'RE NOT SURE WHAT YOU'RE DOING >============//
//==================================================================//
//This list will add the array above + other exceptions if they can be found. See OnStartup().
private List <String> Never_Remove = new List<String>();
//This list will add Weapons that are deflected so they don't fuck themselves up.
private List <IObject> AlreadyTakenCareOf = new List<IObject>();
private Random rnd = new Random();
//Create new Bot Modifiers
private PlayerModifiers BotA_mod;
private PlayerModifiers BotB_mod;
private PlayerModifiers BotC_mod; 
private PlayerModifiers BotD_mod;

//Here we add CustomID's to distribute to Players later.
private List <String> PickBots = new List<String>();

Events.ProjectileHitCallback m_projectileHitEvent = null;			//For BotC
Events.UpdateCallback FantasticFour = null;			//What will keep track of SuperPowers

//Store the Players found
private IPlayer Player_BotA;
private IPlayer Player_BotB;
private IPlayer Player_BotC;
private IPlayer Player_BotD;

//Stores the Area
private IObjectAreaTrigger BotA_Area;
private IObjectAreaTrigger BotB_Area;
private IObjectAreaTrigger BotC_Area;

public void OnStartup(){

	if(BotA){
		Vector2 SpawnA = GetRandomSpawn();
//		Game.CreatePlayer(SpawnA);
//		CreateArea(SpawnA, "DestroyObjects");
		BotA_Area = CreateArea(SpawnA, "DestroyObjects");
		PickBots.Add("BotA");
//		Player_BotA = SpawnPlayer(SpawnA,10,Game.GetActiveUsers()[0].GetProfile());
		
	}
	if(BotB){
		Vector2 SpawnB = GetRandomSpawn();
//		Game.CreatePlayer(SpawnB);
//		CreateArea(SpawnB, "Explode");
		BotB_Area = CreateArea(SpawnB, "Explode");
		PickBots.Add("BotB");
	}
	if(Bot_C){
		Vector2 SpawnC = GetRandomSpawn();
//		Game.CreatePlayer(SpawnC);
//		CreateArea(SpawnC, "DeflectProjectiles");
		BotC_Area = CreateArea(SpawnC, "DeflectProjectiles");

m_projectileHitEvent = Events.ProjectileHitCallback.Start(OnProjectileHit);
		PickBots.Add("BotC");
	}
	if(BotD){
//		Game.CreatePlayer(GetRandomSpawn());
	Events.UpdateCallback.Start(Fantastic_BotD, 350);
		PickBots.Add("BotD");
	}

Never_Remove.AddRange(Never_Remove_Array);

	//Define the SuperPower modifiers.
	BotA_mod = new PlayerModifiers();

	BotB_mod = new PlayerModifiers();
	BotB_mod.ExplosionDamageTakenModifier = 0f;

	BotC_mod = new PlayerModifiers();
	BotC_mod.ExplosionDamageTakenModifier = 0f ;
	BotC_mod.ProjectileCritChanceTakenModifier = 0f;
//	BotC_mod.FireDamageTakenModifier = 0f;
//	BotC_mod.ExplosionDamageTakenModifier = 0.6f; 
//	BotC_mod.ImpactDamageTakenModifier = f;
	BotC_mod.ProjectileDamageTakenModifier = 0f;

	BotD_mod = new PlayerModifiers();

	if(!UsersOnly){ Events.UpdateCallback.Start(Yay, 1000,1); }
	else { AssignPlayers(); }

}



public void SuperPowers(float ms){

//Here i add other exceptions to the List, it's faster then having to write each one down manually...
	foreach(IObject obj in Game.GetObjectsByArea(Game.GetCameraArea())){
		if(!Never_Remove.Contains(obj.Name)){
			if(obj.Name.Contains("Car") || obj.Name.Contains("Elevator") || obj.Name.Contains("Concrete") || obj.Name.Contains("Joint")
			|| obj.Name.Contains("Chandelier") || obj.Name.Contains("Lift") || obj.Name.Contains("Hook") ) {
				Never_Remove.Add(obj.Name); }
		}
	}

//Now we check our SuperPowered Players
	if(BotA){
		if(BotA_Area!=null && (Player_BotA.GetHealth()>=0.1f) ) { //Player_BotA!=null && 
			BotA_Area.SetWorldPosition(Player_BotA.GetWorldPosition() + new Vector2(-10,20));

			foreach(IObject obj in Game.GetObjectsByArea(BotA_Area.GetAABB())){
				if(obj!=Player_BotA) {
					if(obj is IPlayer) {
						IPlayer pleyr = (IPlayer)obj;
						if(Player_BotA.GetTeam()!=PlayerTeam.Independent && pleyr.GetTeam()==Player_BotA.GetTeam()){ return; }
						else{ pleyr.Destroy(); }
						}
					else{
				if(obj.GetBodyType()==BodyType.Dynamic && !Never_Remove.Contains(obj.Name)) {
					CFTXT(obj.GetWorldPosition()); obj.Destroy();	}
					}
				}
			}
		}
		else { if(Game.TotalElapsedGameTime>=5000 && Game.TotalElapsedGameTime<=5020 && PickRandom) { PickBots.Add("BotA"); } }
	}
	if(BotB){
		if(FakeExplosion && ActualExplosion){ ActualExplosion=false; }

		if(BotB_Area!=null && (Player_BotB.GetHealth()>=0.1f) ) { 		//Player_BotB!=null &&
			BotB_Area.SetWorldPosition(Player_BotB.GetWorldPosition() + new Vector2(-10,20));
			if(Player_BotB.GetModifiers().ExplosionDamageTakenModifier != 0) { Player_BotB.SetModifiers(BotB_mod); CFTXT(Player_BotB.GetWorldPosition()); }

			foreach(IObject obj in Game.GetObjectsByArea(BotB_Area.GetAABB())){
			if(obj!=Player_BotB) {
					if(obj is IPlayer ) {
					IPlayer pleyr = (IPlayer)obj;
					Vector2 Direction = Player_BotB.GetWorldPosition()-pleyr.GetWorldPosition();
						if(Player_BotB.GetTeam()!=PlayerTeam.Independent && pleyr.GetTeam()==Player_BotB.GetTeam()){ return; }
						else{ ExplodeObject(pleyr, Direction); }
					}
					else{
					if(obj.GetBodyType()==BodyType.Dynamic && !Never_Remove.Contains(obj.Name) && !(obj is IObjectWeaponItem) ) {
					Vector2 Direction = Player_BotB.GetWorldPosition()-obj.GetWorldPosition();
					ExplodeObject(obj, Direction); }
					}
			}
			}
		}
		else { if(Game.TotalElapsedGameTime>=5000 && Game.TotalElapsedGameTime<=5020 && PickRandom) { PickBots.Add("BotB"); } }
	}
//MSG("This Works");
	if(Bot_C){
		if(BotC_Area!=null && (Player_BotC.GetHealth()>=0.1f) ) {		//Player_BotC!=null && 
			BotC_Area.SetWorldPosition(Player_BotC.GetWorldPosition() + new Vector2(-10,20));
			if(Player_BotC.GetModifiers().ProjectileDamageTakenModifier != 0) { Player_BotC.SetModifiers(BotC_mod); CFTXT(Player_BotC.GetWorldPosition()); }
//			if(Player_BotC.IsBurning) Player_BotC.ClearFire();

		//This removes all Undodgable Projectiles when they enter BotC_Area. And creates new duplicates for reflect effect.
		foreach(IProjectile prj in Game.GetProjectiles()){
			if(BotC_Area.GetAABB().Contains(prj.Position) && UnDogableProjectiles.Contains(prj.ProjectileItem.ToString())){
				//prj.Velocity= prj.Direction*100f;
				Deflect(prj.ProjectileItem, prj.Position + new Vector2(2,2)*prj.Direction*-8, prj.Direction*-1f );
				prj.FlagForRemoval();
			}
		}

		foreach(IObject obj in Game.GetObjectsByArea(BotC_Area.GetAABB())){
			//This removes all Undodgable Weapons that players have when they enter BotC_Area. This is to prevent Bazooka softlocking.
			if(obj is IPlayer && obj!=Player_BotC){
			IPlayer ply = (IPlayer)obj;
				if(ply.CurrentWeaponDrawn==WeaponItemType.Rifle){
					if(UnDogableProjectiles.Contains(ply.CurrentPrimaryWeapon.WeaponItem.ToString()) )
					ply.RemoveWeaponItemType(WeaponItemType.Rifle);
				}
				if(ply.CurrentWeaponDrawn==WeaponItemType.Handgun){
					if(UnDogableProjectiles.Contains(ply.CurrentSecondaryWeapon.WeaponItem.ToString()) )
					ply.RemoveWeaponItemType(WeaponItemType.Handgun);
				}
			}
			//This deflects all Missiles that enter BotC_Area.
			if(obj.IsMissile && !AlreadyTakenCareOf.Contains(obj)) {
				obj.SetLinearVelocity(obj.GetLinearVelocity()*-1); AlreadyTakenCareOf.Add(obj);
			//Alternative method, obsolete
			//	Game.CreateObject(obj.Name, obj.GetWorldPosition()+new Vector2(4,4), obj.GetAngle()*-1f, obj.GetLinearVelocity()*-1, obj.GetAngularVelocity()*-1 );
			//	obj.Remove();
			}
		}
	}
	else { if(Game.TotalElapsedGameTime>=5000 && Game.TotalElapsedGameTime<=5020 && PickRandom) { PickBots.Add("BotC"); } }
	}

	//Loops list to remove missile items when outside of BotC_Area.
	for (int i = AlreadyTakenCareOf.Count - 1; i >= 0; i--){
		IObject Missile = AlreadyTakenCareOf[i];
 		if(!Missile.IsMissile) {
			AlreadyTakenCareOf.Remove(Missile); }
	}

if(Game.TotalElapsedGameTime>=5000 && Game.TotalElapsedGameTime<=5020 && PickRandom) { AssignPlayers(); }

}

public void Yay(float ms){

AssignPlayers();
}

public void OnProjectileHit(IProjectile projectile, ProjectileHitArgs args) {
	if(args.IsPlayer) { //Game.GetPlayer(args.HitObjectID).Remove(); }
		IPlayer ply = Game.GetPlayer(args.HitObjectID);
//		IProjectile prj = (IProjectile)projectile.InstanceID;

IProjectile prj = Game.GetProjectile(projectile.InstanceID);
			if(ply==Player_BotC){
		Deflect(prj.ProjectileItem, prj.Position + new Vector2(2,2)*prj.Direction*-8, prj.Direction*-1f );


prj.FlagForRemoval(); }
				}
}

public void Fantastic_BotD(float ms){
	if(Player_BotD!=null && Player_BotD.GetHealth()>=0.1f){
		Vector2 Shoot = Player_BotD.GetWorldPosition();
		if(Player_BotD.IsMeleeAttacking && Player_BotD.IsWalking){
		int FD = Player_BotD.FacingDirection;
			//Game.SpawnProjectile(ProjectileItem.FLAREGUN, Player_BotD.GetWorldPosition()+ new Vector2(Player_BotD.FacingDirection*10,10), new Vector2(Player_BotD.FacingDirection*1,0.1f) );
			FireBall(Shoot + new Vector2(FD*10,12), new Vector2(FD*1,0.1f));
			FireBall(Shoot + new Vector2(FD*26,10), new Vector2(FD*1,0.2f));
			FireBall(Shoot + new Vector2(FD*18,7), new Vector2(FD*1,0f));
		}
	}
	else { if(Game.TotalElapsedGameTime>=5000 && Game.TotalElapsedGameTime<=5300 && PickRandom) { PickBots.Add("BotD"); AssignPlayers(); } } 
}


public void AssignPlayers(){

	//Makes sure only one is on at times.
	if(byArray){ PickRandom=false; byName=false; }
	if(byName) { PickRandom=false; }


if(PickRandom){
	List <IPlayer> Players = new List<IPlayer>();

	foreach(IPlayer ply in Game.GetPlayers()){
		if(!ply.CustomID.Contains("Bot")){
			if(UsersOnly) { if(ply.GetUser()!=null){ Players.Add(ply); } }
			else { Players.Add(ply); }
		}
	}

	if(Players.Count==0 || PickBots.Count==0) {
//		MSG("Succesfully assigned all"); 
if(FantasticFour==null)	FantasticFour = Events.UpdateCallback.Start(SuperPowers, 0); return; }

	IPlayer rnd_p = Players[rnd.Next(Players.Count)];
	String Botlabel = PickBots[rnd.Next(PickBots.Count)];
		if(Botlabel=="BotA"){
			Transform(rnd_p.UniqueID, BotA_mod, "BotA");
			Player_BotA = rnd_p;
		}
		if(Botlabel=="BotB"){
			Transform(rnd_p.UniqueID, BotB_mod, "BotB");
			Player_BotB = rnd_p;
		}
		if(Botlabel=="BotC"){
			Transform(rnd_p.UniqueID, BotC_mod, "BotC");
			Player_BotC = rnd_p;
		}
		if(Botlabel=="BotD"){
			if(rnd_p.IsUser){
				Transform(rnd_p.UniqueID, BotD_mod, "BotD");
				Player_BotD = rnd_p;
			}
			else { if(PickBots.Count==1) { UsersOnly=true; AssignPlayers(); } }
		}
	PickBots.Remove(Botlabel); //MSG("Run again");
	AssignPlayers();
	}

if(byName){
	foreach(IPlayer ply in Game.GetPlayers()){
		if(UsersOnly) { if(ply.GetUser()!=null){
				if(BotA){
					if(ply.Name.Contains("BotA") )
					{ Transform(ply.UniqueID, BotA_mod, "BotA"); Player_BotA = ply; }
				}
				if(BotB){
					if(ply.Name.Contains("BotB") )
					{ Transform(ply.UniqueID, BotB_mod, "BotB"); Player_BotB = ply; }
				}
				if(Bot_C){
					if(ply.Name.Contains("BotC") )
					{ Transform(ply.UniqueID, BotC_mod, "BotC"); Player_BotC = ply; }
				}
				if(BotD){
					if(ply.Name.Contains("BotD") )
					{ Transform(ply.UniqueID, BotD_mod, "BotD"); Player_BotD = ply; }
				}
			}
		}
		else {
			if(BotA){
				if(ply.Name.Contains("BotA") )
				{ Transform(ply.UniqueID, BotA_mod, "BotA"); Player_BotA = ply; }
			}
			if(BotB){
				if(ply.Name.Contains("BotB") )
				{ Transform(ply.UniqueID, BotB_mod, "BotB"); Player_BotB = ply; }
			}
			if(Bot_C){
				if(ply.Name.Contains("BotC") )
				{ Transform(ply.UniqueID, BotC_mod, "BotC"); Player_BotC = ply; }
			}
			if(BotD){
				if(ply.Name.Contains("BotD") )
				{ Transform(ply.UniqueID, BotD_mod, "BotD"); Player_BotD = ply; }
			}
		}
		}
	}

if(byArray){
	if(UsersOnly){
		if(BotA && GetNum_U(BotA_Array) && NotNull(BotA_Array)) { Player_BotA = User_Player(BotA_Array); Transform(Player_BotA.UniqueID, BotA_mod, "BotA"); }
		if(BotB && GetNum_U(BotB_Array) && NotNull(BotB_Array)) { Player_BotB = User_Player(BotB_Array); Transform(Player_BotB.UniqueID, BotB_mod, "BotB"); }
		if(Bot_C && GetNum_U(BotC_Array) && NotNull(BotC_Array)) { Player_BotC = User_Player(BotC_Array); Transform(Player_BotC.UniqueID, BotC_mod, "BotC"); }
		if(BotD && GetNum_U(BotD_Array) && NotNull(BotD_Array)) { Player_BotD = User_Player(BotD_Array); Transform(Player_BotD.UniqueID, BotD_mod, "BotD"); } }
	else {
		if(BotA && GetNum(BotA_Array) ) { Player_BotA = Game.GetPlayers()[BotA_Array]; Transform(Player_BotA.UniqueID, BotA_mod, "BotA"); }
		if(BotB && GetNum(BotB_Array) ) { Player_BotB = Game.GetPlayers()[BotB_Array]; Transform(Player_BotB.UniqueID, BotB_mod, "BotB"); }
		if(Bot_C && GetNum(BotC_Array) ) { Player_BotC = Game.GetPlayers()[BotC_Array]; Transform(Player_BotC.UniqueID, BotC_mod, "BotC"); }
		if(BotD && GetNum(BotD_Array) ) { Player_BotD = Game.GetPlayers()[BotD_Array]; Transform(Player_BotD.UniqueID, BotD_mod, "BotD"); }
	}
	}

//MSG(Player_BotA.Name+ "   ID ="+Player_BotA.UniqueID);

if(FantasticFour==null)	FantasticFour = Events.UpdateCallback.Start(SuperPowers, 0);
}

public void Slow(TriggerArgs args){ Game.RunCommand("/Settime 0,1"); }
	// =====< helpers >===== //
public void FireBall(Vector2 pos, Vector2 angle) { Game.SpawnProjectile(ProjectileItem.FLAREGUN, pos, angle); }
public void Deflect(ProjectileItem Shoot, Vector2 pos, Vector2 angle) { Game.SpawnProjectile(Shoot, pos, angle); }
public void MSG(string text) { Game.RunCommand("/MSG " + text); }
public void PE(string txt, Vector2 pos, string t) { Game.PlayEffect(txt, pos, t); }
public void PS(String txt,Vector2 pos, float noice) { Game.PlaySound(txt, pos, noice); }
public void CFTXT(Vector2 pos) { Game.PlayEffect("CFTXT", pos, "Bye!"); }
public void EXP(Vector2 pos) { Game.TriggerExplosion(pos); }

public Vector2 GetRandomSpawn(){
	int i = rnd.Next(Game.GetObjectsByName("SpawnPlayer").Length);
	if(i==0) return new Vector2(0,0);
	else
	return ((IObject)Game.GetObjectsByName("SpawnPlayer")[i]).GetWorldPosition();
}

public bool GetNum(int Bot_Array) {
if(Bot_Array<Game.GetPlayers().Length) return true;
return false; }

public bool GetNum_U(int User_Array) {
if(User_Array<Game.GetActiveUsers().Length) return true;
return false; }

public bool NotNull(int User_Array) {
if(Game.GetActiveUsers()[User_Array].GetPlayer()!=null) return true;
return false; }

public void Transform(int rnd_p, PlayerModifiers mod, String C_ID) {  	//IProfile prof
IPlayer ChosenGod = Game.GetPlayer(rnd_p);
ChosenGod.SetModifiers(mod);
ChosenGod.CustomID+=C_ID;

/*
IProfile px_prof = new IProfile();//px.GetProfile();
px_prof.Name = px.Name+" -Gay"; MSG(px_prof.Name);
px_prof.Skin = new IProfileClothingItem("Zombie", " ");
ChosenGod.SetProfile(px_prof); //px_prof.Name+PickBots[b];
*/

}


public IPlayer User_Player(int User_Array) {
IPlayer EndPlayer = Game.GetActiveUsers()[User_Array].GetPlayer(); 
return EndPlayer;
}

private IObjectAreaTrigger CreateArea(Vector2 pos, string id){
IObjectAreaTrigger SuperPowersArea = (IObjectAreaTrigger)Game.CreateObject("AreaTrigger");
SuperPowersArea.SetSizeFactor(new Point((int)3 ,(int)3 ));
SuperPowersArea.SetWorldPosition(pos);
SuperPowersArea.CustomID = id;
SuperPowersArea.Trigger();
return SuperPowersArea;
}

private void ExplodeObject(IObject obj, Vector2 Direction){

if(FakeExplosion){

if(obj is IPlayer) {
IPlayer C = (IPlayer)obj;
if(!C.IsFalling && !C.IsDead){
C.SetInputEnabled(false);
C.AddCommand(new PlayerCommand(PlayerCommandType.Fall));
//Fail-safe in case player gets stuck without bot.
 Events.UpdateCallback.Start((float e) => {
C.SetInputEnabled(true); //MSG("success");
    }, 1000, 1); // after 1second, run code once
}

C.ClearFire();
}

//					CFTXT(obj.GetWorldPosition());
					PE("EXP", obj.GetWorldPosition(), "");
					PS("GLauncher", obj.GetWorldPosition(), 1f);

					obj.SetHealth(obj.GetHealth()-2);
					obj.SetLinearVelocity(Direction*-0.3f);
					obj.SetWorldPosition(obj.GetWorldPosition() + new Vector2(0,3));

					}
					if(ActualExplosion){
					CFTXT(obj.GetWorldPosition());
					obj.SetWorldPosition(new Vector2(obj.GetWorldPosition().X+Direction.X*-2,obj.GetWorldPosition().Y+10) );
					EXP(obj.GetWorldPosition());
					}

}
Survival - Expansion
Back when Survival was brand new and shipped with Beta 1.0.0. I really enjoyed it. But there was one problem. You could only play 4 players! This was bad because when you had a full server more than half would leave. No one wants to stick around and wait 10 min without playing… This always annoyed me, and hence why most servers always choose to skip Survival whenever it was selected. But no more.
This script is supposed to get all the players who aren't spawned and spawns them together with a selected start health and Starting weapons. This script caused me problems because I wasn't aware that running "Game.RunCommand("/give " x wpn)" where x=>4 doesn't work.
It also includes a bonus special mode "Zombie Exterminators" which makes Double Barrelled Shotgun OP. Reach wave 100 and beyond easily.
Short clip - wave 10

Code: Select all

/*
* author: Mighty Spirit The 2.
* description: Finally all 8 Players can join in the survival Fight! Includes Zombie Exterminators (optional)
* mapmodes: survival
*/

//Here you write what weapons each newly spawned player will start with. Use MapEditor Tile-Names!
private String[] StartingWeapons= {
	 "WpnKatana", "WpnSawedOff" //"WpnMagnum",
                                                  };

//============================<general>=============================//
private const bool SetAverageHealth = false;		//Assign the average of survivors health to each new Player
private const bool ZombieExterminators = true;		//Ultra-Shotgun + Increased Damage
private const bool AlliesDamageReduce = true;		//So you don't instakill your own teammates w. Friendly-Fire
Random rnd = new Random();
private PlayerModifiers Dmod;


private int Timer = 0;
private const bool DebugMode = false;		//Save me lots of time...

public void OnStartup(){
if(Game.GetMapType()!=MapType.Survival){ MSG("#SurvivalExpansion -> Not a Survival map, Script shutting down"); return; }

	if(DebugMode){
		foreach(IUser u in Game.GetActiveUsers()) {
			if(u.GetPlayer()!=null)
				u.GetPlayer().Remove();
		}
	}
	else { Spawn(); }
if(ZombieExterminators){
	Events.UpdateCallback.Start(refil, 0);
////This is where the Modifiers are defined
	Dmod = new PlayerModifiers();
	Dmod.ProjectileCritChanceDealtModifier = 100;
	Dmod.ProjectileDamageDealtModifier = 100;
	}
}

public void Spawn(){
	foreach(IUser u in Game.GetActiveUsers()) {
		if(u.GetPlayer()==null){
			//Read info on how this works.
			SpawnPlayers(GetRandomSpawn(), 80f, u.GetProfile(), u, true);
		}
	}
}

public void refil(float ms){
if(DebugMode){
if(Timer<1000) Timer++;
if(Timer==100) Spawn();
}
	foreach (IPlayer Exterminator in Game.GetPlayers()) {
		if(Exterminator.GetTeam()==PlayerTeam.Team1) {
			if(Exterminator.CurrentWeaponDrawn==WeaponItemType.Rifle && Exterminator.CurrentPrimaryWeapon.WeaponItem==WeaponItem.SAWED_OFF){
				if(Exterminator.GetModifiers().ProjectileDamageDealtModifier !=100)  { Exterminator.SetModifiers(Dmod);  Game.PlayEffect("CFTXT", Exterminator.GetWorldPosition(), "Mod!"); }
				if(Exterminator.CurrentPrimaryWeapon.CurrentAmmo==0) { Exterminator.GiveWeaponItem(Exterminator.CurrentPrimaryWeapon.WeaponItem); }
				}
			if( (Exterminator.CurrentWeaponDrawn==WeaponItemType.Rifle && Exterminator.CurrentPrimaryWeapon.WeaponItem!=WeaponItem.SAWED_OFF) || Exterminator.CurrentWeaponDrawn!=WeaponItemType.Rifle){
			if(Exterminator.GetModifiers().ProjectileDamageDealtModifier !=1) { Exterminator.ClearModifiers(); Game.PlayEffect("CFTXT", Exterminator.GetWorldPosition(), "NoMod!"); }
			}
			if(AlliesDamageReduce) {
				if(Exterminator.GetModifiers().ProjectileDamageTakenModifier !=0.01f) Exterminator.SetModifiers(new PlayerModifiers { ProjectileDamageTakenModifier = 0.01f });
			}
		}
	}
}

// =====< helpers >===== //

public void MSG(string text) { Game.RunCommand("/MSG " + text); }

public void SpawnPlayers(Vector2 pos, float health, IProfile prof, IUser u, Boolean GiveWpns){
	IPlayer BackUPTeam = Game.CreatePlayer(pos);
	if(SetAverageHealth){
		float AVRG = 0;
		int Survivors = 0;
		foreach(IUser use in Game.GetActiveUsers()) {
			if(use.GetPlayer()!=null){ AVRG+=use.GetPlayer().GetHealth(); Survivors++; }
		}
		if(Survivors>0)
		BackUPTeam.SetHealth(AVRG/Survivors); }
	else { BackUPTeam.SetHealth(health); }
	BackUPTeam.SetProfile(prof);
	if(u.IsBot){ BackUPTeam.SetBotBehavior(new BotBehavior(true) { PredefinedAI = PredefinedAIType.BotB }); BackUPTeam.SetBotName("BackUPTeam "+ u.Name); }
	else { BackUPTeam.SetUser(u); }
	BackUPTeam.SetTeam(PlayerTeam.Team1);

	if(GiveWpns){

//For some reason, on Survival running command "/give x" where x=>4 won't work.... So you can't give wpns to those players.
/* I tried it 3 ways below bfr realising this.
	//What i tried first, was pretty cool i think.
	int p_ArrayIndex = 0;
		for (int i = 0; i < Game.GetPlayers().Length; i ++){
		IPlayer pleyr = Game.GetPlayers()[i];
		if(BackUPTeam==pleyr) p_ArrayIndex=i;
	}
	//This one below actually works, but all wpns where spawned at player 0.
	foreach(IPlayer Ally in Game.GetPlayers()) {
	if(BackUPTeam==Ally) p_ArrayIndex=Array.IndexOf(Game.GetPlayers(), (IPlayer)(Ally) );
	//When i found out you could run IndexOf for Arrays.
	p_ArrayIndex=Array.IndexOf(Game.GetPlayers(), (IPlayer)(BackUPTeam) ); MSG(string.Format("/ArrayIndex {0} ", p_ArrayIndex) );

	foreach(String wpns in StartingWeapons){ Game.RunCommand(string.Format("/give {0} {1}", p_ArrayIndex ,wpns) ); }
*/

		//In the end i decided to just spawn wpns at their feet. Bcs then i can still use String to spawn.
		foreach(String wpns in StartingWeapons){
			IObject Wpn = Game.CreateObject(wpns, BackUPTeam.GetWorldPosition(), 0f);
			if(Wpn.Name=="error") Wpn.Remove();
		}
	}
}

public Vector2 GetRandomSpawn(){
	int i = rnd.Next(Game.GetObjectsByName("SpawnPlayer").Length);
	if(i==0) return new Vector2(0,0);
	else
	return ((IObject)Game.GetObjectsByName("SpawnPlayer")[i]).GetWorldPosition();
}
1 x
🎶I will tell your story if you die
I will tell your story and keep you alive the best i can
...
But I've always had the feeling we would die young
Some die young
🎵
https://i.imgur.com/D479VLi.png

Post Reply