PDA

View Full Version : player spectate killer


Squirrel
20/03/2013, 04:24 PM
I got this and I dont get it why isnt it working.

Basically if you get killed you should spectate the player that killed you (10 sec), but it wont work.


//Top of the script.
new Died[MAX_PLAYERS], KilledBy[MAX_PLAYERS];
forward EndDeathCam(playerid);

//OnPlayerConnect
Died[playerid] = -1;
KilledBy[playerid] = -1;

//OnPlayerDisconnect
Died[playerid] = 0;
KilledBy[playerid] = 0;

public OnPlayerDeath(playerid, killerid, reason)
{
pInfo[killerid][Kills]++;
pInfo[playerid][Deaths]++;

Died[playerid] = 1;
if(Died[playerid] == 1)
{
Died[playerid] = 0;
if(KilledBy[playerid] != INVALID_PLAYER_ID)
TogglePlayerSpectating(playerid, 1);
PlayerSpectatePlayer(playerid, killerid);
SendClientMessage(playerid, WHITE, "You have been killed, you are now spectating your killer.");
SetTimerEx("EndDeathCam", 10000, 1, "i", playerid); // 10 seconds
}
else
{
TogglePlayerSpectating(playerid, 0);
}
return 1;
}

public EndDeathCam(playerid)
{
TogglePlayerSpectating(playerid, 0);
Died[playerid] = 0;
}

Misiur
20/03/2013, 04:29 PM
Died[playerid] = 1;
if(Died[playerid] == 1)
{
//(...)
}
else
{
//(...)
}

Question: does the else ever gets called?

if(KilledBy[playerid] != INVALID_PLAYER_ID) You have to use brackets to specify how many lines are affected by the condition.

public OnPlayerDeath(playerid, killerid, reason)
{
pInfo[killerid][Kills]++;
pInfo[playerid][Deaths]++;

Died[playerid] = 1;
KilledBy[playerid] = killerid;
TogglePlayerSpectating(playerid, 1);
PlayerSpectatePlayer(playerid, killerid);
SendClientMessage(playerid, WHITE, "You have been killed, you are now spectating your killer.");
SetTimerEx("EndDeathCam", 10000, 1, "i", playerid); // 10 seconds
return 1;
}

thegreathom
20/03/2013, 04:40 PM
#define FILTERSCRIPT
#include <a_samp>

forward spectateend(playerid);

public OnPlayerDeath(playerid,killerid,reason)
{
if ( killerid != INVALID_PLAYER_ID )
{
new szGameTextStr[128], killerName[24];

GetPlayerName(killerid,killerName,24);
TogglePlayerSpectating( playerid, 1 );
if (IsPlayerInAnyVehicle(killerid))
{
PlayerSpectateVehicle( playerid, GetPlayerVehicleID( killerid ) );
}
else
{
PlayerSpectatePlayer( playerid, killerid );
}
format( szGameTextStr, 128, "~w~~n~killCamera~n~~>~Killer: %s ( ID: %i )~<~", killerName, killerid );
GameTextForPlayer( playerid, szGameTextStr, 10000, 5 );
SetTimerEx( "spectateend", true, 10000, "i", playerid );
}
return 1;
}

public spectateend(playerid)
return TogglePlayerSpectating(playerid,0), SpawnPlayer(playerid);
// end.


Now, edit it like you want for your register system..

Squirrel
20/03/2013, 04:47 PM
Oh thanks guys, I'll test it.

Squirrel
20/03/2013, 04:51 PM
I tested it and the issue is that it spectates the player but constantly bugs the camera and you crash. It's like teleporting the camera like crazy.


It just teleports the camera like crazy. FOr example

Teleports Camera to KillerID
Teleports Camera to PlayerID
Teleports Camera to KillerID
Teleports Camera to PlayerID

every sec


This is my OnPlayerSpawn
public OnPlayerSpawn(playerid)
{

TextDrawHideForPlayer(playerid, Textdraw0);
TextDrawHideForPlayer(playerid, Textdraw1);

new Random = random(sizeof(RandomSpawns));
SetPlayerPos(playerid, RandomSpawns[Random][0], RandomSpawns[Random][1], RandomSpawns[Random][2]);
SetPlayerFacingAngle(playerid, RandomSpawns[Random][3]);

return 1;
}

I use this
#define FILTERSCRIPT
#include <a_samp>

forward spectateend(playerid);

public OnPlayerDeath(playerid,killerid,reason)
{
if ( killerid != INVALID_PLAYER_ID )
{
new szGameTextStr[128], killerName[24];

GetPlayerName(killerid,killerName,24);
TogglePlayerSpectating( playerid, 1 );
if (IsPlayerInAnyVehicle(killerid))
{
PlayerSpectateVehicle( playerid, GetPlayerVehicleID( killerid ) );
}
else
{
PlayerSpectatePlayer( playerid, killerid );
}
format( szGameTextStr, 128, "~w~~n~killCamera~n~~>~Killer: %s ( ID: %i )~<~", killerName, killerid );
GameTextForPlayer( playerid, szGameTextStr, 10000, 5 );
SetTimerEx( "spectateend", true, 10000, "i", playerid );
}
return 1;
}

public spectateend(playerid)
return TogglePlayerSpectating(playerid,0), SpawnPlayer(playerid);
// end.

thegreathom
20/03/2013, 05:31 PM
It's work fine for me?

Squirrel
20/03/2013, 06:11 PM
Hmmm...

It doesnt work for me normaly. It just switches the camera as crazy and at the end you crash :/

Can it be related to something else maybe?
Here is my full code
http://pastebin.com/1Z79zv7q

Patrick
20/03/2013, 06:20 PM
Try this? just edited some code. give it a try if it works.

also im not sure if this caused the problem
as when the timer get called it repeats every 10 seconds. so i change the true --> false on code below. give it a try!

SetTimerEx( "spectateend", true, 10000, "i", playerid );//means it repeats every 10 seconds



public OnPlayerDeath(playerid,killerid,reason)
{
if(killerid != INVALID_PLAYER_ID)
{
new szGameTextStr[128];
new kvehicle = GetPlayerVehicleID(killerid);
new killerName[24]; GetPlayerName(killerid, killerName, sizeof killerName);
//
if(IsPlayerInAnyVehicle(killerid)) // = player is in vehicle
return PlayerSpectateVehicle( playerid, kvehicle);

if(!IsPlayerInAnyVehicle(killerid)) // = player is not in vehicle
return PlayerSpectatePlayer( playerid, killerid );

format( szGameTextStr, sizeof szGameTextStr, "~w~~n~killCamera~n~~>~Killer: %s ( ID: %i )~<~", killerName, killerid );
GameTextForPlayer( playerid, szGameTextStr, 10000, 5);
//
TogglePlayerSpectating(playerid, 1);
SetTimerEx( "spectateend", false, 10000, "i", playerid );
}
return 1;
}

forward spectateend(playerid);
public spectateend(playerid)
{
TogglePlayerSpectating(playerid, 0)
SpawnPlayer(playerid);
return 1;
}

Squirrel
20/03/2013, 06:46 PM
Actually I tried with changing the timer but didnt help at all :(