PDA

View Full Version : Objects Will Load But the Player Will Get Teleported After 5 min


CarRamper
09/07/2016, 03:51 PM
as the the topic says Objects Will Load But the Player Will Get Teleported After 5 min
i want to make it like on trying /shipwars objects will load but the player will get teleported after 5 sec
code
#define FILTERSCRIPT
#include <a_samp>
#include <streamer>
#include <zcmd>

#define EVENT_WORLD 4 // virtualworld id of ship wars event
#define EVENT_AMMO 5000 // how many ammo players will get for their weapons
#define EVENT_ICONID 42 // mapicon id for finish icon (not the markertype) for removeplayermapicon
#define EVENT_LIMIT 24 // max. number of people can join
#define EVENT_DISTANCE 850.0
#define DEFAULT_SPEED 7.0

#define WINNER_MONEY 20000 // how much money will winner team get
#define WINNER_SCORE 5 // how much score will winner team get

#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};
// will give player a deagle, combat shotgun, m4 and country rifle
// https://wiki.sa-mp.com/wiki/Weapons

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] We're gaining speed, keep killing them!", (team == _:SHIP_RED) ? ("RED") : ("BLUE"));

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] Game cancelled. (not enough players)");
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);
SetPlayerScore(i, GetPlayerScore(i) + WINNER_SCORE);
}
}

format(string, sizeof(string), "[SHIP WARS] Team %s has won the ship wars!", (team == _:SHIP_RED) ? ("Red") : ("Blue"));
SendClientMessageToAll((team == _:SHIP_RED) ? SHIP_COLOR_RED : SHIP_COLOR_BLUE, string);
}else{
SendClientMessageToAll(-1, "[SHIP WARS] This game has resulted in a draw.");
}

ResetGame();
}

return 1;
}

forward StartGame(time, move);
public StartGame(time, move)
{
if(move) {
SendClientMessageToAll(-1, "[SHIP WARS] Game started.");
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~starting in ~r~~h~%d ~n~~g~~h~get ready!", 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] Game cancelled. (not enough players)");
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] Ships will start moving in 3 seconds.");
ShipTimer = SetTimerEx("StartGame", 3000, false, "ii", 0, 1);
}
}
}


return 1;
}

CMD:shipwars(playerid, params[])
{
if(GameStarted) return SendClientMessage(playerid, 0xE74C3CFF, "[ERROR] {FFFFFF}You can't join ship wars right now.");
if(ShipTeam[playerid] != -1) return SendClientMessage(playerid, 0xE74C3CFF, "[ERROR] {FFFFFF}You're already in ship wars.");
if(PlayersInGame >= EVENT_LIMIT) return SendClientMessage(playerid, 0xE74C3CFF, "[ERROR] {FFFFFF}Ship wars is full.");
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) has started the ship wars, you can join in the next 20 seconds.", name, playerid);
}else{
format(string, sizeof(string), "[SHIP WARS] %s(%d) has joined. (Team %s) [%d/%d]", name, playerid, (team == _:SHIP_RED) ? ("Red") : ("Blue"), PlayersInGame, EVENT_LIMIT);
}

SendClientMessageToAll(-1, string);
SendClientMessage(playerid, (team == _:SHIP_RED) ? SHIP_COLOR_RED : SHIP_COLOR_BLUE, "OBJECTIVE: Kill the enemy team to speed up your ship. First ship gets to end wins!");
SendClientMessage(playerid, (team == _:SHIP_RED) ? SHIP_COLOR_RED : SHIP_COLOR_BLUE, "You'll receive weapons when the countdown finishes.");
SendClientMessage(playerid, (team == _:SHIP_RED) ? SHIP_COLOR_RED : SHIP_COLOR_BLUE, "You can leave ship wars by using /leaveship.");
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:leaveship(playerid, params[])
{
if(ShipTeam[playerid] == -1) return SendClientMessage(playerid, 0xE74C3CFF, "[ERROR] {FFFFFF}You're not in ship wars.");
if(!GameStarted) return SendClientMessage(playerid, 0xE74C3CFF, "[ERROR] {FFFFFF}You can't leave ship wars in this stage.");
LeaveGame(playerid);
return 1;
}