[Open Assets] Team Colors (For Some Variation)

This content may be freely modified and/or maintained by anyone.
Status
Not open for further replies.
This here is a script so you can change your colors in Team Match/CTF. Colors are restricted based on team, and some are not available at all.

Commands:

playercolor <color/help>: sets the color to use in Team Match and CTF.

player2color <color/help>: sets the color for player 2 to use in CTF and team match in splitscreen.

listcolor <red/blue/none/help>: lists the available colors for Red Team and Blue Team, as well as unavailable colors.

V1.0 - Initial Release

V2.0 - Shortened lines, added splitscreen support
 

Attachments

  • srb20563.jpg
    srb20563.jpg
    157.4 KB · Views: 617
  • srb20564.jpg
    srb20564.jpg
    157.1 KB · Views: 674
  • TeamColors.lua
    7.7 KB · Views: 565
Last edited:
This seems to work from what I could see by myself. I haven't tested it in a netgame but I can't see anything breaking with other players due to how it works.
Only minor issue I saw was colour not being kept between maps, but that's an issue that isn't really solvable due to how the code works in the game IIRC.
For advice on the code you have, I recommend using string.lower on your strings where you have checks for what they are, for example, this:
Code:
elseif SetColor == "red" or SetColor == "Red" or SetColor == "RED" or SetColor == "18"
could be turned into this:
Code:
elseif string.lower(SetColor) == "red" or SetColor == "18"
meaning that you don't need to repeat checks for different capitalisation, and any capitalisation can work. You can also just set SetColor be the string.lower output earlier as well. Also if you want to print multiple lines you can add \n to your print instead of doing multiple prints.

For a more personal note the idea behind it I can't really get behind because you need to be really easily able to see who is on the enemy team in those gamemodes. But the colours seem to be setup alright so that there isn't too much of an issue determining who is on what team.
 
Ok, quick question, although it's probably simpler than I think, but how would I make a command for changing player 2's color, and out of curiosity, how many people actually use this?
 
Ok, quick question, although it's probably simpler than I think, but how would I make a command for changing player 2's color, and out of curiosity, how many people actually use this?

When not playing online, you can guarantee that the client player is always players[0], and in the case of splitscreen, the second player is always players[1]. Thus you can set up a console command for changing Player 2's color by first checking for the global variable splitscreen (true when a 2-player game is active, false if 1P or a netgame), and then modifying the color of players[1]. I believe players[1] is also the bot player when playing as Sonic and Tails, so if you want to add support for that guy as well, check for not netgame instead.
 
You know how you use "for player in players.iterate" to access every player in the current game? That works by telling the game to iterate through every entry in the global table "players" and perform an action for each of them—each entry in "players" stores one set of player_t data. But you can also access individual entries of a table by specifying the index value of the entry that you want to access and/or modify, and the way that you do that is using index numbers such as players[0] to access the first player, players[1] to access the second, players[2] to access the third, and so on. So to change the second player's color in splitscreen mode, you would do it like this instead of with an iteration:

Code:
if splitscreen and players[1].mo
    players[1].mo.color = SKINCOLOR_BLUE
end
 
Alternatively, to add splitscreen player 2 support, you can use the exact same function (though you then might want to add a check for if the player exists, not sure), and just set the "flags" value of the command addition line to 2. Something like this:
Code:
local function teamcolor(player, SetColor)
    if string.lower(SetColor) == "help" or SetColor == none then
        [SIZE=1][I]-SNIP TO KEEP THIS POST SHORT-[/I][/SIZE]
    elseif string.lower(SetColor) == "zim" or SetColor == "22" then
        if player.ctfteam == 2 then
            player.mo.color = SKINCOLOR_ZIM
        end
    end
end

COM_AddCommand("playercolor", teamcolor)
COM_AddCommand("playercolor2", teamcolor, 2)

COM_AddCommand("listcolors", function(player, TeamRequest)
    if string.lower(TeamRequest) == "help" or TeamRequest == none then
        [SIZE=1][I]-SNIP TO KEEP THIS POST SHORT, AGAIN-[/I][/SIZE]
    end
end)
Mini-edit: See https://wiki.srb2.org/wiki/Lua/Functions#Console_library for slightly more information.
 
Last edited:
Alright, the script has been updated for splitscreen support. Use the command 'player2color <color/help>' to change player 2's color. It works the same as 'playercolor'.
 
Status
Not open for further replies.

Who is viewing this thread (Total: 1, Members: 0, Guests: 1)

Back
Top