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, 11:00 PM #20
Karoolus
I'm the W@W Menu Guy !
Originally posted by x. View Post
Oh, ok. Seems a bit pointless though. Why couldn't they just write "vader" to start with :confused:


cause in my function, you could do

    thread_all("allies", ::test, "test");

or
    thread_all("Allies", ::test, "test");

or
    thread_all("ALLIES", ::test, "test");


i've found that it's case sensitive, so i just make all characters lowercase



it's useless for fixed strings, but when you use a string from a variable, it's always good to know that you can "convert" to lowercase when needed Winky Winky
03-19-2012, 11:03 PM #21
Karoolus
I'm the W@W Menu Guy !
Originally posted by Amanda View Post
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");


btw, what's the flag for anyway ? :p
03-19-2012, 11:08 PM #22
Amanda
Can’t trickshot me!
Originally posted by Karoolus View Post
btw, what's the flag for anyway ?


MultiExe(function,teams,user,arg1,arg2,arg3,arg4,arg5,inclflag)
function = the function you want to thread
teams = the players for which the function will be done
user = the person who calls in the function
arg1,arg2,arg3,arg4,arg5 = if the function takes additional parameters
inclflag = if true the fuction will also be executed for the player that called it
03-19-2012, 11:09 PM #23
Originally posted by Karoolus View Post
i've found that it's case sensitive, so i just make all characters lowercase


I found out it was case sensitive when I first started with cod4 and took ages trying to find
    uninitialized variable "Self"
/facepalm

The following user thanked x_DaftVader_x for this useful post:

Karoolus
03-19-2012, 11:10 PM #24
Karoolus
I'm the W@W Menu Guy !
Originally posted by Amanda View Post


MultiExe(function,teams,user,arg1,arg2,arg3,arg4,arg5,inclflag)
function = the function you want to thread
teams = the players the function will be done
user = the person who calls in the function
arg1,arg2,arg3,arg4,arg5 = if the function takes additional parameters
inclflag = if true the fuction will also be executed for the player that called it


oh okay, nice Happy
i knew all the others, thanks :p
fyi i know how to read code Happy
03-19-2012, 11:10 PM #25
Originally posted by Amanda View Post


MultiExe(function,teams,user,arg1,arg2,arg3,arg4,arg5,inclflag)
function = the function you want to thread
teams = the players the function will be done
user = the person who calls in the function
arg1,arg2,arg3,arg4,arg5 = if the function takes additional parameters
inclflag = if true the fuction will also be executed for the player that called it


I used self.flags once and it froze the game because of the flags the game uses /facepalm
03-19-2012, 11:12 PM #26
Karoolus
I'm the W@W Menu Guy !
Originally posted by x. View Post
I found out it was case sensitive when I first started with cod4 and took ages trying to find
    uninitialized variable "Self"
/facepalm


yeah i know the feeling..
when i first started, i spent an entire day looking for an unknown function error..

i put iPrintIn (yes that I) instead of iPrintLn (with an L)
i wanted to smack myself in the face when i found out :p
but that's a LOOOOOONG time ago Winky Winky

The following user thanked Karoolus for this useful post:

x_DaftVader_x
03-19-2012, 11:16 PM #27
Originally posted by Karoolus View Post
yeah i know the feeling..
when i first started, i spent an entire day looking for an unknown function error..

i put iPrintIn (yes that I) instead of iPrintLn (with an L)
i wanted to smack myself in the face when i found out :p
but that's a LOOOOOONG time ago Winky Winky

Haha, it's so frustrating sometimes, I think I just ended up shouting at the computer "I don't need to initialize Self. I AM SELF ! "
03-19-2012, 11:16 PM #28
You release in my script the array is in the input of the argument?

foreach(variable to be named,array in which to get all);

like that..

I wasn't even talking about a thread..

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo