#include #define dcmd(%1,%2) if ((strcmp(cmdtext, "/%1", true, %2 + 1) == 0) && (((cmdtext[%2 + 1] == 0) && (dcmd_%1(playerid, ""))) || ((cmdtext[%2 + 1] == 32) && (dcmd_%1(playerid, cmdtext[%2 + 2]))))) return 1 //#define FILTERSCRIPT #define NO_FLAG_BEARER_VEHICLE #define TEAM_GREEN 1 #define TEAM_BLUE 2 #define ARMY_SKIN 45 #define SWAT_SKIN 46 #define WINNING_CAPS 3 new gCounts[2] = {0, 0}; new gTeam[MAX_PLAYERS] = {0, ...}; new gFlagDown = 0; new gBearer[2] = {INVALID_PLAYER_ID, INVALID_PLAYER_ID}; new gResetTimer[2] = {0, 0}; new gCaps[2] = {0, 0}; new gDead[MAX_PLAYERS] = {0, ...}; new Float:fBase[2][3] = { {-973.8201, 1023.9193, 1345.0474}, {-1131.8019, 1094.9739, 1345.7908} }; new Float:gSpawn[2][3][4] = { { {-969.5423, 1049.2847, 1345.0519, 3.9370}, {-970.4763, 1097.6680, 1344.9984, 157.6807}, {-978.8046, 1053.0897, 1344.9847, 2.3937} }, { {-1136.4941, 1069.9429, 1345.7972, 179.4053}, {-1135.7235, 1020.3143, 1345.7455, 316.8555}, {-1127.5035, 1065.6715, 1345.7352, 185.3821} } }; new Float:fFlagPos[2][3]; //new gRespawnCount[MAX_PLAYERS]; #if defined FILTERSCRIPT public OnFilterScriptInit() { print("\n===================================="); print("| |"); print("| Blank Filter Script! |"); print("| ---------------------- |"); print("| |"); print("| By Alex \"Y_Less\" Cole - (c) 2006 |"); print("| |"); print("====================================\n"); return 1; } public OnFilterScriptExit() { return 1; } #else main() { print("\n===================================="); print("| |"); print("| Small Soldiers CTF |"); print("| -------------------- |"); print("| |"); print("| By Alex \"Y_Less\" Cole - (c) 2006 |"); print("| |"); print("====================================\n"); } #endif forward GameLoop(); //forward Respawn(playerid); forward ResetFlag(team); forward EndMode(); public OnGameModeInit() { SetGameModeText("Small Soldiers CTF"); /*AddPlayerClass(137,-969.5423,1049.2847,1345.0519,3.9370,0,0,0,0,0,0); // war 1 1 AddPlayerClass(137,-970.4763,1097.6680,1344.9984,157.6807,0,0,0,0,0,0); // war 1 2 AddPlayerClass(137,-978.8046,1053.0897,1344.9847,2.3937,0,0,0,0,0,0); // war 1 3*/ AddPlayerClass(0, 0.0, 0.0, 0.0, 0.0, 3, 1, 22, 100, 27, 21); // Shotgun AddPlayerClass(0, 0.0, 0.0, 0.0, 0.0, 3, 1, 22, 100, 29, 150); // MP5 AddPlayerClass(0, 0.0, 0.0, 0.0, 0.0, 3, 1, 22, 100, 16, 20); // Grenades ResetFlag(TEAM_GREEN); ResetFlag(TEAM_BLUE); SetTimer("GameLoop", 50, 1); ShowPlayerMarkers(0); return 1; } public OnGameModeExit() { return 1; } public GameLoop() { if (gCaps[0] == WINNING_CAPS || gCaps[1] == WINNING_CAPS) return; //new team; for (new i = 1; i <= 2; i++) // Put team flags on carriers backs { if (!(gFlagDown & i)) { new playerid = gBearer[i - 1]; if (playerid == INVALID_PLAYER_ID || !IsPlayerConnected(playerid)) { DropFlag(i - 1); } else { new Float:x, Float:y, Float:z, Float:a; GetPlayerPos(playerid, x, y, z); GetPlayerFacingAngle(playerid, a); SetFlag(i - 1, x + (-0.2 * floatsin(-a, degrees)), y + (-0.2 * floatcos(-a, degrees)), z, a); } } } // Do the next section less frequently (four times less frequently) static loops = 0; loops++; if (loops >= 4) loops = 0; else return; /*new str[26]; format(str, sizeof (str), "~g~Green %d~w~:~b~%d Blue", gCaps[0], gCaps[1]); GameTextForAll(str, 3000, 1);*/ if (!gFlagDown) return; // No point checking if there's nothing to check for (new i = 0; i < MAX_PLAYERS; i++) { if (IsPlayerConnected(i)) { // If they're in a vehicle go to the next player. if (gDead[i]) continue; if (IsPlayerInAnyVehicle(i)) continue; new team = gTeam[i]; // See if we need to check for the flag for this team. if (gFlagDown & team) { team--; // Are they on their flag? if (IsPlayerNearPoint(i, fFlagPos[team][0], fFlagPos[team][1], fFlagPos[team][2])) { //print("1"); // They picked up the flag. gFlagDown -= team + 1; // Mark it as picked up. //print("2"); //DestroyObject(gFlagObj[team]); SetPlayerCheckpoint(i, fBase[team][0], fBase[team][1], fBase[team][2], 2.0); GameTextForPlayer(i, "~g~You have the flag, return to base!", 5000, 3); GameTextForTeam(team ^ 1, "~r~The enemy has your flag!", 5000, 3); //print("3"); // Make the bearer visible on the map SetPlayerObjectiveForAll(i, 1); //print("4"); gBearer[team] = i; //print("5"); HideFlag(team); //print("6"); if (gResetTimer[team]) { //print("7"); KillTimer(gResetTimer[team]); //print("8"); gResetTimer[team] = 0; //print("9"); } } } } } } public EndMode() { GameModeExit(); } /*public Respawn(playerid) { static gCountDown[MAX_PLAYERS] = {5, ...}; if (IsPlayerConnected(playerid)) { if (gCountDown[playerid]) { SetTimerEx("Respawn", 1000, 0, playerid); new str[14]; format(str, sizeof (str), "~r~Respawn in: %d", gCountDown[playerid]); gCountDown[playerid]--; GameTextForPlayer(playerid, str, 1200, 3); } else { TogglePlayerControllable(playerid, 1); SpawnPlayer(playerid); gCountDown[playerid] = 5; } } for (new i = 0; i < MAX_PLAYERS; i++) { if (!IsPlayerConnected(i)) gCountDown[i] = 5; } }*/ IsPlayerNearPoint(playerid, Float:x1, Float:y1, Float:z1) { new Float:x2, Float:y2, Float:z2; GetPlayerPos(playerid, x2, y2, z2); if (floatsqroot(floatpower(x2 - x1, 2.0) + floatpower(y2 - y1, 2.0) + floatpower(z2 - z1, 2.0)) <= 2.0) return 1; return 0; } public ResetFlag(team) //, timer = 1) { //new other = (team ^ 3) - 1; team--; new other = team ^ 1; if (gBearer[team] != INVALID_PLAYER_ID) return; fFlagPos[team][0] = fBase[other][0]; fFlagPos[team][1] = fBase[other][1]; fFlagPos[team][2] = fBase[other][2]; /*if (team == TEAM_BLUE) { fFlagPos[TEAM_BLUE - 1][0] = -973.8201; fFlagPos[TEAM_BLUE - 1][1] = 1023.9193; fFlagPos[TEAM_BLUE - 1][2] = 1345.0474; } else if (team == TEAM_GREEN) { fFlagPos[TEAM_GREEN - 1][0] = -1131.8019; fFlagPos[TEAM_GREEN - 1][1] = 1094.9739; fFlagPos[TEAM_GREEN - 1][2] = 1345.7908; }*/ //DropFlag(team); PlaceFlag(team); } PlaceFlag(index) { //new index = team - 1; gFlagDown |= (index + 1); //print("1"); for (new i = 0; i < MAX_PLAYERS; i++) { if (IsPlayerConnected(i) /*&& gTeam[i] == team*/) { SetPlayerMapIcon(i, index, fFlagPos[index][0], fFlagPos[index][1], fFlagPos[index][2], 0, 97); } } SetFlag(index, fFlagPos[index][0], fFlagPos[index][1], fFlagPos[index][2], 0.0); //print("2"); if (gBearer[index] != INVALID_PLAYER_ID) { SetPlayerObjectiveForAll(gBearer[index], 0); gBearer[index] = INVALID_PLAYER_ID; } //print("3"); //if (drop) //{ } SetFlag(index, Float:x, Float:y, Float:z, Float:a, destroy = 0) { static flags[2]; if (destroy) { DestroyObject(flags[0]); DestroyObject(flags[1]); } if (!IsValidObject(flags[index])) { flags[index] = CreateObject(1233, x, y, z, 0.0, 0.0, a); } else { SetObjectPos(flags[index], x, y, z); // 0.0, 0.0, 5.0); SetObjectRotation(flags[index], 0.0, 0.0, a); } } HideFlag(index) { for (new i = 0; i < MAX_PLAYERS; i++) { if (IsPlayerConnected(i)) RemovePlayerMapIcon(i, index); } } DropFlag(team) { GameTextForTeam(team, "~r~You Dropped The Enemy Flag!~n~Reset in - 30 s", 5000, 3); GameTextForTeam(team ^ 3, "~g~The Enemy Dropped Your Flag!~n~Reset in - 30 s", 5000, 3); team--; //new index = team ^ 1; GetPlayerPos(gBearer[team], fFlagPos[team][0], fFlagPos[team][1], fFlagPos[team][2]); fFlagPos[team][2] += 2.0; DisablePlayerCheckpoint(gBearer[team]); //print("place"); PlaceFlag(team); //print("place"); //gBearer[team] = INVALID_PLAYER_ID; gResetTimer[team] = SetTimerEx("ResetFlag", 30000, 0, team + 1); //print("place"); } SetPlayerObjectiveForAll(playerid, toggle) { for (new i = 0; i < MAX_PLAYERS; i++) { if (IsPlayerConnected(i)) SetPlayerMarker(i, playerid, toggle); } } GameTextForTeam(team, text[], time, type) { for (new i = 0; i < MAX_PLAYERS; i++) { if (IsPlayerConnected(i) && gTeam[i] == team) GameTextForPlayer(i, text, time, type); } } public OnPlayerRequestClass(playerid, classid) { SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746); SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746); SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746); return 1; } public OnPlayerConnect(playerid) { if (gCounts[0] < gCounts[1]) { gCounts[0]++; gTeam[playerid] = TEAM_GREEN; } else { gCounts[1]++; //printf("%d", playerid); gTeam[playerid] = TEAM_BLUE; } //printf("%d", playerid); SetPlayerColor(playerid, 0xFFFFFFAA); return 1; } public OnPlayerDisconnect(playerid) { new team = gTeam[playerid] - 1; gCounts[team]--; if (gBearer[team] == playerid) DropFlag(team + 1); return 1; } public OnPlayerSpawn(playerid) { new index; index = random(3); if (gTeam[playerid] == TEAM_GREEN) { SetPlayerColor(playerid, 0x00FF00AA); SetPlayerSkin(playerid, ARMY_SKIN); SetPlayerPos(playerid, gSpawn[0][index][0], gSpawn[0][index][1], gSpawn[0][index][2]); SetPlayerFacingAngle(playerid, gSpawn[0][index][3]); } else { SetPlayerColor(playerid, 0x0000FFAA); SetPlayerSkin(playerid, SWAT_SKIN); SetPlayerPos(playerid, gSpawn[1][index][0], gSpawn[1][index][1], gSpawn[1][index][2]); SetPlayerFacingAngle(playerid, gSpawn[1][index][3]); } gDead[playerid] = 0; SetPlayerInterior(playerid, 10); index = (gTeam[playerid] ^ 3) - 1; if (gBearer[index] == INVALID_PLAYER_ID) PlaceFlag(index); if (gBearer[index ^ 1] == INVALID_PLAYER_ID) PlaceFlag(index ^ 1); GameTextForPlayer(playerid, "~g~Capture the flag from the enemys base", 5000, 3); return 1; } public OnPlayerDeath(playerid, killerid, reason) { new team = gTeam[playerid]; if (gBearer[team - 1] == playerid) DropFlag(team); gDead[playerid] = 1; //TogglePlayerControllable(playerid, 0); //SetTimerEx("Respawn", 1000, 0, playerid); return 1; } public OnVehicleSpawn(vehicleid) { return 1; } public OnVehicleDeath(vehicleid, killerid) { return 1; } public OnPlayerText(playerid, text[]) { return 1; } public OnPlayerPrivmsg(playerid, senderid, text[]) { return 1; } public OnPlayerCommandText(playerid, cmdtext[]) { dcmd(mycommand, 9); return 0; } dcmd_mycommand(playerid, text[]) { #pragma unused playerid, text // Do something here return 1; } public OnPlayerInfoChange(playerid) { return 1; } public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger) { //new team = gTeam[playerid] - 1; //if (gBearer[team] == playerid) DropFlag(team); return 1; } public OnPlayerExitVehicle(playerid, vehicleid) { return 1; } public OnPlayerStateChange(playerid, newstate, oldstate) { //print("hi"); if (newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER) { new team = gTeam[playerid] - 1; if (gBearer[team] == playerid) DropFlag(team + 1); } return 1; } public OnPlayerEnterCheckpoint(playerid) { new team = gTeam[playerid]; // - 1; gBearer[team - 1] = INVALID_PLAYER_ID; gCaps[team - 1]++; DisablePlayerCheckpoint(playerid); if (gCaps[team - 1] != WINNING_CAPS) { ResetFlag(team); new str[60]; format(str, sizeof (str), "~g~We captured the enemy flag!~n~~g~Green %d~w~:~b~%d Blue", gCaps[0], gCaps[1]); GameTextForTeam(team, str, 5000, 3); format(str, sizeof (str), "~r~The enemy captured out flag!~n~~g~Green %d~w~:~b~%d Blue", gCaps[0], gCaps[1]); GameTextForTeam(team ^ 3, str, 5000, 3); } else { GameTextForTeam(team, "~g~You have won!~n~Mode end in 5 seconds", 5000, 3); GameTextForTeam(team ^ 3, "~r~You have lost!~n~Mode end in 5 seconds", 5000, 3); if (gFlagDown & 1) HideFlag(0); if (gFlagDown & 2) HideFlag(1); SetFlag(0, 0.0, 0.0, 0.0, 0.0, 1); if (gBearer[(team - 1) ^ 1] != INVALID_PLAYER_ID) { DisablePlayerCheckpoint(gBearer[(team - 1) ^ 1]); } SetTimer("EndMode", 5000, 0); } // Capture //if (gBearer[team] == playerid) DropFlag(team); return 1; } public OnPlayerLeaveCheckpoint(playerid) { return 1; }