Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Ship wars
- #define FILTERSCRIPT
- #include <a_samp>
- #include <streamer>
- #include <zcmd>
- #define EVENT_WORLD 4 // VW
- #define EVENT_AMMO 5000 // AMMO
- #define EVENT_ICONID 42 // MAPICON
- #define EVENT_LIMIT 100 // MAX PLAYERS
- #define EVENT_DISTANCE 850.0
- #define DEFAULT_SPEED 7.0
- #define WINNER_MONEY 25000 // WINNER MONEY
- #define SHIP_COLOR_RED 0xE74C3CFF // color of red team
- #define SHIP_COLOR_BLUE 0x3498DBFF // color of blue team
- enum e_swteams
- {
- SHIP_RED,
- SHIP_BLUE
- }
- enum e_teaminfo
- {
- ShipObject,
- Float: ShipSpeed,
- TeamPoint
- }
- new
- PlayersInGame,
- ShipTimer = -1,
- bool: GameStarted,
- ShipWarsInfo[2][e_teaminfo],
- ShipTeam[MAX_PLAYERS] = {-1, ...},
- LastFallCheck[MAX_PLAYERS];
- new
- Text: shipText[4],
- PlayerText: shipWithTeamColor[MAX_PLAYERS];
- new
- EventWeapons[] = {WEAPON_DEAGLE, WEAPON_SHOTGSPA, WEAPON_M4, WEAPON_RIFLE};
- stock GivePoints(team, points)
- {
- new point_string[6];
- ShipWarsInfo[team][TeamPoint] += points;
- valstr(point_string, ShipWarsInfo[team][TeamPoint]);
- TextDrawSetString(shipText[ (team == _:SHIP_RED) ? 2 : 3 ], point_string);
- if(ShipWarsInfo[team][TeamPoint] % 5 == 0 && ShipWarsInfo[team][ShipSpeed] < 20.0)
- {
- ShipWarsInfo[team][ShipSpeed] = floatadd(ShipWarsInfo[team][ShipSpeed], 0.75);
- if(ShipWarsInfo[team][ShipSpeed] > 20.0) ShipWarsInfo[team][ShipSpeed] = 20.0;
- new string[96];
- format(string, sizeof(string), "[%s TEAM] Mi dobijamo brzinu, pokusaj ih jos ubiti!", (team == _:SHIP_RED) ? ("Black Pearl Ship") : ("White Pearl Ship"));
- for(new i; i < GetMaxPlayers(); ++i)
- {
- if(!IsPlayerConnected(i)) continue;
- if(ShipTeam[i] == team) SendClientMessage(i, (team == _:SHIP_RED) ? SHIP_COLOR_RED : SHIP_COLOR_BLUE, string);
- }
- StopDynamicObject(ShipWarsInfo[team][ShipObject]);
- MoveDynamicObject(ShipWarsInfo[team][ShipObject], (team == _:SHIP_RED) ? 402.896 : 352.896, floatsub(-2137.920, EVENT_DISTANCE), 17.415, ShipWarsInfo[team][ShipSpeed]);
- }
- return 1;
- }
- stock LeaveGame(playerid, reason = 0)
- {
- if(reason != 1)
- {
- RemovePlayerMapIcon(playerid, EVENT_ICONID);
- ResetPlayerWeapons(playerid);
- SetPlayerTeam(playerid, NO_TEAM);
- SetPlayerVirtualWorld(playerid, 0);
- SpawnPlayer(playerid);
- }
- ShipTeam[playerid] = -1;
- PlayersInGame--;
- if(PlayersInGame < 2 && reason < 2)
- {
- if(GameStarted) SendClientMessageToAll(-1, "[SHIP WARS] Event Zavrsen. (nema dovoljno igraca)");
- ResetGame();
- }
- for(new i; i < sizeof(shipText); ++i) TextDrawHideForPlayer(playerid, shipText[i]);
- PlayerTextDrawHide(playerid, shipWithTeamColor[playerid]);
- PlayerTextDrawDestroy(playerid, shipWithTeamColor[playerid]);
- return 1;
- }
- stock ResetGame(unload = 0)
- {
- for(new i; i < GetMaxPlayers(); ++i)
- {
- if(!IsPlayerConnected(i)) continue;
- if(ShipTeam[i] != -1) LeaveGame(i, 2);
- }
- if(!unload)
- {
- if(ShipTimer != -1)
- {
- KillTimer(ShipTimer);
- ShipTimer = -1;
- }
- GameStarted = false;
- PlayersInGame = 0;
- StopDynamicObject(ShipWarsInfo[SHIP_RED][ShipObject]);
- StopDynamicObject(ShipWarsInfo[SHIP_BLUE][ShipObject]);
- SetDynamicObjectPos(ShipWarsInfo[SHIP_RED][ShipObject], 402.896, -2137.920, 17.415);
- SetDynamicObjectPos(ShipWarsInfo[SHIP_BLUE][ShipObject], 352.896, -2137.920, 17.415);
- ShipWarsInfo[SHIP_RED][ShipSpeed] = DEFAULT_SPEED;
- ShipWarsInfo[SHIP_BLUE][ShipSpeed] = DEFAULT_SPEED;
- ShipWarsInfo[SHIP_RED][TeamPoint] = 0;
- ShipWarsInfo[SHIP_BLUE][TeamPoint] = 0;
- TextDrawSetString(shipText[2], "0");
- TextDrawSetString(shipText[3], "0");
- }
- return 1;
- }
- public OnFilterScriptInit()
- {
- ShipWarsInfo[SHIP_RED][ShipObject] = CreateDynamicObject(8493, 402.896, -2137.920, 17.415, 0.000, 0.000, 180.000, EVENT_WORLD, 0);
- ShipWarsInfo[SHIP_BLUE][ShipObject] = CreateDynamicObject(8493, 352.896, -2137.920, 17.415, 0.000, 0.000, 180.000, EVENT_WORLD, 0);
- SetDynamicObjectMaterial(ShipWarsInfo[SHIP_RED][ShipObject], 2, -1, "none", "none", -1618884);
- SetDynamicObjectMaterial(ShipWarsInfo[SHIP_RED][ShipObject], 3, -1, "none", "none", -1618884);
- SetDynamicObjectMaterial(ShipWarsInfo[SHIP_BLUE][ShipObject], 2, -1, "none", "none", -13330213);
- SetDynamicObjectMaterial(ShipWarsInfo[SHIP_BLUE][ShipObject], 3, -1, "none", "none", -13330213);
- ShipWarsInfo[SHIP_RED][ShipSpeed] = DEFAULT_SPEED;
- ShipWarsInfo[SHIP_BLUE][ShipSpeed] = DEFAULT_SPEED;
- shipText[0] = TextDrawCreate(495.000000, 355.000000, "_");
- TextDrawBackgroundColor(shipText[0], 0);
- TextDrawFont(shipText[0], 5);
- TextDrawLetterSize(shipText[0], 0.500000, 1.000000);
- TextDrawColor(shipText[0], -414434049);
- TextDrawSetOutline(shipText[0], 0);
- TextDrawSetProportional(shipText[0], 1);
- TextDrawSetShadow(shipText[0], 1);
- TextDrawUseBox(shipText[0], 1);
- TextDrawBoxColor(shipText[0], 0);
- TextDrawTextSize(shipText[0], 16.000000, 16.000000);
- TextDrawSetPreviewModel(shipText[0], 1254);
- TextDrawSetPreviewRot(shipText[0], 0.000000, 0.000000, 0.000000, 0.875000);
- TextDrawSetSelectable(shipText[0], 0);
- shipText[1] = TextDrawCreate(495.000000, 375.000000, "_");
- TextDrawBackgroundColor(shipText[1], 0);
- TextDrawFont(shipText[1], 5);
- TextDrawLetterSize(shipText[1], 0.500000, 1.000000);
- TextDrawColor(shipText[1], 882433023);
- TextDrawSetOutline(shipText[1], 0);
- TextDrawSetProportional(shipText[1], 1);
- TextDrawSetShadow(shipText[1], 1);
- TextDrawUseBox(shipText[1], 1);
- TextDrawBoxColor(shipText[1], 0);
- TextDrawTextSize(shipText[1], 16.000000, 16.000000);
- TextDrawSetPreviewModel(shipText[1], 1254);
- TextDrawSetPreviewRot(shipText[1], 0.000000, 0.000000, 0.000000, 0.875000);
- TextDrawSetSelectable(shipText[1], 0);
- shipText[2] = TextDrawCreate(511.000000, 357.000000, "0");
- TextDrawBackgroundColor(shipText[2], 255);
- TextDrawFont(shipText[2], 1);
- TextDrawLetterSize(shipText[2], 0.210000, 1.100000);
- TextDrawColor(shipText[2], -414434049);
- TextDrawSetOutline(shipText[2], 1);
- TextDrawSetProportional(shipText[2], 1);
- TextDrawSetSelectable(shipText[2], 0);
- shipText[3] = TextDrawCreate(511.000000, 377.000000, "0");
- TextDrawBackgroundColor(shipText[3], 255);
- TextDrawFont(shipText[3], 1);
- TextDrawLetterSize(shipText[3], 0.210000, 1.100000);
- TextDrawColor(shipText[3], 882433023);
- TextDrawSetOutline(shipText[3], 1);
- TextDrawSetProportional(shipText[3], 1);
- TextDrawSetSelectable(shipText[3], 0);
- return 1;
- }
- public OnFilterScriptExit()
- {
- for(new i; i < sizeof(shipText); ++i)
- {
- TextDrawHideForAll(shipText[i]);
- TextDrawDestroy(shipText[i]);
- }
- ResetGame(1);
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- ShipTeam[playerid] = -1;
- LastFallCheck[playerid] = 0;
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- if(ShipTeam[playerid] != -1) LeaveGame(playerid, 1);
- return 1;
- }
- public OnPlayerUpdate(playerid)
- {
- if(ShipTeam[playerid] != -1 && LastFallCheck[playerid] < tickcount())
- {
- LastFallCheck[playerid] = tickcount()+500;
- new Float: temp, Float: z;
- GetPlayerPos(playerid, temp, temp, z);
- if(z < 3.0)
- {
- SetPlayerHealth(playerid, -1.0);
- GivePoints((ShipTeam[playerid] == _:SHIP_RED) ? SHIP_BLUE : SHIP_RED, 1);
- }
- }
- return 1;
- }
- public OnPlayerSpawn(playerid)
- {
- if(ShipTeam[playerid] != -1)
- {
- new Float: x, Float: y, Float: z;
- GetDynamicObjectPos(ShipWarsInfo[ ShipTeam[playerid] ][ShipObject], x, y, z);
- SetPlayerVirtualWorld(playerid, EVENT_WORLD);
- SetPlayerPos(playerid, x, y - (-22.22), 9.5);
- SetPlayerTeam(playerid, ShipTeam[playerid]);
- ResetPlayerWeapons(playerid);
- if(GameStarted) for(new i; i < sizeof(EventWeapons); ++i) GivePlayerWeapon(playerid, EventWeapons[i], EVENT_AMMO);
- }
- return 1;
- }
- public OnPlayerDeath(playerid, killerid, reason)
- {
- if(killerid != INVALID_PLAYER_ID && ShipTeam[playerid] != -1 && ShipTeam[killerid] != -1 && ShipTeam[playerid] != ShipTeam[killerid])
- {
- new Float: temp, Float: z;
- GetPlayerPos(playerid, temp, temp, z);
- if(z > 5.0) GivePoints(ShipTeam[killerid], 1);
- }
- return 1;
- }
- public OnDynamicObjectMoved(objectid)
- {
- new team = -1;
- if(objectid == ShipWarsInfo[SHIP_RED][ShipObject]) {
- team = SHIP_RED;
- }else if(objectid == ShipWarsInfo[SHIP_BLUE][ShipObject]) {
- team = SHIP_BLUE;
- }else{
- team = -1;
- }
- if(team == -1) return 1;
- new Float: x, Float: y, Float: z, Float: fin_x = (team == _:SHIP_RED) ? 402.896 : 352.896, Float: fin_y = floatsub(-2137.920, EVENT_DISTANCE);
- GetDynamicObjectPos(objectid, x, y, z);
- new Float: dist = floatsqroot(floatpower(fin_x-x, 2.0) + floatpower(fin_y-y, 2.0));
- if(dist < 10.0)
- {
- if(ShipWarsInfo[SHIP_RED][ShipSpeed] == ShipWarsInfo[SHIP_BLUE][ShipSpeed])
- {
- if(ShipWarsInfo[SHIP_RED][TeamPoint] > ShipWarsInfo[SHIP_BLUE][TeamPoint]) {
- team = SHIP_RED;
- }else if(ShipWarsInfo[SHIP_BLUE][TeamPoint] > ShipWarsInfo[SHIP_RED][TeamPoint]) {
- team = SHIP_BLUE;
- }else if(ShipWarsInfo[SHIP_RED][TeamPoint] == ShipWarsInfo[SHIP_BLUE][TeamPoint]) {
- team = -1;
- }
- }
- new string[128];
- if(team != -1) {
- for(new i; i < GetMaxPlayers(); ++i)
- {
- if(!IsPlayerConnected(i)) continue;
- if(ShipTeam[i] == team)
- {
- GivePlayerMoney(i, WINNER_MONEY);
- }
- }
- format(string, sizeof(string), "[SHIP WARS] Tim %s je pobedio u Ship Wars eventu!", (team == _:SHIP_RED) ? ("Black Pearl Ship") : ("White Pearl Ship"));
- SendClientMessageToAll((team == _:SHIP_RED) ? SHIP_COLOR_RED : SHIP_COLOR_BLUE, string);
- }else{
- SendClientMessageToAll(-1, "[SHIP WARS] Igra je zavrsila nereseno, Cestitke svima na dobroj igri.");
- }
- ResetGame();
- }
- return 1;
- }
- forward StartGame(time, move);
- public StartGame(time, move)
- {
- if(move) {
- SendClientMessageToAll(-1, "[SHIP WARS] Event je pokrenut od strane servera. Za ucesce /shipwars!.");
- MoveDynamicObject(ShipWarsInfo[SHIP_RED][ShipObject], 402.896, floatsub(-2137.920, EVENT_DISTANCE), 17.415, ShipWarsInfo[SHIP_RED][ShipSpeed]);
- MoveDynamicObject(ShipWarsInfo[SHIP_BLUE][ShipObject], 352.896, floatsub(-2137.920, EVENT_DISTANCE), 17.415, ShipWarsInfo[SHIP_BLUE][ShipSpeed]);
- }else{
- if(time > 1) {
- time--;
- new string[54];
- format(string, sizeof(string), "~n~~w~pokretanje ~r~~h~%d ~n~~g~~h~budi spreman!", time);
- for(new i; i < GetMaxPlayers(); ++i)
- {
- if(!IsPlayerConnected(i)) continue;
- if(ShipTeam[i] == -1) continue;
- PlayerPlaySound(i, 1056, 0.0, 0.0, 0.0);
- GameTextForPlayer(i, string, 1000, 3);
- }
- ShipTimer = SetTimerEx("StartGame", 1000, false, "ii", time, 0);
- }else if(time == 1) {
- if(PlayersInGame < 2) {
- SendClientMessageToAll(-1, "[SHIP WARS] Event je zavrsio (Nema dovoljno igraca)");
- ResetGame();
- }else{
- GameStarted = true;
- for(new i; i < GetMaxPlayers(); ++i)
- {
- if(!IsPlayerConnected(i)) continue;
- if(ShipTeam[i] == -1) continue;
- PlayerPlaySound(i, 1057, 0.0, 0.0, 0.0);
- for(new x; x < sizeof(EventWeapons); ++x) GivePlayerWeapon(i, EventWeapons[x], EVENT_AMMO);
- }
- SendClientMessageToAll(-1, "[SHIP WARS] Brodovi ce se poceti kretati za 3sekunde.");
- ShipTimer = SetTimerEx("StartGame", 3000, false, "ii", 0, 1);
- }
- }
- }
- return 1;
- }
- CMD:shipwars(playerid, params[])
- {
- if(GameStarted) return SendClientMessage(playerid, 0xE74C3CFF, "[ERROR] {FFFFFF}Ne mozes sada na Ship Wars event.");
- if(ShipTeam[playerid] != -1) return SendClientMessage(playerid, 0xE74C3CFF, "[ERROR] {FFFFFF}Vec si na eventu.");
- if(PlayersInGame >= EVENT_LIMIT) return SendClientMessage(playerid, 0xE74C3CFF, "[ERROR] {FFFFFF}Brodovi su popunjeni.");
- new team = (PlayersInGame % 2 == 0) ? SHIP_RED : SHIP_BLUE;
- ShipTeam[playerid] = team;
- SetPlayerVirtualWorld(playerid, EVENT_WORLD);
- SetPlayerPos(playerid, (team == _:SHIP_RED) ? 402.896 : 352.896, -2109.0, 9.0);
- SetPlayerTeam(playerid, team);
- ResetPlayerWeapons(playerid);
- PlayersInGame++;
- new string[128], name[MAX_PLAYER_NAME];
- GetPlayerName(playerid, name, MAX_PLAYER_NAME);
- if(PlayersInGame == 1) {
- ShipTimer = SetTimerEx("StartGame", 1000, false, "ii", 20, 0);
- format(string, sizeof(string), "[SHIP WARS] %s(%d) je pokrenuo ship wars, mozes se pridruziti na event narednih 20sec.", name, playerid);
- format(string, sizeof(string), "[SHIP WARS] %s(%d) se pridruzio. (Team %s) [%d/%d]", name, playerid, (team == _:SHIP_RED) ? ("Black Pearl Ship") : ("White Pearl Ship"), PlayersInGame, EVENT_LIMIT);
- }
- SendClientMessageToAll(-1, string);
- SendClientMessage(playerid, (team == _:SHIP_RED) ? SHIP_COLOR_RED : SHIP_COLOR_BLUE, "NAPOMENA: Ubijaj neprijatelje kako bih ubrzao svoj brod, ko prvi dodje do kraja, pobjednik!");
- SendClientMessage(playerid, (team == _:SHIP_RED) ? SHIP_COLOR_RED : SHIP_COLOR_BLUE, "Oruzje ce vam se setovati kada odbrojavanje zavrsi.");
- SendClientMessage(playerid, (team == _:SHIP_RED) ? SHIP_COLOR_RED : SHIP_COLOR_BLUE, "Mozete napustiti event komandom /izadjisw.");
- SetPlayerMapIcon(playerid, EVENT_ICONID, (team == _:SHIP_RED) ? 402.896 : 352.896, floatsub(-2137.920, EVENT_DISTANCE), 17.415, 53, 0, MAPICON_GLOBAL);
- shipWithTeamColor[playerid] = CreatePlayerTextDraw(playerid, 493.000000, 310.000000, "_");
- PlayerTextDrawBackgroundColor(playerid, shipWithTeamColor[playerid], 0);
- PlayerTextDrawFont(playerid, shipWithTeamColor[playerid], 5);
- PlayerTextDrawLetterSize(playerid, shipWithTeamColor[playerid], 0.500000, 1.000000);
- PlayerTextDrawColor(playerid, shipWithTeamColor[playerid], (team == _:SHIP_RED) ? SHIP_COLOR_RED : SHIP_COLOR_BLUE);
- PlayerTextDrawSetOutline(playerid, shipWithTeamColor[playerid], 0);
- PlayerTextDrawSetProportional(playerid, shipWithTeamColor[playerid], 1);
- PlayerTextDrawSetShadow(playerid, shipWithTeamColor[playerid], 1);
- PlayerTextDrawUseBox(playerid, shipWithTeamColor[playerid], 1);
- PlayerTextDrawBoxColor(playerid, shipWithTeamColor[playerid], 0);
- PlayerTextDrawTextSize(playerid, shipWithTeamColor[playerid], 130.000000, 130.000000);
- PlayerTextDrawSetPreviewModel(playerid, shipWithTeamColor[playerid], 8493);
- PlayerTextDrawSetPreviewRot(playerid, shipWithTeamColor[playerid], 0.000000, 0.000000, -60.000000, 0.574999);
- PlayerTextDrawSetSelectable(playerid, shipWithTeamColor[playerid], 0);
- for(new i; i < sizeof(shipText); ++i) TextDrawShowForPlayer(playerid, shipText[i]);
- PlayerTextDrawShow(playerid, shipWithTeamColor[playerid]);
- return 1;
- }
- CMD:izadjisw(playerid, params[])
- {
- if(ShipTeam[playerid] == -1) return SendClientMessage(playerid, 0xE74C3CFF, "[Greska] {FFFFFF}Nisi bio na eventu.");
- if(!GameStarted) return SendClientMessage(playerid, 0xE74C3CFF, "[Greska] {FFFFFF}Ne mozes u ovoj fazi napustiti ratne brodove.");
- LeaveGame(playerid);
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement