Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: Cod4 - a few ideas i need confirming

  1. #1
    ... connecting
    Join Date
    Dec 2014
    Posts
    9
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Cod4 - a few ideas i need confirming

    Hello, i'm new here but i've had a minor scripting background with call of duty 4, I was wondering if you would help me with a few things i get stuck on?

    I've been creating a mod for cod4 for awhile now and I want to expand on my scripting knowledge, i was wondering if the following are possible and how I would tackle them. I don't need spoon feeding; just help pointing in the right direction, as I do want to learn how these work correctly.

    1. Is it possible to write to a file (with or without developer) a series of scripts and read them from another script? for example, write from in-game to a gsc in the mod.ff (or iwd etc..)

    Ive tried openfile() but as far as i'm aware it can only print text, not write a script. is there an alternative method?

    2. how would you create a similar function which uses a dvar like ui_promotion to open a popup menu once the game has ended? i'm trying to do the same but having no luck using level.hasEnded and such.

    If you could help me with those i'm greatly appreciated!

  2. #2
    Global Mossaderator Mitch's Avatar
    Join Date
    Nov 2012
    Posts
    654
    Thanks
    204
    Thanked 451 Times in 305 Posts
    Quote Originally Posted by Uk_ViiPeR View Post
    1. Is it possible to write to a file (with or without developer) a series of scripts and read them from another script? for example, write from in-game to a gsc in the mod.ff (or iwd etc..)

    Ive tried openfile() but as far as i'm aware it can only print text, not write a script. is there an alternative method?
    With libcod you can call the OS version of openfile (fopen, fwrite). Or depending on what you wanna use it for. You could use mysql to store your player's stats.

    To execute a command under your system. You can use this (libcod):
    PHP Code:
    status system"ls" ); 
    https://github.com/kungfooman/libcod
    Function documentation: http://killtube.org/showthread.php?1...-documentation
    Support forum: http://killtube.org/forumdisplay.php?44-libcod
    Last edited by Mitch; 2nd December 2014 at 16:35.

  3. The Following 2 Users Say Thank You to Mitch For This Useful Post:

    kung foo man (3rd December 2014),Uk_ViiPeR (2nd December 2014)

  4. #3
    ... connecting
    Join Date
    Dec 2014
    Posts
    9
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Mitch View Post
    With libcod you can call the OS version of openfile (fopen, fwrite). Or depending on what you wanna use it for. You could use mysql to store your player's stats.

    To execute a command under your system. You can use this (libcod):
    PHP Code:
    status system"ls" ); 
    https://github.com/kungfooman/libcod
    Function documentation: http://killtube.org/showthread.php?1...-documentation
    Support forum: http://killtube.org/forumdisplay.php?44-libcod
    Okay thank you very much! i'll give it a shot

  5. #4
    Brigadier General
    Join Date
    Oct 2012
    Posts
    998
    Thanks
    20
    Thanked 590 Times in 390 Posts
    Quote Originally Posted by Mitch View Post
    With libcod you can call the OS version of openfile (fopen, fwrite). Or depending on what you wanna use it for. You could use mysql to store your player's stats.

    To execute a command under your system. You can use this (libcod):
    PHP Code:
    status system"ls" ); 
    https://github.com/kungfooman/libcod
    Function documentation: http://killtube.org/showthread.php?1...-documentation
    Support forum: http://killtube.org/forumdisplay.php?44-libcod
    You don't need libcod to store a player's stats in COD4 as it already has a built-in method. That is why there is ranking in COD4.

  6. #5
    Brigadier General
    Join Date
    Oct 2012
    Posts
    998
    Thanks
    20
    Thanked 590 Times in 390 Posts
    Quote Originally Posted by Uk_ViiPeR View Post
    Hello, i'm new here but i've had a minor scripting background with call of duty 4, I was wondering if you would help me with a few things i get stuck on?

    I've been creating a mod for cod4 for awhile now and I want to expand on my scripting knowledge, i was wondering if the following are possible and how I would tackle them. I don't need spoon feeding; just help pointing in the right direction, as I do want to learn how these work correctly.

    1. Is it possible to write to a file (with or without developer) a series of scripts and read them from another script? for example, write from in-game to a gsc in the mod.ff (or iwd etc..)

    Ive tried openfile() but as far as i'm aware it can only print text, not write a script. is there an alternative method?

    2. how would you create a similar function which uses a dvar like ui_promotion to open a popup menu once the game has ended? i'm trying to do the same but having no luck using level.hasEnded and such.

    If you could help me with those i'm greatly appreciated!
    1. All the file functions work in COD4, only you have to run your server in developer mode, and as such you can't run a dedicated server in that mode. However, I would suggest you tell us what it is you are trying to write to files, as COD4 has a built-in function that writes numerical data to client-side files (named "mpdata"). Modders throughout the COD4 community have been using numbers and then converting those numbers to other functions/data sets. You simply have to use your imagination to do it.

    2. To open a menu at the end of the game, just use the endGame() function (maps\mp\gametypes\_globallogic.gsc). Just set the client dvar "g_scriptMainMenu" to the name of the popup you want to open, and that menu will open automatically (just as it does in stock COD4 when it opens the end-of-game menu).

    3. Custom string tables - these work like ordinary string tables:

    1. you must run your server in online/rankedmatch mode:

    Code:
    	level.rankedMatch = ( level.onlineGame && getDvarInt( "sv_pure" ) );
    	/#
    	if ( getdvarint( "scr_forcerankedmatch" ) == 1 )
    		level.rankedMatch = true;
    	#/
    If your mod is based on modwarfare, you need to change that line of code in modwarfare's version of _globallogic.gsc as it turns off the read/write status of the setStat/getStat functions.

    2. Create your custom string table and compile it into fastfile - NB: COD4 will not read string tables in RAW format. They must be compiled into fastfile. So, add it to your mod.CSV file:

    Code:
    stringtable,mp/nameoftable.csv
    3. The way the string table function works is like this:

    Code:
    TableLookup( <filename>, <search column num>, <search value>, <return value column num> )
    1. <filename> - the first argument is the name of the file to search through
    2. <search column num> - next is the column to search through (the column numbering starts at 0 )
    3. <search value> - then is the thing that it is trying to find (in this case it is passed to the method as a parameter)
    4. <return value column num> - finally is the column number of the thing to return on the same row as the thing you want to find is located

    It is a very powerful and flexible system. You can read practically any data set as long as you are imaginative to do it. I have created string tables to spawn models and even weapons.

    If you want to give me any concrete examples of what it is you want to write/read I'm pretty sure I can help you solve any problems for you.
    Last edited by Tally; 2nd December 2014 at 17:29.

  7. The Following 2 Users Say Thank You to Tally For This Useful Post:

    kung foo man (3rd December 2014),Uk_ViiPeR (2nd December 2014)

  8. #6
    ... connecting
    Join Date
    Dec 2014
    Posts
    9
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Tally View Post
    1. All the file functions work in COD4, only you have to run your server in developer mode, and as such you can't run a dedicated server in that mode. However, I would suggest you tell us what it is you are trying to write to files, as COD4 has a built-in function that writes numerical data to client-side files (named "mpdata"). Modders throughout the COD4 community have been using numbers and then converting those numbers to other functions/data sets. You simply have to use your imagination to do it.

    2. To open a menu at the end of the game, just use the endGame() function (maps\mp\gametypes\_globallogic.gsc). Just set the client dvar "g_scriptMainMenu" to the name of the popup you want to open, and that menu will open automatically (just as it does in stock COD4 when it opens the end-of-game menu).

    3. Custom string tables - these work like ordinary string tables:

    1. you must run your server in online/rankedmatch mode:

    Code:
    	level.rankedMatch = ( level.onlineGame && getDvarInt( "sv_pure" ) );
    	/#
    	if ( getdvarint( "scr_forcerankedmatch" ) == 1 )
    		level.rankedMatch = true;
    	#/
    If your mod is based on modwarfare, you need to change that line of code in modwarfare's version of _globallogic.gsc as it turns off the read/write status of the setStat/getStat functions.

    2. Create your custom string table and compile it into fastfile - NB: COD4 will not read string tables in RAW format. They must be compiled into fastfile. So, add it to your mod.CSV file:

    Code:
    stringtable,mp/nameoftable.csv
    3. The way the string table function works is like this:

    Code:
    TableLookup( <filename>, <search column num>, <search value>, <return value column num> )
    1. <filename> - the first argument is the name of the file to search through
    2. <search column num> - next is the column to search through (the column numbering starts at 0 )
    3. <search value> - then is the thing that it is trying to find (in this case it is passed to the method as a parameter)
    4. <return value column num> - finally is the column number of the thing to return on the same row as the thing you want to find is located

    It is a very powerful and flexible system. You can read practically any data set as long as you are imaginative to do it. I have created string tables to spawn models and even weapons.

    If you want to give me any concrete examples of what it is you want to write/read I'm pretty sure I can help you solve any problems for you.
    You sir are amazing! thank you so much! this is exactly what I was looking for!

    For the string tables though, once I create the file it should look like this if i'm correct?

    Code:
    5256,string_here
    and to read the string i would use tableLookUp like the following:

    Code:
    TableLookup( "mp/custom.csv", 1, string_here, 0 ) //or is string_here meant to be 5256?
    Thank you once again for pointing me in the right direction

  9. #7
    Brigadier General
    Join Date
    Oct 2012
    Posts
    998
    Thanks
    20
    Thanked 590 Times in 390 Posts
    Quote Originally Posted by Uk_ViiPeR View Post
    You sir are amazing! thank you so much! this is exactly what I was looking for!

    For the string tables though, once I create the file it should look like this if i'm correct?

    Code:
    5256,string_here
    and to read the string i would use tableLookUp like the following:

    Code:
    TableLookup( "mp/custom.csv", 1, string_here, 0 ) //or is string_here meant to be 5256?
    Thank you once again for pointing me in the right direction
    Yes, that looks correct. The use of "string_here" is simply so you can remember it. Personally, most of the time I never use it. I simply remember the stat number I want to use and use the number instead. Example:

    Code:
    self setStat( 3152, level.configedit + 1 );
    I know what stat 3152 does, and so I don't need a string name to remember it. So, if you can remember which numbers are which, you don't really need a custom string table. It is just for mods which use a hell of a lot of different numbers and can get confusing.

    However, let's assume you really need to use a custom string table, you also need a custom function to read/write it, since otherwise, the stock ones wont work, as they specify certain string tables. In that case, create custom functions to read or write your data:

    Code:
    statGetCustom( dataName ) 
    {
    	return self getStat( int(tableLookup( "mp/customStatsTable.csv", 1, dataName, 0 )) );
    }
    
    statSetCustom( dataName, value ) 
    {
    	self setStat( int(tableLookup( "mp/customStatsTable.csv", 1, dataName, 0 )), value );	
    }
    You can place those functions anywhere in your mod, and simply call them when needed. They work exactly like the stock versions in maps\mp\gametypes\_persistence.gsc but now you have named your custom table instead of the stock playerStatsTable.csv.

  10. The Following User Says Thank You to Tally For This Useful Post:

    Uk_ViiPeR (2nd December 2014)

  11. #8
    ... connecting
    Join Date
    Dec 2014
    Posts
    9
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Tally View Post
    Yes, that looks correct. The use of "string_here" is simply so you can remember it. Personally, most of the time I never use it. I simply remember the stat number I want to use and use the number instead. Example:

    Code:
    self setStat( 3152, level.configedit + 1 );
    I know what stat 3152 does, and so I don't need a string name to remember it. So, if you can remember which numbers are which, you don't really need a custom string table. It is just for mods which use a hell of a lot of different numbers and can get confusing.

    However, let's assume you really need to use a custom string table, you also need a custom function to read/write it, since otherwise, the stock ones wont work, as they specify certain string tables. In that case, create custom functions to read or write your data:

    Code:
    statGetCustom( dataName ) 
    {
    	return self getStat( int(tableLookup( "mp/customStatsTable.csv", 1, dataName, 0 )) );
    }
    
    statSetCustom( dataName, value ) 
    {
    	self setStat( int(tableLookup( "mp/customStatsTable.csv", 1, dataName, 0 )), value );	
    }
    You can place those functions anywhere in your mod, and simply call them when needed. They work exactly like the stock versions in maps\mp\gametypes\_persistence.gsc but now you have named your custom table instead of the stock playerStatsTable.csv.
    Okay i understand that perfectly thank you! one more thing if you don't mind, how would you use the getGUID() function properly? or even easier use "level.name" to log their name. i want to add a script where it logs a "cheater", stores the data in a string table and read it from the string table to detect them if they reconnect. a bit like the tempBan commands.

  12. #9
    Brigadier General
    Join Date
    Oct 2012
    Posts
    998
    Thanks
    20
    Thanked 590 Times in 390 Posts
    1. The getGUID() function only works on a dedicated server, so you can't test it on a local/listen server. It is a script function, run from a .GSC file, and the syntax is:

    Code:
    player getGUID();
    2. level.name would return the same name for any player. It is a SP function which denotes the human being playing as opposed to the AI entities. In MP, always use "self.name" or "player.name" once you've identified who the player is.

    3. To ban cheaters from your server, you don't need anything other than the setStat()/getStat() functions in COD4 - simply appoint a stat number to cheaters. For example, let's use one of the available ones: 3175. This is now your cheater identifier. So, when you spot a cheater, and you have an admin menu (this may be something else you need) which allows you to set a player flag on a cheater, you simply get his entity number and set the stat on them:

    Code:
    {
    	mycheaterID = some method to determine the cheater - probably run from an admin menu/panel
    	for( i=0; i < level.players.size; i++ )
    	{
    		player = level.players[i];
    
    		cheaterID = player getEntityNumber();
    		if( cheaterID == mycheaterID )
    			player setStat( 3175, 1 );
    	}
    }
    	
    	
    onPlayerConnect()
    {
    	for( ;; )
    	{
    		level waittill( "connected", player );
    		
    		cheater = player getStat( 3175 );
    		if( cheater > 0 )
    		{
    			kick( player getEntityNumber() );
    		}
    	
    	}
    
    }
    That puts a value in the cheater stat and checks for it whenever a player connects. If it finds a value higher than 0, it boots them.
    Last edited by Tally; 2nd December 2014 at 18:41.

  13. The Following User Says Thank You to Tally For This Useful Post:

    Uk_ViiPeR (2nd December 2014)

  14. #10
    ... connecting
    Join Date
    Dec 2014
    Posts
    9
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Tally View Post
    1. The getGUID() function only works on a dedicated server, so you can't test it on a local/listen server. It is a script function, run from a .GSC file, and the syntax is:

    Code:
    player getGUID();
    2. level.name would return the same name for any player. It is a SP function which denotes the human being playing as opposed to the AI entities. In MP, always use "self.name" or "player.name" once you've identified who the player is.

    3. To ban cheaters from your server, you don't need anything other than the setStat()/getStat() functions in COD4 - simply appoint a stat number to cheaters. For example, let's use one of the available ones: 3175. This is now your cheater identifier. So, when you spot a cheater, and you have an admin menu (this may be something else you need) which allows you to set a player flag on a cheater, you simply get his entity number and set the stat on them:

    Code:
    {
    	mycheaterID = some method to determine the cheater - probably run from an admin menu/panel
    	for( i=0; i < level.players.size; i++ )
    	{
    		player = level.players[i];
    
    		cheaterID = player getEntityNumber();
    		if( cheaterID == mycheaterID )
    			player setStat( 3175, 1 );
    	}
    }
    	
    	
    onPlayerConnect()
    {
    	for( ;; )
    	{
    		level waittill( "connected", player );
    		
    		cheater = player getStat( 3175 );
    		if( cheater > 0 )
    		{
    			kick( player getEntityNumber() );
    		}
    	
    	}
    
    }
    That puts a value in the cheater stat and checks for it whenever a player connects. If it finds a value higher than 0, it boots them.
    Thank you so much! it was easier than i thought it would be when i kept trial and erroring different stuff but at least you can confirm this all works. Thank you for everything!

    ps. do you know any available stat numbers for world at war? or are they the same as cod4?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •