Saving weapons when spectating - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Saving weapons when spectating (
/showthread.php?tid=450524)
Saving weapons when spectating -
glbracer - 13.07.2013
Alright, so here is my /spec command:
pawn Код:
CMD:spec(playerid, params[])
{
if(PlayerInfo[playerid][pAdmin] >= 2 || PlayerInfo[playerid][pDeveloper] >= 3 || ModDuty[playerid] == 1)
{
new id, string[256];
if(sscanf(params, "u", id)) return SCM(playerid, COLOR_ERROR, "USAGE: /spec(tate) [playerid]");
if(!IsPlayerConnected(id)) return SCM(playerid, COLOR_ERROR, "That player is not connected.");
if(IsPlayerConnected(id))
{
for(new i = 0; i < 13; i++)
{
GetPlayerWeaponData(playerid, i, specWeapons[playerid][i][0], specWeapons[playerid][i][1]);
}
GetPlayerPos(playerid, specCoord[playerid][0], specCoord[playerid][1], specCoord[playerid][2]);
GetPlayerFacingAngle(playerid, specCoord[playerid][3]);
specInterior[playerid] = GetPlayerInterior(playerid);
specVW[playerid] = GetPlayerVirtualWorld(playerid);
specID[playerid] = id;
Spectating[playerid] = true;
BeingSpectated[id] = true;
TogglePlayerSpectating(playerid, true);
if(IsPlayerInAnyVehicle(id)) { PlayerSpectateVehicle(playerid, GetPlayerVehicleID(id)); }
if(!IsPlayerInAnyVehicle(id)){ PlayerSpectatePlayer(playerid, id); }
format(string, sizeof(string), "[AdmCmd]{dfebff}: %s (%d) is now spectating %s (%d)", GPN(playerid), playerid, GPN(id), id);
if(PlayerInfo[id][pAdmin] > 0 || PlayerInfo[id][pDeveloper] > 0 || PlayerInfo[playerid][pHelper] > 0)
return SendAdminMessage(COLOR_NICERED, string);
}
}
return 1;
}
And here is my /specoff command
pawn Код:
CMD:specoff(playerid, params[])
{
if(PlayerInfo[playerid][pAdmin] >= 2 || PlayerInfo[playerid][pDeveloper] >= 3 || ModDuty[playerid] >= 1)
{
if(Spectating[playerid])
{
new string[256];
TogglePlayerSpectating(playerid, 0);
SetPlayerPos(playerid, specCoord[playerid][0], specCoord[playerid][1], specCoord[playerid][2]);
SetPlayerFacingAngle(playerid, specCoord[playerid][3]);
SetPlayerInterior(playerid, specInterior[playerid]);
SetPlayerVirtualWorld(playerid, specVW[playerid]);
for(new i = 0; i < 13; i++)
{
GivePlayerWeapon(playerid, specWeapons[playerid][i][0], specWeapons[playerid][i][1]);
}
Spectating[playerid] = false;
BeingSpectated[specID[playerid]] = false;
format(string, sizeof(string), "[AdmCmd]{dfebff}: %s (%d) has stopped spectating %s (%d)", GPN(playerid), playerid, GPN(specID[playerid]), specID[playerid]);
specID[specID[playerid]] = INVALID_PLAYER_ID;
SendAdminMessage(COLOR_NICERED, string);
return 1;
}
if(!Spectating[playerid])
return SCM(playerid, COLOR_ERROR, "You aren't spectating anyone!");
}
return 1;
}
Here are the variables defined at the top of the script.
pawn Код:
Float:specCoord[MAX_PLAYERS][4],
specWeapons[MAX_PLAYERS][13][2],
specID[MAX_PLAYERS],
bool:Spectating[MAX_PLAYERS],
bool:BeingSpectated[MAX_PLAYERS],
specInterior[MAX_PLAYERS],
specVW[MAX_PLAYERS],
Weapons are
not saving and/or loading properly while spectating. It's incredibly frustrating, and I'd like to know why, and what I'm doing doing wrong...
Re: Saving weapons when spectating -
Threshold - 13.07.2013
When you disable TogglePlayerSpectating, OnPlayerSpawn gets called. So under OnPlayerSpawn, add
pawn Код:
if(Spectating[playerid] == true)
{
//give weapons
// set pos
Spectating[playerid] = false;
return 1;
//etc.
}