exec("./load_functions.cs"); exec("./commands.cs"); function fxDTSBrick::getTopBrick(%this) { %upbrick = %this; while(isObject(%upbrick.getUpBrick(0))) { %upbrick = %upbrick.getUpBrick(0); } return %upbrick; } function setRequiredTrackBricks() { // eventually get around to setting a specific color for track bricks via track info for(%i=0;%i= %required_amount) { %this.hasTouched = ""; %this.touchedCount = 0; %this.lapTime[%this.laps] = getSimTime() - %this.startedLap; if(%this.laps >= $Racing::Laps) { %client = %this.getControllingClient(); messageAll('',"\c3" @ %client.name SPC "\c6has finished in\c3" SPC getPositionString(%this.getApproximatePosition()) SPC "\c6with a time of\c3" SPC getTimeString((getSimTime() - $Racing::StartedAt)/1000) @ "\c6!"); %this.inRace = 0; $Racing::Finished++; $DefaultMinigame.checkToEnd(); // YEAH EXPLOSIONS %this.schedule(100,finalExplosion); } if(isObject(%this)) { %this.laps++; %this.startedLap = getSimTime(); talk("LAP" SPC %this.laps SPC %this.getControllingClient().name); } } } } // really the only reason why this is here is to "predict" race positions and prevent you lame cheaters from cheating } function MinigameSO::checkToEnd(%this) { for(%i=0;%i<%this.numMembers;%i++) { %mem = %this.member[%i]; if(isObject(%mem.player)) { if(%mem.player.inRace) { %not_finished++; } } } if(!%not_finished) { %this.messageAll('',"End of round" SPC $SK::ResetCount @ ". A new round will begin in 8 seconds."); %this.schedule(8000,reset); } } function Vehicle::getApproximatePosition(%this) { for(%i=0;%i<$DefaultMinigame.numMembers;%i++) { %client = $DefaultMinigame.member[%i]; if(isObject(%client.player)) { if(%client.player.totalTouchedCount >= %this.touchedCount && %client != %this.getControllingClient()) { %pos++; } } } return %pos + 1 + $Racing::Finished; } function getPositionString(%num) { if(strLen(%num)-2 >= 0) { %ident = getSubStr(%num,strLen(%num)-2,2); } else { %ident = %num; } if(%ident >= 10 && %ident < 20) { return %num @ "th"; } %ident = getSubStr(%num,strLen(%num)-1,1); switch(%ident) { case 1: return %num @ "st"; case 2: return %num @ "nd"; case 3: return %num @ "rd"; default: return %num @ "th"; } } function GameConnection::doStatLoop(%this) { cancel(%this.statLoop); %this.statLoop = %this.schedule(100,doStatLoop); %player = %this.player; %time[1] = getSimTime() - %player.startedLap; %time[2] = getSimTime() - $Racing::StartedAt; for(%i=1;%i<=2;%i++) { if(strLen(%time[%i])-3 >= 0) { %time_ms[%i] = getSubStr(%time[%i],strLen(%time[%i])-3,1); } if(%time_ms[%i] $= "") { %time_ms[%i] = 0; } } %str[1] = "" @ getPositionString(%this.player.getApproximatePosition()); %str[2] = "Lap" SPC %this.player.laps SPC "/" SPC $Racing::Laps; %str[3] = "" @ getTimeString(mFloor(%time[2]/1000)) @ "." @ %time_ms[2] @ " [" @ getTimeString(mFloor(%time[1]/1000)) @ "." @ %time_ms[1] @ "]"; %this.bottomPrint(%str[1] @ %str[2] SPC "\c7::" SPC %str[3],1,1); //%this.bottomPrint(%time); } function MinigameSO::startRace(%this) { if($Racing::HasStarted) { return; } %this.centerPrintAll("\c2GO!",3); $Racing::HasStarted = 1; $Racing::Finished = 0; $Racing::StartedAt = getSimTime(); for(%i=0;%i<%this.numMembers;%i++) { %client = %this.member[%i]; if(isObject(%client.player)) { %player = %client.player; for(%j=0;%j<4;%j++) { %player.setWheelPowered(%j,1); } %player.doBrickCheckLoop(); %client.doStatLoop(); %player.startedLap = getSimTime(); } } } package GoKartPackage { function WheeledVehicleData::onAdd(%data,%obj) { Parent::onAdd(%data, %obj); //making sure of things %obj.lastTouched = ""; %obj.lastTransform = ""; %obj.laps = 1; %obj.touchedCount = 0; %obj.totalTouchedCount = 0; %obj.hasTouched = ""; %obj.lastTransform = %obj.getTransform(); } function VehicleData::onEnterLiquid(%data, %obj, %coverage, %type) { if(%obj.lastTransform !$= "") { echo("LAST TRANSFORM EXISTS"); %rot = getWord(%obj.lastTransform,6); %obj.setVelocity("0 0 0"); %obj.setTransform(getWords(%obj.lastTransform,0,2) SPC "0 0 1" SPC %rot); %obj.setVelocity("0 0 0"); } else { // something has gone wrong, just explode them. echo("LAST TRANSFORM DOES NOT EXIST"); %obj.damage(%obj,%obj.getPosition(),10000,$DamageType::Lava); $DefaultMinigame.checkToEnd(); } Parent::onEnterLiquid(%data, %obj, %coverage, %type); } function GameConnection::spawnPlayer(%this) { parent::spawnPlayer(%this); if(isObject(%this.minigame)) { if(!$Racing::HasStarted) { if(%this.vehicleType $= "") { %type = "SpeedKartclassicgtVehicle"; } else { %type = %this.vehicleType; } for(%i=1;%i<=42;%i++) { %brick = "_vehicle_spawn" @ %i; if(!%brick.isUsed) { %this.spawnBrick = %brick; %brick.isUsed = 1; if(!%brick.vehicle) { %brick.setVehicle(%type.getID()); if(!isObject(%brick.vehicle)) { %brick.respawnVehicle(); } } else { %brick.respawnVehicle(); } %this.player.delete(); %this.player = %brick.vehicle; %brick.vehicle.inRace = 1; $Racing::PlayerAmount++; %this.setControlObject(%brick.vehicle); if(%this.vehicleColor !$= "") { %this.player.schedule(100,setNodeColor,"ALL",%this.vehicleColor); } else { %this.player.schedule(100,setNodeColor,"ALL",getRandom(0,100)/100 SPC getRandom(0,100)/100 SPC getRandom(0,100)/100 SPC "1"); } return; } else { if(isObject(%brick)) { if(%this.spawnBrick.getID() == %brick.getID()) { if(!%brick.vehicle) { %brick.setVehicle(%type.getID()); if(!isObject(%brick.vehicle)) { %brick.respawnVehicle(); } } else { %brick.respawnVehicle(); } %this.player.delete(); %this.player = %brick.vehicle; %brick.vehicle.inRace = 1; $Racing::PlayerAmount++; %this.setControlObject(%brick.vehicle); if(%this.vehicleColor !$= "") { %this.player.schedule(100,setNodeColor,"ALL",%this.vehicleColor); } else { %this.player.schedule(100,setNodeColor,"ALL",getRandom(0,100)/100 SPC getRandom(0,100)/100 SPC getRandom(0,100)/100 SPC "1"); } return; } } } } } else { %camera = %this.Camera; %camera.setFlyMode(); %camera.mode = "Observer"; %this.setControlObject(%camera); } } } function Vehicle::finalExplosion(%this) { //%this.dump(); echo("EXPLOSION CALLED"); %this.spawnBrick.isUsed = 0; %client = %this.getControllingClient(); if(isObject(%client)) { echo("CLIENT EXISTS:" SPC %client SPC %client.getClassName() SPC %client.getName()); cancel(%client.statLoop); %camera = %client.Camera; %camera.setFlyMode(); %camera.mode = "Observer"; %client.setControlObject(%camera); %client.spawnBrick = ""; if(isObject(%client.minigame)) { $Racing::PlayerAmount--; } } else { echo("CLIENT DOESN'T EXIST"); } parent::finalExplosion(%this); } function serverCmdSuicide(%this) { if(isObject(%this.minigame)) { %this.player.damage(%this.player,%this.player.getPosition(),10000,$DamageType::Lava); $DefaultMinigame.checkToEnd(); messageAll('',"" SPC %this.name); } } function MinigameSO::Reset(%this,%client) { $Racing::HasStarted = 0; $Racing::PlayerAmount = 0; parent::Reset(%this,%client); if(!$SK::MapChange) { //looks like i have to force respawn everyone? %this.respawnAll(); messageAll('',"\c6The race will start in 12 seconds."); %this.schedule(10000,centerPrintAll,"\c0Ready?"); %this.schedule(11000,centerPrintAll,"\c3Set?"); %this.schedule(12000,startRace); } } function GameConnection::onClientLeaveGame(%this) { $Racing::PlayerAmount--; return parent::onClientLeaveGame(%this); } }; activatePackage(GoKartPackage);