home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Classic Fond 54
/
ClassicFond54.iso
/
games
/
stars.rar
/
multiplayer
/
multiplayerStdLib.cs
< prev
next >
Wrap
Text File
|
1999-02-19
|
29KB
|
914 lines
//------------------------------------------------------------------------------
//
// Multiplayer standard library
//
//-----------------------------------------------
// Utility functions
// If this variable is set to true, when a teammate hits another teammate repeatedly,
// he will be penalized. The offender's Herc will be shut down, his reactor and shields
// drained, and all of his ammo (energy too) drained. Once a player has offended, he
// will be on probation temporarily. The probation time depends on how bad (or many times)
// he has attacked his teammates.
//
// When enabled, the offending player is notified with a text message that he is being
// penalized for team attacking.
$teamHittingPenalty = False;
function timeDifference(%t1, %t2)
{
// calculates the time difference t1-t2 and returns it as a string
// such as "1 minute, 32 seconds"
%diff = %t1 - %t2;
%minutes = 0;
// can't do rounding in console so hack it
%temp = %diff;
%temp = %temp - 60;
while(%temp >= 0)
{
%minutes = %minutes + 1;
%temp = %temp - 60;
}
%seconds = %temp + 60;
// prepare output
%output = "";
if(%minutes > 0)
{
%output = %output @ %minutes @ " ";
if(%minutes == 1)
{
%output = %output @ *IDMULT_MINUTE;
}
else
{
%output = %output @ *IDMULT_MINUTES;
}
if(%seconds > 0)
{
// make space for seconds output
%output = %output @ ", ";
}
}
if(%seconds > 0)
{
%output = %output @ %seconds @ " ";
if(%seconds == 1)
{
%output = %output @ *IDMULT_SECOND;
}
else
{
%output = %output @ *IDMULT_SECONDS;
}
}
return %output;
}
function withinDistance( %obj1, %obj2, %distance)
{
%obj1 = getObjectId( %obj1 );
%obj2 = getObjectId( %obj2 );
%var = getDistance( %obj1, %obj2 );
if( %var > %distance )
{
return false;
}
else
{
return true;
}
}
function warp( %obj1, %obj2 )
{
// set the position of obj1 to the position of obj2
%obj2X = getPosition( %obj2, "x" );
%obj2Y = getPosition( %obj2, "y" );
%obj2Z = getPosition( %obj2, "z" );
setPosition( %obj1, %obj2X, %obj2Y, %obj2Z );
}
function randomTransport( %object, %x1, %y1, %x2, %y2)
{
// set the position of %object to a randow spot within the space
// bounded by (x1, y1) and (x2, y2). The Z coordinate is going to
// be set to 40 meters above the terrain at the new point.
%x = randomInt(%x1, %x2);
%y = randomInt(%y1, %y2);
%z = getTerrainHeight(%x, %y) + 60;
%playerNum = playerManager::vehicleIdToPlayerNum(%object);
// play a sound at both locations
playSound(0, IDSFX_TELEPORTER, IDPRF_NEAR, %object);
playSound(0, IDSFX_TELEPORTER, IDPRF_NEAR, %x, %y, %z);
if(%playerNum != 0)
{
fadeEvent(%playerNum, out, 1.0, 1.0, 1.0, 1.0);
schedule(strcat("fadeEvent(", %playerNum, ",in, 1.0, 1.0, 1.0, 1.0);"), 1.2);
}
schedule(strcat("setPosition(", %object, ",", %x,",", %y,",", %z,");"), 1.0);
}
function displayPercentage(%this, %percentage)
{
%player = playerManager::vehicleIdToPlayerNum( %this );
if(%player != 0)
{
say(%player, 0, *IDMULT_CHAT_SHOW_PERCENTAGE_1 @ %percentage @ *IDMULT_CHAT_SHOW_PERCENTAGE_2);
}
}
function getFullPath(%object)
{
// recursive function to get the path of this thing
if(%object == 0)
{
return "";
}
%name = getObjectName(%object);
if(%name == "MissionGroup")
{
return %name;
}
else
{
return (getFullPath(getGroup(%object)) @ "\\" @ %name);
}
}
//-----------------------------------------------
// Rules enforcement
function vehicle::onDestroyed(%destroyed, %destroyer)
{
// a generic enforcement of rules
if($server::TeamPlay == true)
{
if(
(getTeam(%destroyed) == getTeam(%destroyer)) &&
(%destroyed != %destroyer)
)
{
antiTeamKill(%destroyer);
}
}
}
function antiTeamKill(%offender)
{
// offender is a vehicle
%player = playerManager::vehicleIdToPlayerNum(%offender);
if(%player == 0)
return; // it's the server
say(%player, %player, "", "rules_violated.wav");
// since whatever we do will kill the offender, avoid recursion
resetLastHitBy(%offender);
if(
(%player.teamKillWarn == true) && // already been warned
(%player != getConnectedClient()) // check to see if it is the hosting player
)
{
// kick 'em
// reset the warn flag first
%player.teamKillWarn = false;
kick(%player, *IDMULT_CHAT_TEAM_KILL_KICK);
}
else
{
// set the warn flag first
%player.teamKillWarn = true;
// kill the offender
damageObject(%offender, 1000000);
// tell the player
messageBox(%player, *IDMULT_CHAT_TEAM_KILL_WARN);
}
}
function getNumberOfPlayersOnTeam(%bits)
{
%name = getTeamNameFromTeamId(%bits);
%count = 0;
%playerCount = playerManager::getPlayerCount();
for (%p = 0; %p < %playerCount; %p++)
{
%player = playerManager::getPlayerNum(%p);
%team = getTeam(%player);
if(%team == %name)
{
%count++;
}
}
return %count;
}
//-----------------------------------------------
// Zen Stuff
// these are triggers that heal, reload, or both
// only one player can use it at a time, and each time it is used, it
// will "re-charge" for a certain number of seconds (optional). The player
// who landed on it is "special" and can stay as long as he/she wants.
// As soon as this person leaves it, he/she is no longer "special".
// player::onRemove must be run for triggers to handle "special" correctly
// any script that overrides this function should specifically include this code
function player::onRemove(%this)
{
%vehicle = playerManager::playerNumToVehicleId(%this);
if(%vehicle != 0)
{
if(%vehicle.pad != "")
{
// reset the special for the pad this guy was on
%vehicle.pad.special = "";
}
}
}
function Zen::onEnter(%trigger, %object, %message, %isReady, %countdown)
{
// %trigger has been entered
// %object is the one who hit it
// %message is a string to display (could be empty).
// %isReady is a boolean -- if we report, do we tell if trigger is ready?
// %countdown is a boolean -- if we report, and we tell player if trigger
// is ready, and trigger is not ready, do we tell player when trigger
// will be ready?
// in all cases, this function will only send one message to the player,
// since all of the above information will be concatenated.
if(%message != "")
{
// the basic message
%output = %message;
// check for which soundfile we should play
%soundFile = "";
if(%message == *IDMULT_CHAT_HEALPAD)
{
%soundFile = "repair_ent.wav";
}
else if(%message == *IDMULT_CHAT_AMMOPAD)
{
%soundFile = "reload_ent.wav";
}
if(%isReady == true)
{
// make space for the next part
%output = %output @ " ";
// see whether or not it is ready
if(
%trigger.wait == false ||
%trigger.wait == "" ||
(%trigger.reset <= getCurrentTime())
)
{
// it's ready
%output = %output @ *IDMULT_READY;
}
else
{
%output = %output @ *IDMULT_NOT_READY;
// trigger isn't ready, but do we display the countdown
if(
%countdown == true && // display countdown?
%trigger.reset != ""