pawn Код:
// DEVELOPMENT SCRIPT
// ** INCLUDES
#include <a_samp>
#include <sscanf>
#include <zcmd>
// ** VARIABLES
// *** GLOBAL VARIABLES
// **** VEHICLES
new vhInterior[MAX_VEHICLES];
// *** PER-PLAYER VARIABLES
// **** GENERAL
new pSpectatingPlayer[MAX_PLAYERS],
Float:pSpectatingPos[MAX_PLAYERS][4],
pSpectatingInterior[MAX_PLAYERS],
pSpectatingVirtualWorld[MAX_PLAYERS],
pSpectatingWeapons[MAX_PLAYERS][13],
pSpectatingAmmo[MAX_PLAYERS][13];
// **** STATES
new bool:sSpectating[MAX_PLAYERS] = false;
// ** HOOKS
stock Hook_LinkVehicleToInterior(vehicleid, interiorid)
{
vhInterior[vehicleid] = interiorid;
return LinkVehicleToInterior(vehicleid, interiorid);
}
#if defined _ALS_LinkVehicleToInterior
#undef LinkVehicleToInterior
#else
#define _ALS_LinkVehicleToInterior
#endif
#define LinkVehicleToInterior Hook_LinkVehicleToInterior
// ** MAIN
main()
{
print("Loaded \"spectate.amx\".");
}
// ** CALLBACKS
public OnGameModeInit()
{
return 1;
}
public OnGameModeExit()
{
return 1;
}
public OnPlayerSpawn(playerid)
{
if(IsPlayerSpectating(playerid))
{
SetPlayerInterior(playerid, pSpectatingInterior[playerid]);
SetPlayerVirtualWorld(playerid, pSpectatingVirtualWorld[playerid]);
SetPlayerPos(playerid, pSpectatingPos[playerid][0], pSpectatingPos[playerid][1], pSpectatingPos[playerid][2]);
SetPlayerFacingAngle(playerid, pSpectatingPos[playerid][3]);
SetCameraBehindPlayer(playerid);
for(new i = 0; i <= 12; i ++)
{
GivePlayerWeapon(playerid, pSpectatingWeapons[playerid][i], pSpectatingAmmo[playerid][i]);
}
pSpectatingPlayer[playerid] = -1;
sSpectating[playerid] = false;
}
return 1;
}
public OnVehicleDeath(vehicleid, killerid)
{
vhInterior[vehicleid] = 0;
return 1;
}
// ** COMMANDS
CMD:spec(playerid, params[])
{
new lookupid;
if(sscanf(params, "u", lookupid)) return SendClientMessage(playerid, -1, "Usage: /spec (id/name).");
if(!IsPlayerConnected(lookupid)) return SendClientMessage(playerid, -1, "That player isn't connected to the server.");
if(IsPlayerNPC(lookupid)) return SendClientMessage(playerid, -1, "You cannot spectate an NPC.");
if(lookupid == playerid) return SendClientMessage(playerid, -1, "You cannot spectate yourself.");
if(IsPlayerSpectating(lookupid)) return SendClientMessage(playerid, -1, "That player is spectating another player.");
if(!IsPlayerSpectating(playerid))
{
GetPlayerPos(playerid, pSpectatingPos[playerid][0], pSpectatingPos[playerid][1], pSpectatingPos[playerid][2]);
GetPlayerFacingAngle(playerid, pSpectatingPos[playerid][3]);
pSpectatingInterior[playerid] = GetPlayerInterior(playerid);
pSpectatingVirtualWorld[playerid] = GetPlayerVirtualWorld(playerid);
new weapon[13], ammo[13];
for(new i = 0; i <= 12; i ++)
{
GetPlayerWeaponData(playerid, i, weapon[i], ammo[i]);
pSpectatingWeapons[playerid][GetWeaponSlot(weapon[i])] = weapon[i];
pSpectatingAmmo[playerid][GetWeaponSlot(weapon[i])] = ammo[i];
}
}
TogglePlayerSpectating(playerid, true);
if(IsPlayerInAnyVehicle(lookupid))
{
new vehicleid = GetPlayerVehicleID(lookupid);
SetPlayerInterior(playerid, GetVehicleInterior(vehicleid));
SetPlayerVirtualWorld(playerid, GetVehicleVirtualWorld(vehicleid));
PlayerSpectateVehicle(playerid, vehicleid);
}
else
{
SetPlayerInterior(playerid, GetPlayerInterior(lookupid));
SetPlayerVirtualWorld(playerid, GetPlayerVirtualWorld(lookupid));
PlayerSpectatePlayer(playerid, lookupid);
}
pSpectatingPlayer[playerid] = lookupid;
sSpectating[playerid] = true;
return 1;
}
CMD:specoff(playerid, params[])
{
if(!IsPlayerSpectating(playerid)) return SendClientMessage(playerid, -1, "You are not spectating anyone.");
TogglePlayerSpectating(playerid, false);
SetPlayerInterior(playerid, 0);
SetPlayerVirtualWorld(playerid, 0);
return 1;
}
// ** FUNCTIONS
stock GetVehicleInterior(vehicleid) return vhInterior[vehicleid];
stock GetWeaponSlot(weaponid)
{
new slot;
switch(weaponid)
{
case 0, 1: slot = 0;
case 2, 3, 4, 5, 6, 7, 8, 9: slot = 1;
case 22, 23, 24: slot = 2;
case 25, 26, 27: slot = 3;
case 28, 29, 32: slot = 4;
case 30, 31: slot = 5;
case 33, 34: slot = 6;
case 35, 36, 37, 38: slot = 7;
case 16, 17, 18, 39: slot = 8;
case 41, 42, 43: slot = 9;
case 10, 11, 12, 13, 14, 15: slot = 10;
case 44, 45, 46: slot = 11;
case 40: slot = 12;
}
return slot;
}
forward bool:IsPlayerSpectating(playerid);
public bool:IsPlayerSpectating(playerid) return sSpectating[playerid];