1. Hey Guest, is it this your first time on the forums?

    Visit the Beginner's Box

    Introduce yourself, read some of the ins and outs of the community, access to useful links and information.

    Dismiss Notice

[Solved] Setting a team to spawn at a specific blob

Discussion in 'Modding Help' started by Frikman, Sep 3, 2016.

  1. Frikman

    Frikman Bison Rider

    Messages:
    162
    Hi, I haven't got team swapping 100% functional yet but I'd like to know if there's a way to make a team spawn at a certain shop/blob while the other has a different way for spawning. What I have now makes both teams spawn at the edges of the map (like in sandbox)
    Code:
        Vec2f getSpawnLocation(PlayerInfo@ p_info)
        {
            CTFPlayerInfo@ c_info = cast<CTFPlayerInfo@>(p_info);
            if(c_info !is null)
            {
                CMap@ map = getMap();
                if(map !is null)
                {
                    CPlayer@ player = getPlayerByUsername(p_info.username);
                    u8 lemo = player.getTeamNum();
                    if (lemo == 0)
                    {
                        f32 x = XORRandom(2) == 0 ? 32.0f : map.tilemapwidth * map.tilesize - 32.0f;
                        return Vec2f(x, map.getLandYAtX(s32(x/map.tilesize))*map.tilesize - 16.0f);
                    }
                    else if (lemo == 1)
                    {
                        f32 x = XORRandom(2) == 0 ? 32.0f : map.tilemapwidth * map.tilesize - 32.0f;
                        return Vec2f(x, map.getLandYAtX(s32(x/map.tilesize))*map.tilesize - 16.0f);
                    }
                }
            }
    
            return Vec2f(0,0);
        }
    (I know, I'm terrible at naming things)
    But I'd like to know if it would be possible to check the player's team and then set one of them to spawn on the edges and the other on a workshop underground.
     
  2. Geti

    Geti Please avoid PMing me (poke a mod instead) THD Team Administrator Global Moderator

    Messages:
    3,730
    Obligatory "anything's possible"

    Spawning isn't some hardcoded thing - you decide how you create blobs and hook players up to them. There's absolutely no reason you can't make one team's spawn mechanics different.
     
  3. Frikman

    Frikman Bison Rider

    Messages:
    162
    [QUOTE="Geti, post: 385405, member: 60]"Obligatory "anything's possible"[/QUOTE]
    hej. Yeah my question was silly I guess.
    I've tried to copy and modify the spawning code from TDM and replace the instances of "tdm_spawn" with "zombieportal", but that made the red team spawn on the upper ledges of the map and fall to death. I'm still not sure on how to properly achieve this
     
  4. Geti

    Geti Please avoid PMing me (poke a mod instead) THD Team Administrator Global Moderator

    Messages:
    3,730
    Honestly this is the bad side of trying to mod from existing scripts.

    The reason I wrote the example "no rulescore" zombie code for @kaizokuroof is to show how simple rules behaviour can be. If you're trying to use some vanilla gamemode code as a base things get a lot more complicated cause there's a big pile of code that goes into solving all sorts of edge cases that come up.

    It sounds like for this you have very specific spawn case "spawn guys at this point, at this interval" - you could do that by just checking if it's time to try to spawn guys, iterating through all the players, and if they're dead, spawning new blobs for them somewhere. Something like:
    Code:
    //use this to respawn a single player
    void RespawnPlayer(CPlayer@ p)
    {
    	//detach from the current blob, if there is one
    	CBlob@ oldblob = p.getBlob();
    	if(oldblob !is null)
    	{
    		oldblob.server_SetPlayer(null);
    		//vanish if it's not dead (respawn from alive?)
    		if(!oldblob.hasTag("dead"))
    		{
    			oldblob.server_Die();
    		}
    	}
    
    	//decide which blob to spawn, where
    	string name = "";
    	Vec2f pos(0,0);
    	int team = p.getTeamNum();
    	if(team == 0)
    	{
    		name = "builder";
    		pos = /*get the blue team spawn pos*/;
    	}
    	else
    	{
    		name = "zombie";
    		pos = /*get red team spawn pos*/;
    	}
    	CBlob@ b = server_CreateBlob(name, team, pos);
    	b.server_SetPlayer(p);
    }
    
    //run this code whenever you want to respawn all dead players
    void DoRespawns()
    {
    	for(int i = 0; i < getPlayersCount(); i++)
    	{
    		CPlayer@ p = getPlayer(i);
    
    		//skip spectators and high team players (eg ones that just joined)
    		//you'll have to change this if you want more than 8 teams
    		if(p.getTeamNum() > 8) continue;
    
    		//missing a blob or blob is dead
    		if(p.getBlob() is null || p.getBlob().hasTag("dead"))
    		{
    			RespawnPlayer(p);
    		}
    	}
    }
    Note: this was just air-coded. It's not been tested but it's how I'd approach a simple respawn behaviour.

    You should write your own from this example, not copy-paste it. You won't learn anything from that.
     
  5. Frikman

    Frikman Bison Rider

    Messages:
    162
    When I tried using the ZombiesFramework I couldn't get many (and by many I mean none) things done. I guess I'll have to give a try to writing my own stuff eventually, I tried doing something really straightforward and just "set" the position of the player upon spawn
    Code:
        Vec2f getSpawnLocation(PlayerInfo@ p_info)
        {
            CTFPlayerInfo@ c_info = cast<CTFPlayerInfo@>(p_info);
            if(c_info !is null)
            {
                CMap@ map = getMap();
                if(map !is null)
                {
                    CPlayer@ player = getPlayerByUsername(p_info.username);
                    u8 lemo = player.getTeamNum();
                    if (lemo == 0) //survivors spawn point
                    {
                        f32 x = XORRandom(2) == 0 ? 32.0f : map.tilemapwidth * map.tilesize - 32.0f;
                        return Vec2f(x, map.getLandYAtX(s32(x/map.tilesize))*map.tilesize - 16.0f);
                    }
                    else if (lemo == 1) //undead spawn point
                    {
                        CBlob@[] portals;
                        getBlobsByName("ZombiePortal", @portals);
                        for (int n = 0; n < portals.length; n++)
                        if(portals[n] !is null) //check if we still have portals and spawn us there
                        {
                            return Vec2f(portals[n].getPosition());                   
                        }               
                        else //in case portals are destroyed
                        {
                            f32 x = XORRandom(2) == 0 ? 32.0f : map.tilemapwidth * map.tilesize - 32.0f;
                            return Vec2f(x, map.getLandYAtX(s32(x/map.tilesize))*map.tilesize - 16.0f);               
                        }               
                    }
                }
            }
            return Vec2f(0,0);
        }
    For now it's working, but it took me many hours to understand how to get it working :kappa:.

    EDIT: if all portals are destroyed/missing it'll spawn me on 0,0 (the top left edge of the map). Wew lad
    EDIT2: got it working by doing this
    Code:
        Vec2f getSpawnLocation(PlayerInfo@ p_info)
        {
            CTFPlayerInfo@ c_info = cast<CTFPlayerInfo@>(p_info);
            if(c_info !is null)
            {
                CMap@ map = getMap();
                if(map !is null)
                {
                    CPlayer@ player = getPlayerByUsername(p_info.username);
                    u8 lemo = player.getTeamNum();
                    if (lemo == 0) //survivors spawn point
                    {
                        CBlob@[] villagers;
                        getBlobsByName("villager", @villagers);
                        for (int n = 0; n < villagers.length; n++)
                        if(villagers[n] !is null) //check if we still have villagers and spawn us there
                        {
                            return Vec2f(villagers[n].getPosition());
                        }   
                    }
                    else if (lemo == 1) //undead spawn point
                    {
                        CBlob@[] portals;
                        getBlobsByName("ZombiePortal", @portals);
                        for (int n = 0; n < portals.length; n++)
                        if(portals[n] !is null) //check if we still have portals and spawn us there
                        {
                            ParticleZombieLightning(portals[n].getPosition());
                            return Vec2f(portals[n].getPosition());
                        }                                       
                    }
                }
            }
            CMap@ map = getMap();
            f32 x = XORRandom(2) == 0 ? 32.0f : map.tilemapwidth * map.tilesize - 32.0f;
            return Vec2f(x, map.getLandYAtX(s32(x/map.tilesize))*map.tilesize - 16.0f);    //in case portals/villagers are missing spawn at the edge
        }
     
    Last edited: Sep 7, 2016
    makmoud98 likes this.