Author Topic: Team:getColor() patch  (Read 1646 times)

0 Members and 1 Guest are viewing this topic.

Offline m!m

  • 211
Team:getColor() patch
I wrote a team:getColor() function to get the IFF color of a team and I'd like to see it committed to trunk.
Could someone with who knows the scripting system review the new code and maybe commit it?
I tested the patch and it works without any warnings/errors on Windows.
Patch is here against revision 6607:
Code: [Select]
Index: code/parse/lua.cpp
===================================================================
--- code/parse/lua.cpp (revision 6607)
+++ code/parse/lua.cpp (working copy)
@@ -2832,6 +2832,24 @@
  return ade_set_args(L, "s", Iff_info[tdx].iff_name);
 }
 
+ADE_FUNC(getColor, l_Team, NULL, "Gets the IFF color of the specified Team", "number, number, number", "grb color for the specified team or nil if invalid") {
+ int idx;
+ int r,g,b;
+ if(!ade_get_args(L, "o", l_Team.Get(&idx)))
+ return ade_set_error(L, "s", "");
+
+ if(idx < 0 || idx >= Num_iffs)
+ return ADE_RETURN_NIL;
+
+ color* col = iff_get_color_by_team(idx, 0, 0);
+
+ r = col->red;
+ g = col->green;
+ b = col->blue;
+
+ return ade_set_args(L, "iii", r, g, b);
+}
+
 ADE_FUNC(isValid, l_Team, NULL, "Detects whether handle is valid", "boolean", "true if valid, false if handle is invalid, nil if a syntax/type error occurs")
 {
  int idx;

Regards,
m!m

 

Offline The E

  • He's Ebeneezer Goode
  • 213
  • Nothing personal, just tech support.
    • Steam
    • Twitter
Re: Team:getColor() patch
Checked and committed in revision 6610.

Note that I altered it so that it always returns nil in case of failure; your version returned an empty string if it couldn't get a valid team handle.
If I'm just aching this can't go on
I came from chasing dreams to feel alone
There must be changes, miss to feel strong
I really need lifе to touch me
--Evergrey, Where August Mourns

 

Offline m!m

  • 211
Re: Team:getColor() patch
Thank you!