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] Players not changing colors upon team switch

Discussion in 'Modding Help' started by Frikman, Aug 31, 2016.

  1. Frikman

    Frikman Bison Rider

    Messages:
    162
    Hi, for the past few days I've been battling with the zombie rules made by Eanmig and I've been trying to add another team for zombie players. The thing is, it's not working at all. After comparing the rules to the ones used on CTF, I've noticed something odd. On the zombie_Rules, on the line 527 the function AddPlayer goes as this:
    Code:
       
    void AddPlayer(CPlayer@ player, u8 team = 0, string default_config = "")
        {
             CTFPlayerInfo p(player.getUsername(), 0, "builder" );
            players.push_back(p);
            ChangeTeamPlayerCount(p.team, 1);
            warn("sync");
            getRules().Sync("gold_structures",true);
        }
    The 0 will always force players to spawn on the blue team, no matter if they switch to red. Now, if I try to change the rules and make them look more like CTF by doing this:
    Code:
    team = player.getTeamNum();
    CTFPlayerInfo p(player.getUsername(), team, "builder" );
    Players never spawn and the console prints "PLAYER TEAM NOT SET CORRECTLY!". I honestly have no clue why it isn't working, because if I change the 0 to any other number it'll work, forcing players to spawn on said team all the time. Does anyone have a clue?

    (Here's a link to the full mod, if needed. https://forum.thd.vg/resources/zombie-fortress-plus.433/)

    EDIT: I noticed that zombie_Rules are really similar to the rules from Sandbox.
     

    Attached Files:

    Last edited: Sep 1, 2016
  2. Geti

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

    Messages:
    3,730
    Player teams aren't forced to anything when they join unless you have a script doing the forcing. Set their team to something on join and you should be fine.
     
  3. Frikman

    Frikman Bison Rider

    Messages:
    162
    I thought it had something to do with players joining. Now, where do I set that? I tried using this
    Code:
    void onNewPlayerJoin( CPlayer@ player )
    {
        player.server_setTeamNum(0);
    }
    But it does nothing, probably because the function has the wrong name.
     
  4. makmoud98

    makmoud98 You are already DEAD Forum Moderator Staff Alumni Tester

    Messages:
    586
    there could be another script that is changing it to something else after this script has ran
     
  5. Frikman

    Frikman Bison Rider

    Messages:
    162
    This is really confusing. I checked the game mode file and I noticed that JoinCoreHooks was there. I copied it and edited it to look like my previous post (onnewplayer join, server set team 0, etc etc) but now I'm stuck on where I was at the beggining: team switch doesn't work, it always gets me on the blue team. I'm totally lost on what's the problem now
    [​IMG]

    EDIT: Trying to switch while the game is running on a server gets even weirder, it'll switch me really fast to the team 2 and then back to team 1.
    [​IMG]
     

    Attached Files:

    Last edited: Sep 2, 2016
  6. makmoud98

    makmoud98 You are already DEAD Forum Moderator Staff Alumni Tester

    Messages:
    586
    that is because rules core and respawn system are in charge of the teams, so you cannot simply do server_setTeamNum, you need change some code first.
    The reason whenever you try to change it and it changes back is because on line 170 it checks if the player is on the wrong team and reverts it back to what their playerinfo class's team number is.
    [​IMG]
    So you can try to remove that little bit of code and try to do it. This is a hacky solution, but rulescore is a mess in itself
     
  7. Frikman

    Frikman Bison Rider

    Messages:
    162
    I tried doing that before and it didn't work, but after checking RespawnSystem I noticed this little bit of code
    [​IMG]
    I disabled it, and now I can switch teams. With this, a new problem has just emerged: Team2 color is not loaded properly.
    [​IMG]
    If I restart the map I'll get the correct colors, but that also means I can't switch back to blue. Once you start the game with a color, you keep it for the rest of the game no matter what team you're in. This means, if you're on the blue team but your pallete shows you're red, you'll be able to hit blue players. It's really buggy, any idea on how to fix it?
    [​IMG]
     

    Attached Files:

  8. you don't need that team = player.getTeamNum(); line, since you already have team passed as function argument
     
  9. Frikman

    Frikman Bison Rider

    Messages:
    162
    I changed it to this. Thought it would probably solve the color issue, but it doesn't.
    [​IMG]
    If I left u8 team = 0 as a function argument and removed the rest of the team thing, but it didn't solve the issue either. I'm stuck
     
  10. makmoud98

    makmoud98 You are already DEAD Forum Moderator Staff Alumni Tester

    Messages:
    586
    you are better off using the scripted scoreboard like in tdm and ctf and you can customize how you want the scoreboard to behave
     
  11. Frikman

    Frikman Bison Rider

    Messages:
    162
    I don't think the problem lies within the scoreboard (and if it does, hell isn't it contra-intuitive). The problem now is that team switching works partially, requiring a map restart to work as intended. Since english isn't my native language I might be explaining something wrongly, so I recorded a quick video to explain it.

    My guess is that the game is not updating team changes, or that it's switching me the same way using !team # does. The changes on zombie_Rules were made from the line 170 onwards, and the changes on RespawnSystem were done from line 37 (replaced both instances of player.server_setTeamNum(p_info.team);). Still, I'm running out of hacky ideas to solve this ::(:
    EDIT: The video's not private anymore whoops
     

    Attached Files:

    Last edited: Sep 3, 2016
  12. blackjoker77777

    blackjoker77777 Haxor Tester
    1. Zen Laboratories

    Messages:
    441
    Never loose hope, never.
    I don't think it's related to the scoreboard either, even though I agree with makmoud, the scripted one is definitely better and could be considered as "more useful" for the future development of your mod.
    I think you got it the opposite way, apparently (based on the video) swapping your team changes your player team (the one stated on the scoreboard) and keeps your old blob team without any change until you restart the map.
    using the !team <int> changes your blob team without affecting your actual player team, so in a sandbox server and despite the fact all the players seem to be on the same blue team on the scoreboard, they could pick custom teams for their blobs.
    So here's what I got after having a short look on the custom "RespawnSystem.as" :
    upload_2016-9-3_22-35-39.png
    That part is confusing me, for real, I mean why are you re-assigning the player's team to it's old value?
    You're simply setting the same old value, over and over again (maybe it was a typo and you actually wanted to do player.getBlob().server_setTeamNum(lmao); ?).
    Also it might be worth mentioning that you're using the same functions in both "RespawnSystem.as" and "zombies_Rules.as" and overriding functions is never a good idea, I'm talking about those:
    (I might have missed some tho)
    So probably you shouldn't use both of these scripts in the same mod, just to avoid any odd behavior.
    Now about investigating the issue of team assignment, the player team is assigned properly but the blob's one isn't, so maybe the p_info.team was -somehow- messed up. My idea is forcing the blob team to be the same as the player's every time the player spawns/re-spawns.
    In the "zombies_Rules.as" try doing this:
    -Remove the highlighted area
    upload_2016-9-3_23-6-58.png
    Because those conditions aren't that important (unless if you really need the warning about player team number?)
    But keep the "lmao" variable, we can use it later. :P
    -Try forcing the blob team
    upload_2016-9-3_23-20-47.png
    You can still change the player.getTeamNum() with lmao if you didn't delete that variable, so it would look something like this:
    upload_2016-9-3_23-27-52.png
    Try that out, and hopefully it could solve your issue.
     
    Frikman likes this.
  13. Frikman

    Frikman Bison Rider

    Messages:
    162
    You absolute madman, it works! The only issue now is that the team menu itself doesn't change players (I have to do it via console or admin options), but I wanted to use TeamMenuJustSpectator anyway.
    What is this scripted scoreboard you guys talk about? Why is it better ._.?
     
  14. blackjoker77777

    blackjoker77777 Haxor Tester
    1. Zen Laboratories

    Messages:
    441
    I'm glad I could help. :)
    It's the new scoreboard used in CTF, you can have a look on how it works in "CTF_Interface.as" (starting from line 193, I guess).
    Using it you can create your own ways of score calculations, the way the color of player names is assigned (let's say give a pink color for admins? because why not!), how players are sorted and how their ranks are picked, the size of the scoreboard,...
    So it's up to you to use your creativity and create a "unique" scoreboard. :^)
     
  15. Frikman

    Frikman Bison Rider

    Messages:
    162
    I'll have a look on it. For now the main issues were solved and I can start working on zombie classes :y
     
    Geti and blackjoker77777 like this.