Call of Duty 4: Useful Functions: Difference between revisions

From COD Modding & Mapping Wiki
Jump to navigation Jump to search
(Created page with "<br> Image:Warning.png <font color="red">NOTE: These scripts are only adding functionality into game. They do not add things such as mines, artillery, kaboom etc...</font col...")
 
mNo edit summary
Line 155: Line 155:
</syntaxhighlight>
</syntaxhighlight>


'''Feel free to use these functions in your own mod. Just remember to put me in credits.'''
'''Feel free to use these functions in your own mod. Just remember to put "Brax" in credits.'''


By Brax - [http://modsonline.com/Forums-top-140965-0.html#737400 Sources]
By Brax - [http://modsonline.com/Forums-top-140965-0.html#737400 Sources]

Revision as of 19:28, 13 May 2011


NOTE: These scripts are only adding functionality into game. They do not add things such as mines, artillery, kaboom etc...

Returns array of all players on the server.

getAllPlayers()
{
	return getEntArray( "player", "classname" );
}

Play local sound on all players.

playSoundOnAllPlayers( soundAlias )
{
	players = getAllPlayers();
	for( i = 0; i < players.size; i++ )
	{
		players[i] playLocalSound( soundAlias );
	}
}

Removes all text messages from screen.

cleanScreen()
{
	for( i = 0; i < 6; i++ )
	{
		iPrintlnBold( " " );
		iPrintln( " " );
	}
}

Delete object after time.

deleteAfterTime( time )
{
	wait time;
	if( isDefined( self ) )
		self delete();
}

Return BOOL (true of false) when player is really alive and playing.

Note: CoD's isAlive() function seems to be bugged.

isReallyAlive()
{
	if( self.sessionstate == "playing" )
		return true;
	else
		return false;
}

isPlaying() { return isReallyAlive(); } </syntaxhighlight>

Toggle third person camera.

thirdPerson()
{
	if( !isDefined( self.tp ) )
	{
		self.tp = true;
		self setClientDvar( "cg_thirdPerson", 1 );
	}
	else
	{
		self.tp = undefined;
		self setClientDvar( "cg_thirdPerson", 0 );
	}
}

Waits for enough players to start game.

// Use: waitForPlayers( 3 ); Code after this function call will be executed when there is required number of alive players.
waitForPlayers( requiredPlayersCount )
{
	quit = false;
	while( !quit )
	{
		wait 0.5;
		count = 0;
		players = getAllPlayers();
		for( i = 0; i < players.size; i++ )
		{
			if( players[i] isPlaying() )
				count++;
		}

		if( count >= requiredPlayersCount )
			break;
	}
}

Return player with that nick name or its part.

getPlayerByName( nickname ) 
{
	players = getAllPlayers();
	for ( i = 0; i < players.size; i++ )
	{
		if ( isSubStr( toLower(players[i].name), toLower(nickname) ) ) 
		{
			return players[i];
		}
	}
}

Return player with that slot number.

getPlayerByNum( pNum ) 
{
	players = getAllPlayers();
	for ( i = 0; i < players.size; i++ )
	{
		if ( players[i] getEntityNumber() == pNum ) 
			return players[i];
	}
}

Return true when victim was killed through world geometry.

isWallBang( attacker, victim )
{
	start = attacker getEye();
	end = victim getEye();
	if( bulletTracePassed( start, end, false, attacker ) )
		return false;
	return true;
}

Feel free to use these functions in your own mod. Just remember to put "Brax" in credits.

By Brax - Sources

--Zeroy 12:36, 13 May 2011 (IST)