Call of Duty 4: Useful Functions: Difference between revisions
mNo edit summary |
Small optimizations |
||
Line 20: | Line 20: | ||
players = getAllPlayers(); | players = getAllPlayers(); | ||
for( i = 0; i < players.size; i++ ) | for( i = 0; i < players.size; i++ ) | ||
players[i] playLocalSound( soundAlias ); | players[i] playLocalSound( soundAlias ); | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 57: | Line 55: | ||
isReallyAlive() | isReallyAlive() | ||
{ | { | ||
return self.sessionstate == "playing"; | |||
} | } | ||
isPlaying() | isPlaying() | ||
Line 75: | Line 69: | ||
thirdPerson() | thirdPerson() | ||
{ | { | ||
if( | if( isDefined( self.tp ) ) | ||
{ | { | ||
self.tp = | self.tp = undefined; | ||
self setClientDvar( "cg_thirdPerson", | self setClientDvar( "cg_thirdPerson", 0 ); | ||
} | } | ||
else | else | ||
{ | { | ||
self.tp = | self.tp = true; | ||
self setClientDvar( "cg_thirdPerson", | self setClientDvar( "cg_thirdPerson", 1 ); | ||
} | } | ||
} | } | ||
Line 94: | Line 88: | ||
waitForPlayers( requiredPlayersCount ) | waitForPlayers( requiredPlayersCount ) | ||
{ | { | ||
for(;;) | |||
{ | { | ||
wait 0.5; | wait 0.5; | ||
Line 101: | Line 94: | ||
players = getAllPlayers(); | players = getAllPlayers(); | ||
for( i = 0; i < players.size; i++ ) | for( i = 0; i < players.size; i++ ) | ||
if( players[i] isPlaying() ) | if( players[i] isPlaying() ) | ||
count++; | count++; | ||
if( count >= requiredPlayersCount ) | if( count >= requiredPlayersCount ) | ||
Line 119: | Line 110: | ||
players = getAllPlayers(); | players = getAllPlayers(); | ||
for ( i = 0; i < players.size; i++ ) | for ( i = 0; i < players.size; i++ ) | ||
if ( isSubStr( toLower(players[i].name), toLower(nickname) ) ) | if ( isSubStr( toLower(players[i].name), toLower(nickname) ) ) | ||
return players[i]; | return players[i]; | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 135: | Line 122: | ||
players = getAllPlayers(); | players = getAllPlayers(); | ||
for ( i = 0; i < players.size; i++ ) | for ( i = 0; i < players.size; i++ ) | ||
if ( players[i] getEntityNumber() == pNum ) | if ( players[i] getEntityNumber() == pNum ) | ||
return players[i]; | return players[i]; | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 147: | Line 132: | ||
isWallBang( attacker, victim ) | isWallBang( attacker, victim ) | ||
{ | { | ||
return !bulletTracePassed( attacker getEye(), victim getEye(), false, attacker ); | |||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> |
Latest revision as of 12:53, 23 February 2012
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.
<syntaxhighlight lang="cpp"> getAllPlayers() { return getEntArray( "player", "classname" ); } </syntaxhighlight>
Play local sound on all players.
<syntaxhighlight lang="cpp"> playSoundOnAllPlayers( soundAlias ) { players = getAllPlayers(); for( i = 0; i < players.size; i++ ) players[i] playLocalSound( soundAlias ); } </syntaxhighlight>
Removes all text messages from screen.
<syntaxhighlight lang="cpp"> cleanScreen() { for( i = 0; i < 6; i++ ) { iPrintlnBold( " " ); iPrintln( " " ); } } </syntaxhighlight>
Delete object after time.
<syntaxhighlight lang="cpp"> deleteAfterTime( time ) { wait time; if( isDefined( self ) ) self delete(); } </syntaxhighlight>
Return BOOL (true of false) when player is really alive and playing.
Note: CoD's isAlive() function seems to be bugged.
<syntaxhighlight lang="cpp"> isReallyAlive() { return self.sessionstate == "playing"; }
isPlaying() { return isReallyAlive(); } </syntaxhighlight>
Toggle third person camera.
<syntaxhighlight lang="cpp"> thirdPerson() { if( isDefined( self.tp ) ) { self.tp = undefined; self setClientDvar( "cg_thirdPerson", 0 ); } else { self.tp = true; self setClientDvar( "cg_thirdPerson", 1 ); } } </syntaxhighlight>
Waits for enough players to start game.
<syntaxhighlight lang="cpp"> // Use: waitForPlayers( 3 ); Code after this function call will be executed when there is required number of alive players. waitForPlayers( requiredPlayersCount ) { for(;;) { wait 0.5; count = 0; players = getAllPlayers(); for( i = 0; i < players.size; i++ ) if( players[i] isPlaying() ) count++;
if( count >= requiredPlayersCount ) break; } } </syntaxhighlight>
Return player with that nick name or its part.
<syntaxhighlight lang="cpp"> getPlayerByName( nickname ) { players = getAllPlayers(); for ( i = 0; i < players.size; i++ ) if ( isSubStr( toLower(players[i].name), toLower(nickname) ) ) return players[i]; } </syntaxhighlight>
Return player with that slot number.
<syntaxhighlight lang="cpp"> getPlayerByNum( pNum ) { players = getAllPlayers(); for ( i = 0; i < players.size; i++ ) if ( players[i] getEntityNumber() == pNum ) return players[i]; } </syntaxhighlight>
Return true when victim was killed through world geometry.
<syntaxhighlight lang="cpp"> isWallBang( attacker, victim ) { return !bulletTracePassed( attacker getEye(), victim getEye(), false, attacker ); } </syntaxhighlight>
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)