This forum is locked and will eventually go offline. If you have feedback to share you can find us in our Discord channel "MythoLogic Interactive" https://discord.gg/nECKnbT7gk

Forum rules

Need Help with script

Here you can find answered ScriptAPI topics.
Forum rules
By using the forum you agree to the following rules.
Locked
User avatar
Billy
Superfighter
Superfighter
Posts: 285
Joined: Fri Apr 22, 2016 3:56 pm
Title: Owner of a failed Clan
SFD Account: Billy
SFD Alias: Billy
Started SFD: October 2015
Location: Austria
Gender:
Age: 24

Need Help with script

Post by Billy » Tue Apr 26, 2016 6:03 pm

can someone help we with dat code, it should set teamspawns and the projectile spawners should work

// 2 Teams system...

Random Rnd = new Random();
Dictionary<PlayerTeam, int> Teams = new Dictionary<PlayerTeam, int>(4);
PlayerTeam[] teams = {PlayerTeam.Team1, PlayerTeam.Team2, PlayerTeam.Team3, PlayerTeam.Team4};
public void OnStartup(){
	List<IPlayer> players = new List<IPlayer>();
	Teams.Add(PlayerTeam.Team1, 0);
	Teams.Add(PlayerTeam.Team2, 0);

	foreach(IObject spawn in Game.GetObjectsByName("SpawnPlayer")){
		AvailableSpawns.Add(spawn);
	}

	foreach(IPlayer ply in Game.GetPlayers()){
		players.Add(ply);
	}

	while(true){
		int rndIndex = Rnd.Next(players.Count);
		IPlayer ply = players[rndIndex];

		if(ply.GetTeam() == PlayerTeam.Independent){
			ply.SetTeam(TeamAvailable());
		}

		ply.SetWorldPosition(AvailableSpawn(ply.GetTeam()));
		players.Remove(players[rndIndex]);
		if(players.Count == 0)
			break;
	}
}

private PlayerTeam TeamAvailable(){
	PlayerTeam team = PlayerTeam.Independent;
	int less = Teams[teams[0]];
	for(int i = Teams.Count-1; i>=0; i--){
		if(Teams[teams] <= less){
			team = teams;
			less = Teams[teams];
			Game.WriteToConsole(Teams[teams].ToString());
		}
	}
	Teams[team] ++;
	return team;
}

List<IObject> AvailableSpawns = new List<IObject>();
public Vector2 AvailableSpawn(PlayerTeam team){
	string plyTeam = "";
	IObject spawn = null;
	switch(team){
		case PlayerTeam.Team1:
		plyTeam = "blue";
		break;
		case PlayerTeam.Team2:
		plyTeam = "red";
		break;
	}
	for(int i = AvailableSpawns.Count-1; i>=0; i--){
		if(AvailableSpawns.CustomId == plyTeam){
			spawn = AvailableSpawns;
			AvailableSpawns.Remove(AvailableSpawns);
			return spawn.GetWorldPosition();
		}
	}
	
	if(plyTeam == "" && AvailableSpawns.Count>0){
		spawn = AvailableSpawns[0];
		AvailableSpawns.Remove(AvailableSpawns[0]);
		return ((IObject)spawn).GetWorldPosition();
	}

	IObject[] usedSpawns = (IObject[])Game.GetObjectsByCustomId(plyTeam);
	return (usedSpawns[Rnd.Next(0, usedSpawns.Length)]).GetWorldPosition();
}







public void ActivateShooter(TriggerArgs args){
   IObject obj01 = Game.GetFirstObject("Object01") as IObject;
   IObject obj02 = Game.GetFirstObject("Object02") as IObject;

   if(obj02 != null){ // if object01 still exists
      Vector2 pos01 = obj01.GetWorldPosition();
      Vector2 pos02 = obj02.GetWorldPosition();

      Vector2 direction = pos02 - pos01;

      Game.SpawnProjectile(ProjectileItem.M60, pos01, direction);
   }
}




public void ActivateCannon(TriggerArgs args){
   IObject obj01 = Game.GetFirstObject("Object01B") as IObject;
   IObject obj02 = Game.GetFirstObject("Object02B") as IObject;

   if(obj02 != null){ // if object01 still exists
      Vector2 pos01 = obj01.GetWorldPosition();
      Vector2 pos02 = obj02.GetWorldPosition();

      Vector2 direction = pos02 - pos01;

      Game.SpawnProjectile(ProjectileItem.Grenadelauncher, pos01, direction);
   }
}


You will be mentioned in the credits

Added in 53 minutes 50 seconds:
it says the term for grenade launcher is not right does anyone knows the right one?
0 x
Join Delta Squad today, if you mail me now you will get this cool private rank for FREE, but thats not all, you will also get an imaginary Cookie, so better hurry up!
Yea, ehh, that was a big fail...

User avatar
TheOriginalCj
Moderator
Moderator
Posts: 177
Joined: Tue Mar 15, 2016 10:28 pm
Title: Lifetime Sentence to SF Wiki
SFD Alias: RedneckJed
Started SFD: PreAlpha 1.1.0
Location: USA
Gender:
Contact:

Post by TheOriginalCj » Tue Apr 26, 2016 6:09 pm

It's gotta be written as Grenade_Launcher.
1 x
Superfighters Wiki Founder
The Superfighters Wiki
Join the Wiki!
Danger Ross wrote: What are you doing here wiki-slave?! GET BACK TO WORK!

User avatar
ShutDownMan
Fighter
Fighter
Posts: 32
Joined: Sat Mar 19, 2016 7:17 pm
Title: Yeah, science!
SFD Alias: ShutDownMan, Devil Shut
Started SFD: 1.2.something
Location: Hu3, Brazil
Gender:
Age: 26
Contact:

Post by ShutDownMan » Wed Apr 27, 2016 11:40 pm

Check the API to see all the enums for that

it should be written like that.

Also, thanks for using my 2 teams script :3
2 x
~ShutDownMan

User avatar
Billy
Superfighter
Superfighter
Posts: 285
Joined: Fri Apr 22, 2016 3:56 pm
Title: Owner of a failed Clan
SFD Account: Billy
SFD Alias: Billy
Started SFD: October 2015
Location: Austria
Gender:
Age: 24

Post by Billy » Thu Apr 28, 2016 11:11 am

It was a pleashure or however you wite it
0 x
Join Delta Squad today, if you mail me now you will get this cool private rank for FREE, but thats not all, you will also get an imaginary Cookie, so better hurry up!
Yea, ehh, that was a big fail...

Locked