07.10.2012, 20:10
I have taken the spectate system from Ladmin4v2 to my Gamemode but the spectate isnt working well.
Id 0 crash the whole server when he wants to view other player.
Script:
I have a race Gamemode so when ppl die they spectate and when the last person that is alive wins or dies the current map ends and other map loads.
ID 0 crash the whole server if he press left / right mouse button to switch from players.
if you are ID 1 and other IDs then it wont crash the server.
I hope someone can help me out,
Thanks!
Id 0 crash the whole server when he wants to view other player.
Script:
Код:
//OnTop of script
enum PlayerData
{
SpecID
}
new PlayerInfo[MAX_PLAYERS][PlayerData];
//somewhere in ur script
stock StartSpectate(playerid, specplayerid)
{
for(new x=0; x<MAX_PLAYERS; x++) {
if(GetPlayerState(x) == PLAYER_STATE_SPECTATING && PlayerInfo[x][SpecID] == playerid) {
AdvanceSpectate(x);
}
}
SetPlayerInterior(playerid,GetPlayerInterior(specplayerid));
TogglePlayerSpectating(playerid, 1);
if(IsPlayerInAnyVehicle(specplayerid))
{
PlayerSpectateVehicle(playerid, GetPlayerVehicleID(specplayerid));
}
else
{
PlayerSpectatePlayer(playerid, specplayerid);
}
return 1;
}
stock StopSpectate(playerid)
{
TogglePlayerSpectating(playerid, 0);
return 1;
}
stock AdvanceSpectate(playerid)
{
if(GetPlayerState(playerid) == PLAYER_STATE_SPECTATING && PlayerInfo[playerid][SpecID] != INVALID_PLAYER_ID)
{
for(new x=PlayerInfo[playerid][SpecID]+1; x<=MAX_PLAYERS; x++)
{
if(x == MAX_PLAYERS) x = 0;
if(IsPlayerConnected(x) && x != playerid)
{
if(GetPlayerState(x) == PLAYER_STATE_SPECTATING && PlayerInfo[x][SpecID] != INVALID_PLAYER_ID)
{
continue;
}
else
{
StartSpectate(playerid, x);
break;
}
}
}
}
return 1;
}
stock ReverseSpectate(playerid)
{
if(GetPlayerState(playerid) == PLAYER_STATE_SPECTATING && PlayerInfo[playerid][SpecID] != INVALID_PLAYER_ID)
{
for(new x=PlayerInfo[playerid][SpecID]-1; x>=0; x--))
{
if(x == 0) x = MAX_PLAYERS;
if(IsPlayerConnected(x) && x != playerid)
{
if(GetPlayerState(x) == PLAYER_STATE_SPECTATING && PlayerInfo[x][SpecID] != INVALID_PLAYER_ID || (GetPlayerState(x) != 1 && GetPlayerState(x) != 2 && GetPlayerState(x) != 3))
{
continue;
}
else
{
StartSpectate(playerid, x);
break;
}
}
}
}
return 1;
}
Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(GetPlayerState(playerid) == PLAYER_STATE_SPECTATING)
{
if(newkeys & KEY_HANDBRAKE)//Right Mouse
{
AdvanceSpectate(playerid);
}
if(newkeys & KEY_FIRE)//Left Mouse
{
ReverseSpectate(playerid);
}
}
return 1;
}
Код:
//when player dies [OnPlayerDeath]
for(new x=PlayerInfo[playerid][SpecID]+1; x<=MAX_PLAYERS; x++)
{
if(x == MAX_PLAYERS) x = 0;
if(IsPlayerConnected(x) && x != playerid)
{
StartSpectate(playerid, x);
break;
}
}
ID 0 crash the whole server if he press left / right mouse button to switch from players.
if you are ID 1 and other IDs then it wont crash the server.
I hope someone can help me out,
Thanks!

