// // // D_F_A Guard 1.0 // // ------------- // // by c-middia // // based on // // Surface to Air Missile // // By LucifeR // // Lucifer@vgames.co.il // #include #define COLOR_GREEN 0x00AA00AA #define COLOR_RED 0xFF0000AA #define MAX_D_F_A 3 new D_F_A[MAX_PLAYERS][MAX_D_F_A]; new D_F_A_T[MAX_PLAYERS][MAX_D_F_A]; new D_F_A_M[MAX_PLAYERS]; new D_F_A_I[MAX_PLAYERS]; new D_F_A_re[MAX_PLAYERS]; new D_F_A_timervar; //new target[MAX_PLAYERS]; new playername[256], tmp[256], cmd[256]; new sendername[MAX_PLAYER_NAME]; new giveplayer[MAX_PLAYER_NAME]; //new giveplayerid[MAX_PLAYER_NAME]; new giveplayerid, idx; new string2[256]; forward D_F_A_timer(); forward D_F_A_lunch(playerid); forward D_F_A_go(playerid, num); forward D_F_A_relunch(playerid); forward SendPlayerFormattedText(playerid, const str[], define); forward SendAllFormattedText(playerid, const str[], define); public OnFilterScriptInit() { printf(" _ _ "); printf(" ( ) _ _ ____ _ ___ ____| \\_ "); printf(" | | | | | |/ ___|(_)/ __|/ __ | \\ \\ "); printf(" | | | | | | | | | |_ / / /_/ / / "); printf(" | |____| |_| | |___ | | _| |___ | | \\ "); printf(" |______\\_____/\\____||_|_| \\____|| |\\ \\ "); printf(" D_F_A guard"); printf(" D_F_A convesion by c-middia "); D_F_A_timervar = SetTimer("D_F_A_timer", 100, 1); return 1; } public OnFilterScriptExit() { return 1; } public OnPlayerConnect(playerid) { D_F_A_setup(playerid); return 1; } public OnPlayerDisconnect(playerid, reason) { return 1; } public OnPlayerSpawn(playerid) { D_F_A_setup(playerid); // target[giveplayerid] = 0; return 1; } public OnPlayerDeath(playerid) { D_F_A_setup(playerid); // target[giveplayerid] = 0; return 1; } public OnPlayerCommandText(playerid, cmdtext[]) { if((strcmp(cmdtext, "/D_F_A on", true) == 0) && (IsPlayerAdmin(playerid))) { new tmpstr[256]; GetPlayerName(playerid, playername, MAX_PLAYER_NAME); D_F_A_timervar = SetTimer("D_F_A_timer", 500, 1); format(tmpstr, 256, " ***** D_F_A system activated by %s!", playername); for(new i=0; i <= MAX_PLAYERS; i++) { SendClientMessage(i, COLOR_RED, tmpstr); } return 1; } if((strcmp(cmdtext, "/D_F_A off", true) == 0) && (IsPlayerAdmin(playerid))) { new tmpstr[256]; GetPlayerName(playerid, playername, MAX_PLAYER_NAME); KillTimer(D_F_A_timervar); format(tmpstr, 256, " ****** D_F_A system has been disabled by %s!", playername); for(new i=0; i <= MAX_PLAYERS; i++) { SendClientMessage(i, COLOR_GREEN, tmpstr); } return 1; } if((strcmp(cmdtext, "/D_F_A", true) == 0) && (IsPlayerAdmin(playerid))) { SendClientMessage(playerid, 0xFFFFFFFF, "usage: /D_F_A [on/off]"); return 1; } if(strcmp(cmd, "/dfa", true) == 0 && IsPlayerAdmin(playerid) == 1) { // new cmd[256]; // new idx; tmp = strtok(cmdtext, idx); if(!strlen(tmp)) { SendClientMessage(playerid, COLOR_RED, "USAGE: /uaj [playerid]"); return 1; } cmd = strtok(cmdtext, idx); giveplayerid = strval(tmp); if(IsPlayerConnected(giveplayerid) && IsPlayerAdmin(playerid) == 1) { GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer)); GetPlayerName(playerid, sendername, sizeof(sendername)); D_F_A_M[giveplayerid] = 1; D_F_A_lunch(giveplayerid); format(string2, sizeof(string2), "%s (id: %d) ADMIN launched a missile at %s (id: %d).", sendername,playerid,giveplayer,giveplayerid); printf(string2); format(string2, sizeof(string2), "%s (id: %d) is a target.", giveplayer,giveplayerid); SendClientMessage(playerid, COLOR_RED, string2); format(string2, sizeof(string2), "Launched by %s (id: %d).", sendername,playerid); SendClientMessage(giveplayerid, COLOR_GREEN, string2); } else { format(string2, sizeof(string2), "%d is not an active player.", giveplayerid); SendClientMessage(playerid, COLOR_RED, string2); } return 1; } return 0; } //enum D_F_A_ar//setupfloats //{ //Float:minX, //Float:minY, //Float:minZ, //Float:maxX, //Float:maxY, //Float:maxZ //} new Float:D_F_Aarea [6] = {-4000.0,-4000.0,-25.0,4000.0,4000.0,1500.0}; public D_F_A_timer() { for(new playerid=0; playerid <= MAX_PLAYERS; playerid++) if(D_F_A_M[playerid] == 0 && IsPlayerConnected(playerid) && isPlayerInArea(playerid, D_F_Aarea)) { if(D_F_A_M[playerid] == 0) { // D_F_A_M[playerid] = 1; // D_F_A_lunch(playerid); } } } D_F_A_setup(playerid) { D_F_A_re[playerid] = 0; D_F_A_M[playerid]=0; for(new i=(MAX_D_F_A-1); i <= 0; i++) { if(D_F_A[playerid][i] != 0 && IsValidObject(D_F_A[playerid][i])) { DestroyObject(D_F_A[playerid][i]); } D_F_A[playerid][i] = 0; D_F_A_T[playerid][i] = 0; } } public D_F_A_lunch(playerid) { // GetPlayerTeam(playerid); // if(D_F_A_M[playerid] != (IsPlayerAdmin(playerid)) && D_F_A_M[playerid] == 1 && !(D_F_A[playerid][0] > 0))// if(D_F_A_M[playerid] == 1 && !(D_F_A[playerid][0] > 0))//TEAM_ARMY { D_F_A[playerid][0] = CreateObject(3790, -0.0, 0.0, 10000.0, 0.0, 30.0, 270.0); D_F_A_T[playerid][0] =SetTimerEx("D_F_A_go", 100, 1, "d d", playerid, 0); CreateExplosion(14.939204, 1720.225097, 24.630422, 4, 1); } } public D_F_A_go(playerid, num) { new Float:ox,Float:oy,Float:oz; GetObjectPos(D_F_A[playerid][num], ox, oy, oz); if(isPlayerNearPos(playerid, ox, oy, oz, 1)) { KillTimer(D_F_A_T[playerid][num]); CreateExplosion(ox, oy, oz, 7, 2); CreateExplosion(ox, oy, oz, 7, 2); DestroyObject(D_F_A[playerid][num]); D_F_A[playerid][num] = 0; RemovePlayerMapIcon(playerid, D_F_A_I[playerid]); SetTimerEx("D_F_A_relunch", 3000, 0, "d", playerid); D_F_A_re[playerid] = 1; if(!IsPlayerConnected(playerid)) { KillTimer(D_F_A_T[playerid][num]); DestroyObject(D_F_A[playerid][num]); D_F_A[playerid][num] = 0; RemovePlayerMapIcon(playerid, D_F_A_I[playerid]); D_F_A_re[playerid] = 0; } } else { new Float:px,Float:py,Float:pz; GetPlayerPos(playerid, px, py, pz); MoveObject(D_F_A[playerid][num], px, py, pz, 60); SetObjectToFaceCords(D_F_A[playerid][num], px, py, pz); D_F_A_M[playerid]-=1; PlayerPlaySound(playerid, 1057, px, py, pz); RemovePlayerMapIcon(playerid, D_F_A_I[playerid]); SetPlayerMapIcon(playerid, D_F_A_I[playerid], ox, oy, oz, 0, COLOR_RED); if(!IsPlayerConnected(playerid)) { KillTimer(D_F_A_T[playerid][num]); DestroyObject(D_F_A[playerid][num]); D_F_A[playerid][num] = 0; RemovePlayerMapIcon(playerid, D_F_A_I[playerid]); D_F_A_re[playerid] = 0; } } } //public D_F_A_relunch(playerid) //{ // new Float:h; // GetPlayerHealth(playerid, h); // if(h > 0 && D_F_A_re[playerid] == 1) // D_F_A_lunch(playerid); // // D_F_A_re[playerid] = 0; //} SetObjectToFaceCords(objectid, Float:x1,Float:y1,Float:z1) { // SetObjectToFaceCords() By LucifeR // // LucifeR@vgames.co.il // // setting the objects cords new Float:x2,Float:y2,Float:z2; GetObjectPos(objectid, x2,y2,z2); // setting the distance values new Float:DX = floatabs(x2-x1); new Float:DY = floatabs(y2-y1); new Float:DZ = floatabs(z2-z1); // defining the angles and setting them to 0 new Float:yaw = 0; new Float:pitch = 0; // check that there isnt any 0 in one of the distances, // if there is any use the given parameters: if(DY == 0 || DX == 0) { if(DY == 0 && DX > 0) { yaw = 00; pitch = 0; } else if(DY == 0 && DX < 0) { yaw = 180; pitch = 180; } else if(DY > 0 && DX == 0) { yaw = 90; pitch = 90; } else if(DY < 0 && DX == 0) { yaw = 270; pitch = 270; } else if(DY == 0 && DX == 0) { yaw = 0; pitch = 0; } } // calculating the angale using atan else // non of the distances is 0. { // calculatin the angles yaw = atan(DX/DY); pitch = atan(floatsqroot(DX*DX + DZ*DZ) / DY); // there are three quarters in a circle, now i will // check wich circle this is and change the angles // according to it. if(x1 > x2 && y1 <= y2) { yaw = yaw + 90; pitch = pitch - 45; } else if(x1 <= x2 && y1 < y2) { yaw = 90 - yaw; pitch = pitch - 45; } else if(x1 < x2 && y1 >= y2) { yaw = yaw - 90; pitch = pitch - 45; } else if(x1 >= x2 && y1 > y2) { yaw = 270 - yaw; pitch = pitch + 315; } // the pitch could be only in two quarters, lets see wich one: if(z1 < z2) pitch = 360-pitch; } // setting the object rotation (should be twice cuz of lame GTA rotation system) SetObjectRot(objectid, 0, 0, yaw); SetObjectRot(objectid, 0, pitch, yaw); } isPlayerNearPos(playerID, Float:x, Float:y, Float:z, c) { new Float:PX, Float:PY, Float:PZ; GetPlayerPos(playerID, PX, PY, PZ); if((x-c < PX) && (x+c > PX) && (y-c < PY) && (y+c > PY) && (z-c < PZ) && (z+c > PZ)) { return 1; } return 0; } isPlayerInArea(playerID, Float:data[6]) { new Float:X, Float:Y, Float:Z; GetPlayerPos(playerID, X, Y, Z); if(X >= data[0] && X <= data[3] && Y >= data[1] && Y <= data[4] && Z >= data[2] && Z <= data[5] ) { return 1; } return 0; } //---------- //--- public SendPlayerFormattedText(playerid, const str[], define) { new tmpbuf[256]; format(tmpbuf, sizeof(tmpbuf), str, define); SendClientMessage(playerid, 0xFFFF00AA, tmpbuf); } public SendAllFormattedText(playerid, const str[], define) { new tmpbuf[256]; format(tmpbuf, sizeof(tmpbuf), str, define); SendClientMessageToAll(0xFFFF00AA, tmpbuf); } strtok(const string[], &index) { new length = strlen(string); while ((index < length) && (string[index] <= ' ')) { index++; } new offset = index; new result[20]; while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1))) { result[index - offset] = string[index]; index++; } result[index - offset] = EOS; return result; } //--