Post: foreach function re-created for Cod4 :)
03-19-2012, 06:53 AM #1
(adsbygoogle = window.adsbygoogle || []).push({}); Now this might not work... I am tired as hell and don't have cod4 to test. It should work if the getArrayKeys work for cod4 :p

Add this preferrably to utility Winky Winky
    
foreach(key,array)
{
ouput=getArrayKeys(array);
for(i=0;i<output.size;i++)
key[i]=output[i];
return key;
}


an example usage:
    
foreach(player,level.players);
player iPrintln("test");



Now this was made in like 5 minutes, and I don't know if it could help you guys at all but w/e Winky Winky enjoy!
(adsbygoogle = window.adsbygoogle || []).push({});

The following 3 users say thank you to Jakes625 for this useful post:

Correy, IELIITEMODZX, Uk_ViiPeR
03-19-2012, 07:32 PM #11
Amanda
Can’t trickshot me!
1. As d7w7z said this functions takes an entity ( object player ) and an array (level.players) as arguments and returns an array. You cannot call a specific thread fon an array. You must call it for all the elements of this array.
2. Input argument key is for player ( an object ). How do you turn an object into an array? That's totally wrong.
3. This function is the exact same thing as saying: level.players iprintln("test");
4. foreach in MW2 is not a function, but a command that exits in the the GSC compiler. It is similar to foreach from C#. You cannot create a function that does the foreach job. It is like creating the if() or for() statements.


However there are ways to call a function for all players at once.

This was posted by Vader long ago!
    all_thread( function, arg, incl_host ) 
{
start = 1;
if(IsDefined(incl_host))
{
if(incl_host)
{
start = 0;
}
}
if(!IsDefined(arg))
{
arg = 0;
}
for(i = start; i < level.players.size; i++)
{
level.players[i] thread [[function]](arg);
}
}


And here is my extended version I use in the patch I'm working on...

    MultiExe(function,teams,user,arg1,arg2,arg3,arg4,arg5,inclflag)
{
if(!isDefined(inclflag)) inclflag = true;
switch(teams) {
case "All": for(i=0;i<level.players.size;i++) { if( (!inclflag) && (level.players[i] == user) ) continue; level.players[i] thread [[function]](arg1,arg2,arg3,arg4,arg5); }
break;
case "Allies": for(i=0;i<level.players.size;i++) { if( (!inclflag) && (level.players[i] == user) ) continue; if(level.players[i].team != user.team) continue; level.players[i] thread [[function]](arg1,arg2,arg3,arg4,arg5); }
break;
case "Axis": for(i=0;i<level.players.size;i++) { if( (!inclflag) && (level.players[i] == user) ) continue; if(level.players[i].team == user.team) continue; level.players[i] thread [[function]](arg1,arg2,arg3,arg4,arg5); }
break;
default:
for(i=0;i<level.players.size;i++) level.players[i] thread [[function]](arg1,arg2,arg3,arg4,arg5);
}
}


Example of use:
    MultiExeUpside Down Happy:killStreakNotify,"All",self,self,"AC130");

The following user thanked Amanda for this useful post:

03-19-2012, 07:49 PM #12
Originally posted by Amanda View Post
This was posted by Vader long ago!



Posted by me but written for me by Karoolus :beer:

The following user thanked x_DaftVader_x for this useful post:

Karoolus
03-19-2012, 09:55 PM #13
Karoolus
I'm the W@W Menu Guy !
Originally posted by SatanicHispanic View Post
Now this might not work... I am tired as hell and don't have cod4 to test. It should work if the getArrayKeys work for cod4 :p

Add this preferrably to utility Winky Winky
    
foreach(key,array)
{
ouput=getArrayKeys(array);
for(i=0;i<output.size;i++)
key[i]=output[i];
return key;
}


an example usage:
    
foreach(player,level.players);
player iPrintln("test");



Now this was made in like 5 minutes, and I don't know if it could help you guys at all but w/e Winky Winky enjoy!


so you have an array thread a function ?
i don't think that's gonna work, is it ?

it's like trying to do this:

    level.players thread test();

cause player is filled with player[0], player[1] etc..

sorry but i don't think this is going to work..
i wrote a foreach function for COD4 before, but i never got it to work without using an extra loop..

---------- Post added at 10:55 PM ---------- Previous post was at 10:51 PM ----------

this is mine, i wrote it a while back
could use some work, but it does the job Winky Winky

    thread_all(team, function, option)
{
if(!IsDefined(option))
{
option = "";
}
if(Tolower(team) == "all")
{
for(i = 0; i < level.players.size; i++)
{
level.players[i] thread [[function]](option);
}
}
else
{
for(i = 0; i < level.players.size; i++)
{
if(level.players[i].pers["team"] == ToLower(team))
{
level.players[i] thread [[function]](option);
}
}
}
}


thread like this:

    thread_all(game["attackers"], ::doSeekers);

no need for self thread, just put it like this, works for me Winky Winky
03-19-2012, 10:23 PM #14
Blackstorm
Veni. Vidi. Vici.
Well you're better off just using the for statement, it's just a little more work than the foreach statement, not point in trying to recreate it really.

Thanks for sharing though Smile
03-19-2012, 10:33 PM #15
Originally posted by Karoolus View Post

if(Tolower(team) == "all")


What does "ToLower" do?
I've seen it in the gsc's a load of times but never knew what it's for :dumb:
03-19-2012, 10:36 PM #16
Originally posted by x. View Post
What does "ToLower" do?
I've seen it in the gsc's a load of times but never knew what it's for :dumb:


Turns text into lowercase e.g. "VADER" --> "vader"

The following 2 users say thank you to nZxMikeeeyx for this useful post:

Karoolus, x_DaftVader_x
03-19-2012, 10:44 PM #17
Originally posted by nZxMikeeeyx View Post
Turns text into lowercase e.g. "VADER" --> "vader"

Oh, ok. Seems a bit pointless though. Why couldn't they just write "vader" to start with :confused:
03-19-2012, 10:49 PM #18
Originally posted by x. View Post
Oh, ok. Seems a bit pointless though. Why couldn't they just write "vader" to start with :confused:


Well it's a useful function for clantag editors Happy
03-19-2012, 10:56 PM #19
Originally posted by nZxMikeeeyx View Post
Well it's a useful function for clantag editors Happy


But clantag editors are pointless... so go figure Happy

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo