Hard Light Productions Forums

Modding, Mission Design, and Coding => The Scripting Workshop => Topic started by: m!m on October 15, 2010, 12:33:58 pm

Title: Team:getColor() patch
Post by: m!m on October 15, 2010, 12:33:58 pm
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
Title: Re: Team:getColor() patch
Post by: The E on October 15, 2010, 02:45:46 pm
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.
Title: Re: Team:getColor() patch
Post by: m!m on October 16, 2010, 06:30:16 am
Thank you!