AWE Callback Override (in MM2) - CrazyCoder - 03-19-2018
Here is the callback override stuff so you load _mc2\_callbacks from _callbacksetup.gsc. _mc2\_players.gsc is then loaded by _callbacks.gsc.
To make is so everything is not crammed in tdm.gsc callbacks. Less clutter, more organized
_callbacksetup.gsc
Code:
// Callback Setup
// This script provides the hooks from code into script for the gametype callback functions.
//=============================================================================
// Code Callback functions
/*================
Called by code after the level's main script function has run.
================*/
CodeCallback_StartGameType()
{
// If the gametype has not beed started, run the startup
if(!isDefined(level.gametypestarted) || !level.gametypestarted)
{
[[level.callbackStartGameType]]();
level.gametypestarted = true; // so we know that the gametype has been started up
}
}
/*================
Called when a player begins connecting to the server.
Called again for every map change or tournement restart.
Return undefined if the client should be allowed, otherwise return
a string with the reason for denial.
Otherwise, the client will be sent the current gamestate
and will eventually get to ClientBegin.
firstTime will be qtrue the very first time a client connects
to the server machine, but qfalse on map changes and tournement
restarts.
================*/
CodeCallback_PlayerConnect()
{
self endon("disconnect");
[[level.callbackPlayerConnect]]();
}
/*================
Called when a player drops from the server.
Will not be called between levels.
self is the player that is disconnecting.
================*/
CodeCallback_PlayerDisconnect()
{
self notify("disconnect");
[[level.callbackPlayerDisconnect]]();
}
/*================
Called when a player has taken damage.
self is the player that took damage.
================*/
CodeCallback_PlayerDamage(eInflictor, eAttacker, iDamage, iDFlags, sMeansOfDeath, sWeapon, vPoint, vDir, sHitLoc, timeOffset)
{
self endon("disconnect");
[[level.callbackPlayerDamage]](eInflictor, eAttacker, iDamage, iDFlags, sMeansOfDeath, sWeapon, vPoint, vDir, sHitLoc, timeOffset);
}
/*================
Called when a player has been killed.
self is the player that was killed.
================*/
CodeCallback_PlayerKilled(eInflictor, eAttacker, iDamage, sMeansOfDeath, sWeapon, vDir, sHitLoc, timeOffset, deathAnimDuration)
{
self endon("disconnect");
[[level.callbackPlayerKilled]](eInflictor, eAttacker, iDamage, sMeansOfDeath, sWeapon, vDir, sHitLoc, timeOffset, deathAnimDuration);
}
//=============================================================================
/*================
Setup any misc callbacks stuff like defines and default callbacks
================*/
SetupCallbacks()
{
// MERCILESS
_mc2\_callbacks::init();
SetDefaultCallbacks();
// Set defined for damage flags used in the playerDamage callback
level.iDFLAGS_RADIUS = 1;
level.iDFLAGS_NO_ARMOR = 2;
level.iDFLAGS_NO_KNOCKBACK = 4;
level.iDFLAGS_NO_TEAM_PROTECTION = 8;
level.iDFLAGS_NO_PROTECTION = 16;
level.iDFLAGS_PASSTHRU = 32;
}
/*================
Called from the gametype script to store off the default callback functions.
This allows the callbacks to be overridden by level script, but not lost.
================*/
SetDefaultCallbacks()
{
level.default_CallbackStartGameType = level.callbackStartGameType;
level.default_CallbackPlayerConnect = level.callbackPlayerConnect;
level.default_CallbackPlayerDisconnect = level.callbackPlayerDisconnect;
level.default_CallbackPlayerDamage = level.callbackPlayerDamage;
level.default_CallbackPlayerKilled = level.callbackPlayerKilled;
}
/*================
Called when a gametype is not supported.
================*/
AbortLevel()
{
println("Aborting level - gametype is not supported");
level.callbackStartGameType = ::callbackVoid;
level.callbackPlayerConnect = ::callbackVoid;
level.callbackPlayerDisconnect = ::callbackVoid;
level.callbackPlayerDamage = ::callbackVoid;
level.callbackPlayerKilled = ::callbackVoid;
setcvar("g_gametype", "dm");
exitLevel(false);
}
/*================
================*/
callbackVoid()
{
}
_mc2\_callbacks.gsc
Code:
init()
{
// Override callbacks
level.mc2_callbackStartGameType = level.callbackStartGameType;
level.mc2_callbackPlayerConnect = level.callbackPlayerConnect;
level.mc2_callbackPlayerDisconnect = level.callbackPlayerDisconnect;
level.mc2_callbackPlayerDamage = level.callbackPlayerDamage;
level.mc2_callbackPlayerKilled = level.callbackPlayerKilled;
level.callbackStartGameType = ::Callback_StartGameType;
level.callbackPlayerConnect = ::Callback_PlayerConnect;
level.callbackPlayerDisconnect = ::Callback_PlayerDisconnect;
level.callbackPlayerDamage = ::Callback_PlayerDamage;
level.callbackPlayerKilled = ::Callback_PlayerKilled;
}
Callback_StartGameType()
{
_mc2\_player::StartGametype();
[[level.mc2_callbackStartGameType]]();
}
Callback_PlayerConnect()
{
self endon("disconnect");
self _mc2\_player::PlayerConnect();
[[level.mc2_callbackPlayerConnect]]();
}
Callback_PlayerDisconnect()
{
self endon("disconnect");
self _mc2\_player::PlayerDisconnect();
[[level.mc2_callbackPlayerDisconnect]]();
}
Callback_PlayerDamage(eInflictor, eAttacker, iDamage, iDFlags, sMeansOfDeath, sWeapon, vPoint, vDir, sHitLoc, psOffsetTime)
{
self endon("disconnect");
iDamage = self _mc2\_player::PlayerDamage(eInflictor, eAttacker, iDamage, iDFlags, sMeansOfDeath, sWeapon, vPoint, vDir, sHitLoc, psOffsetTime);
if(iDamage>=0)
{
[[level.mc2_callbackPlayerDamage]](eInflictor, eAttacker, iDamage, iDFlags, sMeansOfDeath, sWeapon, vPoint, vDir, sHitLoc, psOffsetTime);
_mc2\_player::PostPlayerDamage(eInflictor, eAttacker, iDamage, iDFlags, sMeansOfDeath, sWeapon, vPoint, vDir, sHitLoc, psOffsetTime);
}
/* OFF TEMP
// Update healthbar
if (isdefined(self) && isPlayer(self))
self mc2\_healthbar::UpdateHealthBar();
if (isdefined(eAttacker) && isPlayer(eAttacker))
eAttacker mc2\_healhbar::UpdateHealthBar();
*/
}
Callback_PlayerKilled(eInflictor, attacker, iDamage, sMeansOfDeath, sWeapon, vDir, sHitLoc, psOffsetTime, deathAnimDuration)
{
self endon("disconnect");
self _mc2\_player::PlayerKilled(eInflictor, attacker, iDamage, sMeansOfDeath, sWeapon, vDir, sHitLoc, psOffsetTime, deathAnimDuration);
[[level.mc2_callbackPlayerKilled]](eInflictor, attacker, iDamage, sMeansOfDeath, sWeapon, vDir, sHitLoc, psOffsetTime, deathAnimDuration);
}
then _players.gsc loads each script:
Code:
StartGameType()
{
//Flags
_mc2\_levelflags::InitPlayer_Flags();
//sprint
//if(getcvarint("scr_" + self.pers["pClass"] + "_speed") < 1)
self.maxspeed = getcvar("g_speed");
//else
// self.maxspeed = getcvarint("scr_" + self.pers["pClass"] + "_speed");
//bots
thread _mc2\_bots::init();
thread _mc2\_bots::addTestClients();
//SpawnProtection int
_mc2\_protect::init();
_mc2\_mc2_init::init();
_mc2\pb::pb_init();
thread _mc2\_mc2_classes::init();
thread _mc2\_mc2_classes::MonitorClasses();
// _mc2\_mortars::init(); //update later
_mc2\_artillery::init();
_mc2\_mc2_special::init(); //Eliminate later
// Sprinting
thread _mc2\_sprinting::init(); // Added by bell
_mc2\_healthpacks::init();
thread _mc2\_protect::nozombie();
thread _mc2\_bannerimage::banner_image("gfx/hud/logo_mc1.tga", 179,45,15,-5);
}
PlayerConnect()
{
}
PlayerDisconnect()
{
}
spawnPlayer()
{
//Spawn Protection
_mc2\_protect::ProtectSpawnPlayer();
if(isdefined(game["german_soldiertype"]) && (game["german_soldiertype"] == "winterlight"||game["german_soldiertype"] == "winterdark")
||isdefined(game["russian_soldiertype"]) && (game["russian_soldiertype"] == "padded"||game["russian_soldiertype"] == "coats")&&level.scr_coldbreath==1)
self thread _mc2\_coldbreath::breath();
//Skins
self thread _mc2\_playermodels::checkAttachment_head();
self thread _mc2\_playermodels::checkAttachment_hat();
self thread _mc2\_buttonusage::checkStance();
self thread _mc2\_buttonusage::check_adsbutton();
//deadbody handling
//self thread _mc2\_mc2_gore::check_nade();
self thread _mc2\_mc2_gore::body_shooting();
_mc2\_mc2_hud::hud();
//Reset some HUD Elems
_mc2\_clearhud::resetHUD();
self _mc2\_sprinting::RunOnSpawn(); // Added by bell
//Wait until player dies
self waittill("TimeToDie", attacker);
_mc2\_sprinting::CleanupKilled(); // Added by bell
//Clean up HUD Elems
_mc2\_clearhud::hud_playerdeath();
//Obitsys
_mc2\_obitsys::ObitSpawnPlayer(attacker);
}
spawnSpectator()
{
self _mc2\_clearhud::resetHUD();
self _mc2\_clearhud::hud_playerdeath();
if(isDefined(self.sprot))
self.sprot destroy();
}
PlayerDamage(eInflictor, eAttacker, iDamage, iDFlags, sMeansOfDeath, sWeapon, vPoint, vDir, sHitLoc, psOffsetTime)
{
if(isdefined(self.burned)&&self.burned==1||sMeansOfDeath == "MOD_UNKNOWN"||sMeansOfDeath == "MOD_FALLING"||isDefined(self.protected))return;
if (!isDefined(vPoint))
vPoint = self.origin + (0,0,11);
if(isDefined(self.scr) && self.health - iDamage > 0 )
self thread _mc2\_painsounds::_doSounds("pain",sMeansOfDeath);
if (isPlayer(eAttacker) && sMeansOfDeath != "MOD_FALLING" && level.scr_bloodyscreen)
{
if(sMeansOfDeath == "MOD_MELEE" || distance(eAttacker.origin , self.origin ) <= 48 )
eAttacker thread _mc2\_mc2_gore::Splatter_View();
if(level.scr_showhit )
eAttacker thread _mc2\_mc2_gore::showhit();
}
if(sHitLoc == "head" || shitLoc=="none" || sHitLoc=="helmet")
{
if(level.scr_bloodyscreen && (!isDefined(self.thrown)))
self thread _mc2\_mc2_gore::Splatter_View();
}
if(level.scr_extragore && sMeansOfDeath != "MOD_GRENADE" && sMeansOfDeath != "MOD_GRENADE_SPLASH")
{
if(level.bloodfx==0)return;
else if(level.bloodfx==1)
{
switch (randomint(3))
{
case 0: playfx(level._effect["hit_extra1_mc"],vPoint,vDir);break;
case 1: playfx(level._effect["hit_extra2_mc"],vPoint,vDir);break;
case 2: playfx(level._effect["hit_extra3_mc"],vPoint,vDir);break;
}
}
else
{
switch (randomint(3))
{
case 0: playfx(level._effect["hit_extra1"],vPoint,vDir);break;
case 1: playfx(level._effect["hit_extra2"],vPoint,vDir);break;
case 2: playfx(level._effect["hit_extra3"],vPoint,vDir);break;
}
}
}
if(sHitLoc == "right_hand"|| sHitLoc == "left_hand" || sHitLoc == "gun" || sHitLoc == "right_arm_lower" || sHitLoc == "left_arm_lower")
{
if ( isAlive(self) && level.scr_dropweaponhit > randomint(99))
self dropItem(self getcurrentweapon());
}
if(level.realism && sHitLoc == "left_leg_upper" || sHitLoc == "right_leg_upper" || sHitLoc == "left_leg_lower" || sHitLoc == "right_leg_lower" || sHitLoc == "left_foot" || sHitLoc == "right_foot")
{
if(self.stance==2)
_mc2\_forceto::forceto("crouch");
else if(self.stance==1)
_mc2\_forceto::forceto("prone");
}
if(sHitLoc == "head"|| sHitLoc=="helmet")
{
if( self.health - iDamage < 1 && (iDamage >= level.scr_decap_min) && sMeansOfDeath != "MOD_MELEE" )
{
}
else
if(self.decaped != 1 )
{
self thread _mc2\_painsounds::_doSounds("death",sMeansOfDeath);
}
}
if(sHitLoc == "none")
{
if(sMeansOfDeath == "MOD_PROJECTILE" || sMeansOfDeath == "MOD_PROJECTILE_SPLASH" || sMeansOfDeath == "MOD_GRENADE" || sMeansOfDeath == "MOD_GRENADE_SPLASH" || sMeansOfDeath == "MOD_EXPLOSIVE")
{
if(self.health - iDamage < 1)
{
if(isDefined(eInflictor))
{
if(distance(eInflictor.origin,self.origin)<=100)
{
}
else if(distance(eInflictor.origin,self.origin)>100)
{
if( (iDamage >= level.scr_decap_min) && (level.scr_decap_chance >= randomint(100)) && (sMeansOfDeath != "MOD_MELEE") && (!isDefined(self.thrown)) )
{
}
else
{
self thread _mc2\_painsounds::_doSounds("death",sMeansOfDeath);
}
}
}
}
}
}
}
PostPlayerDamage(eInflictor, eAttacker, iDamage, iDFlags, sMeansOfDeath, sWeapon, vPoint, vDir, sHitLoc, psOffsetTime)
{
//Gas Nade
self thread _mc2\_gasnade::GasPlayerDamage(vPoint, eInflictor, eAttacker, iDamage, iDFlags, sMeansOfDeath, sWeapon, level.mustardgas, vDir, sHitLoc, psOffsetTime);
//flame nade
self thread _mc2\_flamenade::FlamePlayerDamage(vPoint, eInflictor, eAttacker, iDamage, iDFlags, sMeansOfDeath, sWeapon, level.flamenade, vDir, sHitLoc, psOffsetTime);
//helmet pop
thread _mc2\_helmetpop::HelmetPlayerDamage(sHitLoc, sMeansOfDeath, self.helm, vPoint, self.curhat, iDamage, "death", org, ch, vDir, model);
}
PlayerKilled(eInflictor, attacker, iDamage, sMeansOfDeath, sWeapon, vDir, sHitLoc, psOffsetTime, deathAnimDuration)
{
if(self.sessionteam == "spectator")
return;
if(isPlayer(attacker))
{
if(attacker == self) // killed himself
{
}
else
{
if(level.awe_teamplay && self.pers["team"] == attacker.pers["team"]) // killed by a friendly
{
attacker _mc2\_teamkilling::TeamKill();
}
else // killed by an enemy
{
}
}
}
else // If you weren't killed by a player, you were in the wrong place at the wrong time
{
}
// Drop health
_mc2\_healthpacks::dropHealth();
//Bloodpools
_mc2\_bloodpools::BloodPlayerKilled(self.burned, self.origin);
//PlayerBurn
_mc2\_playerburn::BurnPlayerKilled(self.burned, sWeapon);
}
endMap()
{
//remove bots
thread _mc2\_bots::removeTestClients();
}
|