• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Pawn] [HELP] Spec on NPC
#1
Hi everyone, I have a little problem with this script.

This script allows you to attack the camera on the npc via the command /camera, but once the camera is attached on the npc, I cannot change the view as you normally do on the player (usually with the V key).

Is it possible to do this?



Then another problem: when an NPC is in an interior, the interior is not visible.



This is the script.





Code:
#include <a_samp>

#include <sscanf2>

#include <zcmd>

new IsSpectating[MAX_PLAYERS];

new Float:PosBeforeSpec[MAX_PLAYERS][3];

new InteriorBeforeSpec[MAX_PLAYERS];

new bool:LastTimeSpeced[MAX_PLAYERS];



ResetPlayerStats(playerid)

{

IsSpectating[playerid] = INVALID_PLAYER_ID;

PosBeforeSpec[playerid][0] = 0.0, PosBeforeSpec[playerid][1] = 0.0, PosBeforeSpec[playerid][2] = 0.0;

InteriorBeforeSpec[playerid] = 0;

LastTimeSpeced[playerid] = false;

}



public OnPlayerDisconnect(playerid, reason)

{

for(new i; i < MAX_PLAYERS; i)

{

if(IsSpectating[i] == playerid)

{

cmd_cameraoff(i, "");

}

}



ResetPlayerStats(playerid); //@@@WARNING: KEEP THIS LINE AT THE BOTTOM RIGHT HERE OR THINGS MAY BEHAVE DIFFERENT THAN EXPECTED!!!

return 1;

}



public OnPlayerSpawn(playerid)

{

if(LastTimeSpeced[playerid])

? ? {

? ? LastTimeSpeced[playerid] = false;

SetPlayerInterior(playerid, InteriorBeforeSpec[playerid]);

SetPlayerPos(playerid, PosBeforeSpec[playerid][0], PosBeforeSpec[playerid][1], PosBeforeSpec[playerid][2]);

? ? }

return 1;

}



public OnPlayerStateChange(playerid, newstate, oldstate)

{

if(newstate == PLAYER_STATE_ONFOOT || newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)

? ? {

? ? ? ? for(new i; i < MAX_PLAYERS; i)

? ? ? ? {

? ? ? ? ? ? if(IsSpectating[i] == playerid)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? SetPlayerToSpectatePlayer(i, playerid);

? ? ? ? ? ? }

? ? ? ? }

? ? }

? ? return 1;

}



public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)

{

if(newinteriorid != oldinteriorid)

{

for(new i; i < MAX_PLAYERS; i)

{

if(IsSpectating[i] == playerid && GetPlayerState(i) == PLAYER_STATE_SPECTATING)

{

SetPlayerToSpectatePlayer(i, playerid);

}

}

}

return 1;

}



CMD:camera(playerid, params[])

{

new targetid;

if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, -1, "Usa: /camera <playerid/nome>");

if(!IsPlayerConnected(targetid) || !IsPlayerNPC(targetid)) return SendClientMessage(playerid, -1, "Player id invalido.");

if(playerid == targetid) return SendClientMessage(playerid, -1, "Non puoi guardare te stesso.");

//if(IsSpectating[targetid] != INVALID_PLAYER_ID) return SendClientMessage(playerid, -1, "That player is already watching someone.");

//if(GetPlayerState(targetid) == PLAYER_STATE_SPECTATING) return SendClientMessage(playerid, -1, "Player is in spectating mode. (Possibly didn't spawn yet)");

SetPlayerToSpectatePlayer(playerid, targetid);



if(IsSpectating[playerid] == INVALID_PLAYER_ID)

{

new str[156];

format(str, sizeof(str), "Ora stai guardando [%i]%s. Usa /cameraoff per smettere di guardarlo o /camera <id> per guardare un altro player.", targetid);

SendClientMessage(playerid, -1, str);

}

return 1;

}



CMD:cameraoff(playerid, params[])

{

if(IsSpectating[playerid] == INVALID_PLAYER_ID) return SendClientMessage(playerid, -1, "Non stai guardando nessuno.");

LastTimeSpeced[playerid] = true;

StopPlayerSpectatePlayer(playerid);

return 1;

}



SetPlayerToSpectatePlayer(playerid, targetid)

{

IsSpectating[playerid] = targetid;



//Last pos before specing (if he was specing we don't get the next spec)

if(GetPlayerState(playerid) != PLAYER_STATE_SPECTATING)

{

GetPlayerPos(playerid, PosBeforeSpec[playerid][0], PosBeforeSpec[playerid][1], PosBeforeSpec[playerid][2]);

InteriorBeforeSpec[playerid] = GetPlayerInterior(playerid);

}



new targetInterior = GetPlayerInterior(targetid);



SetPlayerInterior(playerid, targetInterior);



TogglePlayerSpectating(playerid, 1);

if(GetPlayerState(targetid) == PLAYER_STATE_DRIVER || GetPlayerState(targetid) == PLAYER_STATE_PASSENGER)

{

new vehToSpec = GetPlayerVehicleID(targetid);

PlayerSpectateVehicle(playerid, vehToSpec);

}

else PlayerSpectatePlayer(playerid, targetid);

return 1;

}



StopPlayerSpectatePlayer(playerid)

{

IsSpectating[playerid] = INVALID_PLAYER_ID;



TogglePlayerSpectating(playerid, 0);



SetPlayerInterior(playerid, InteriorBeforeSpec[playerid]);

SetPlayerPos(playerid, PosBeforeSpec[playerid][0], PosBeforeSpec[playerid][1], PosBeforeSpec[playerid][2]);

}

[color=#333333][size=small][font=Tahoma, Verdana, Arial, sans-serif]
[/font][/size][/color]
  Reply
#2
GetPlayerInterior always returns 0 for NPCs according to the wiki. You'll need to store which interior they are placed in and apply it to the spectator via a variable.
  Reply


Forum Jump: