mirror of
https://github.com/ChocoTaco1/TacoServer.git
synced 2026-01-19 16:14:44 +00:00
Numerous fixes
This commit is contained in:
parent
c4fe922410
commit
f91110c468
|
|
@ -1,6 +1,13 @@
|
|||
//Fixes for collision tunneling on flag objects note only in CTF type games
|
||||
//Fixes for collision tunneling among other flag issues, note only works in classic ctf game types
|
||||
//Script By:DarkTiger
|
||||
$ftEnable = 1;
|
||||
$ftEnable = 1;//disables all
|
||||
$limitFlagCalls = 1; // prevents frame perfect events witch can cause bad outcomes
|
||||
$antiCeiling = 1; // keep flags from getting stuck in the ceiling
|
||||
$antiTerTunnel = 0;//prevents terrain tunneling keeps the flag above the terrain leave this off unless you think its a problem
|
||||
$antiFlagImpluse = 1000;//time out period to prevent explosions from effecting flags on drop/toss
|
||||
|
||||
|
||||
//best to leave these values alone unless you understand what the code is doing
|
||||
$flagSimTime = 60;//note a higher the time, the larger the sweep scans will be
|
||||
$flagCheckRadius = 50;
|
||||
$playerBoxA = "-0.6 -0.6 0";
|
||||
|
|
@ -53,35 +60,113 @@ package flagFix{
|
|||
}
|
||||
%game.fcs = getSimTime();
|
||||
}
|
||||
|
||||
//prevents frame perfect flag touches witch can cause bad stuff to happen in ctf
|
||||
function CTFGame::playerTouchFlag(%game, %player, %flag){
|
||||
if(%flag.lastFlagCallms > 0 && $limitFlagCalls){
|
||||
%timeDif = getSimTime() - %flag.lastFlagCallms;
|
||||
if(%timeDif < 32){
|
||||
return;
|
||||
}
|
||||
}
|
||||
%flag.lastFlagCallms = getSimTime();
|
||||
parent::playerTouchFlag(%game, %player, %flag);
|
||||
}
|
||||
|
||||
function SCtFGame::playerTouchFlag(%game, %player, %flag){
|
||||
if(%flag.lastFlagCallms > 0 && $limitFlagCalls){
|
||||
%timeDif = getSimTime() - %flag.lastFlagCallms;
|
||||
if(%timeDif < 32){
|
||||
return;
|
||||
}
|
||||
}
|
||||
%flag.lastFlagCallms = getSimTime();
|
||||
parent::playerTouchFlag(%game, %player, %flag);
|
||||
}
|
||||
|
||||
function PracticeCTFGame::playerTouchFlag(%game, %player, %flag){
|
||||
if(%flag.lastFlagCallms > 0 && $limitFlagCalls){
|
||||
%timeDif = getSimTime() - %flag.lastFlagCallms;
|
||||
if(%timeDif < 32){
|
||||
return;
|
||||
}
|
||||
}
|
||||
%flag.lastFlagCallms = getSimTime();
|
||||
parent::playerTouchFlag(%game, %player, %flag);
|
||||
}
|
||||
|
||||
function CTFGame::playerDroppedFlag(%game, %player){
|
||||
%flag = %player.holdingFlag;
|
||||
%flag.lastDropTime = getSimTime();
|
||||
parent::playerDroppedFlag(%game, %player);
|
||||
}
|
||||
|
||||
function SCtFGame::playerDroppedFlag(%game, %player){
|
||||
%flag = %player.holdingFlag;
|
||||
%flag.lastDropTime = getSimTime();
|
||||
parent::playerDroppedFlag(%game, %player);
|
||||
}
|
||||
|
||||
function PracticeCTFGame::playerDroppedFlag(%game, %player){
|
||||
%flag = %player.holdingFlag;
|
||||
%flag.lastDropTime = getSimTime();
|
||||
parent::playerDroppedFlag(%game, %player);
|
||||
}
|
||||
|
||||
function Flag::shouldApplyImpulse(%data, %obj){
|
||||
%val = parent::shouldApplyImpulse(%data, %obj);
|
||||
if($antiFlagImpluse > 0 && %val && %obj.lastDropTime > 0){
|
||||
%time = getSimTime() - %obj.lastDropTime;
|
||||
if(%time < $antiFlagImpluse){
|
||||
%val = 0;
|
||||
}
|
||||
}
|
||||
return %val;
|
||||
}
|
||||
};
|
||||
activatePackage(flagFix);
|
||||
|
||||
|
||||
function DefaultGame::flagColTest(%game, %flag){
|
||||
//flag ceiling check
|
||||
%curPos = %flag.getWorldBoxCenter();
|
||||
if( !%flag.isHome ){
|
||||
%flag.stuckChkTimer += $flagSimTime;
|
||||
if(%flag.stuckChkTimer > $flagStuckTime){ // rate limit are checks
|
||||
if(vectorLen(%flag.getVelocity()) < 2){ // only check if we are not at speed
|
||||
%fpos = %flag.getPosition();
|
||||
//0.1 offset any fp errors with the flag position being at ground level, 2.4 offset flag height offset + some extra
|
||||
%upRay = containerRayCast(vectorAdd(%fpos,"0 0 0.1"), vectorAdd(%fpos,"0 0 2.4"), $TypeMasks::InteriorObjectType | $TypeMasks::StaticTSObjectType | $TypeMasks::ForceFieldObjectType, %flag);
|
||||
if(%upRay){
|
||||
%dist = vectorDist(%fpos,getWords(%upRay,1,3));
|
||||
//error(%dist);
|
||||
%flag.setPosition(vectorSub(%fpos,"0 0" SPC (2.5 - %dist)));
|
||||
if($antiCeiling){
|
||||
%flag.stuckChkTimer += $flagSimTime;
|
||||
if(%flag.stuckChkTimer > $flagStuckTime){ // rate limit are checks
|
||||
if(vectorLen(%flag.getVelocity()) < 2){ // only check if we are not at speed
|
||||
%fpos = %flag.getPosition();
|
||||
//0.1 offset any fp errors with the flag position being at ground level, 2.4 offset flag height offset + some extra
|
||||
%upRay = containerRayCast(vectorAdd(%fpos,"0 0 0.1"), vectorAdd(%fpos,"0 0 2.4"), $TypeMasks::InteriorObjectType | $TypeMasks::StaticTSObjectType | $TypeMasks::ForceFieldObjectType, %flag);
|
||||
if(%upRay){
|
||||
%dist = vectorDist(%fpos,getWords(%upRay,1,3));
|
||||
%flag.setTransform(vectorSub(%fpos,"0 0" SPC (2.5 - %dist)) SPC getWords(%flag.getTransform(), 3, 6));
|
||||
}
|
||||
}
|
||||
%flag.stuckChkTimer = 0;
|
||||
}
|
||||
}
|
||||
if($antiTerTunnel){
|
||||
// anti flag tunneling on terrain
|
||||
if(%flag.lastUpdate > 0 && (getSimTime() - %flag.lastUpdate) < 128){//make sure are last position is current
|
||||
%terRay = containerRayCast(%flag.dtLastPos, %curPos, $TypeMasks::TerrainObjectType, %flag);
|
||||
if(%terRay){
|
||||
%curPos = vectorAdd(getWords(%terRay,1,3), "0 0 0.5");
|
||||
%flag.setTransform(%curPos SPC getWords(%flag.getTransform(), 3, 6));
|
||||
}
|
||||
}
|
||||
%flag.stuckChkTimer = 0;
|
||||
%flag.lastUpdate = getSimTime();
|
||||
%flag.dtLastPos = %curPos;
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//flag collision check
|
||||
%Box2 = %flag.getWorldBox();
|
||||
InitContainerRadiusSearch( %flag.getWorldBoxCenter(), $flagCheckRadius, $TypeMasks::PlayerObjectType);
|
||||
InitContainerRadiusSearch( %curPos, $flagCheckRadius, $TypeMasks::PlayerObjectType);
|
||||
while((%player = containerSearchNext()) != 0){
|
||||
%playerPos = %player.getPosition();
|
||||
if(%player.lastSim > 0 && (%player.getState() !$= "Dead")){// only check at speed
|
||||
if((getSimTime() - %player.lastSim) <= 256){//make sure are last position is valid
|
||||
if((getSimTime() - %player.lastSim) <= 128){//make sure are last position is valid
|
||||
%sweepCount = mFloor(vectorDist(%playerPos, %player.oldPos) + 1);
|
||||
for(%i = 0; %i < %sweepCount; %i++){// sweep behind us to see if we should have hit something
|
||||
%lerpPos = vectorLerp(%playerPos, %player.oldPos, (%i+1)/%sweepCount);//back sweep
|
||||
|
|
@ -96,7 +181,7 @@ function DefaultGame::flagColTest(%game, %flag){
|
|||
%player.oldPos = %playerPos;
|
||||
%player.lastSim = getSimTime();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function vectorLerp(%point1, %point2, %t) {
|
||||
return vectorAdd(%point1, vectorScale(vectorSub(%point2, %point1), %t));
|
||||
|
|
@ -119,3 +204,19 @@ function DefaultGame::atHomeFlagLoop(%game){
|
|||
if(isObject(Game) && $missionRunning && $ftEnable)
|
||||
%game.flagLoop = %game.schedule(%speed, "atHomeFlagLoop");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//original flag impluse fix
|
||||
//dont use this function, it likes to ue im leaving this here just as a reminder
|
||||
//also note flag gains velocity from things when not in play aka at stand or on a player backs
|
||||
//if this is ever used that built up velocity needs to be zeroed out when it not in play
|
||||
//function Item::applyImpulse(%this, %position, %impulseVec){
|
||||
//%data = %this.getDatablock();
|
||||
//%x = getWord(%impulseVec, 0) / %data.mass;
|
||||
//%y = getWord(%impulseVec, 1) / %data.mass;
|
||||
//%z = getWord(%impulseVec, 2) / %data.mass;
|
||||
//%vel = %x SPC %y SPC %z;
|
||||
//%this.setVelocity(vectorAdd(%this.getVelocity(), %vel));
|
||||
//}
|
||||
|
|
|
|||
Loading…
Reference in a new issue