if(GetPlayerState(playerid) == PLAYER_STATE_SPECTATING)
{
new string[235], Float:H, Float:A;
GetPlayerHealth(playerid, H); GetPlayerArmour(playerid, A);
format(string,sizeof(string),"Health: %0.1f",H);
TextDrawSetString(Health1, string);
format(string,sizeof(string),"Armour: %0.1f",A));
TextDrawSetString(Name, string);
format(string,sizeof(string),"Money: %d",GetPlayerMoney(playerid));
TextDrawSetString(Money, string);
format(string,sizeof(string),"Name: %s",RPN(playerid));
TextDrawSetString(Name, string);
}
CMD:spec(playerid, params[])
{
new playerb, string[128];
if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You need to login first before using any command.");
if(PlayerInfo[playerid][pAdmin] < 1) return SendClientMessage(playerid, COLOR_GREY, "You are not authorized to use this command.");
if(!strcmp(params, "off", true))
{
if(!Spec[playerid]) return SendClientMessage(playerid, COLOR_GREY, "You aren't spectating anybody.");
Spec[playerid] = 0;
TogglePlayerSpectating(playerid, 0);
GetPlayerHealth(playerid, PlayerInfo[playerid][pHealth]);
GetPlayerArmour(playerid, PlayerInfo[playerid][pArmor]);
SetPlayerVirtualWorld(playerid, PlayerInfo[playerid][pVW]);
SetPlayerInterior(playerid, PlayerInfo[playerid][pInt]);
SetPlayerPos(playerid, PlayerInfo[playerid][pX], PlayerInfo[playerid][pY], PlayerInfo[playerid][pZ]);
SendClientMessage(playerid, COLOR_WHITE, " You have stopped spectating players.");
TextDrawHideForPlayer(playerid, Health1);
TextDrawHideForPlayer(playerid, Money);
TextDrawHideForPlayer(playerid, Name);
TextDrawHideForPlayer(playerid, Armour);
if(PlayerInfo[Specid[playerid]][pAdmin] >= PlayerInfo[playerid][pAdmin])
{
format(string, sizeof(string), "SpecWarn: %s has stopped spectating you.", RPN(playerid));
SendClientMessage(Specid[playerid], COLOR_DARKRED, string);
}
Specid[playerid] = -1;
return 1;
}
if(sscanf(params, "u", playerb)) return SendClientMessage(playerid, COLOR_WHITE, "[Usage]: /spec [playerid]");
if(playerid == playerb) return SendClientMessage(playerid, COLOR_GREY, "You can't spectate yourself.");
if(!IsPlayerLoggedIn(playerb)) return SendClientMessage(playerid, COLOR_GREY, "Invalid player id.");
if(Spec[playerb]) return SendClientMessage(playerid, COLOR_GREY, "Player is spectating someone.");
PlayerInfo[playerid][pModel] = GetPlayerSkin(playerid);
if(Specid[playerid] != -1 && PlayerInfo[Specid[playerid]][pAdmin] > PlayerInfo[playerid][pAdmin])
{
format(string, sizeof(string), "SpecWarn: %s has stopped spectating you.", RPN(playerid));
SendClientMessage(Specid[playerid], COLOR_DARKRED, string);
}
if(!Spec[playerid])
{
PlayerInfo[playerid][pVW] = GetPlayerVirtualWorld(playerid);
PlayerInfo[playerid][pInt] = GetPlayerInterior(playerid);
GetPlayerPos(playerid, PlayerInfo[playerid][pX], PlayerInfo[playerid][pY], PlayerInfo[playerid][pZ]);
}
Specid[playerid] = playerb;
TogglePlayerSpectating(playerid, 1);
Spec[playerid] = 1;
SetPlayerInterior(playerid, GetPlayerInterior(playerb));
SetPlayerVirtualWorld(playerid, GetPlayerVirtualWorld(playerb));
format(string, sizeof(string), " Currently spectating %s", RPN(playerb));
SendClientMessage(playerid, COLOR_WHITE, string);
TextDrawShowForPlayer(playerid, Health1);
TextDrawShowForPlayer(playerid, Money);
TextDrawShowForPlayer(playerid, Name);
TextDrawShowForPlayer(playerid, Armour);
if(IsPlayerInAnyVehicle(playerb))
{
PlayerSpectateVehicle(playerid, GetPlayerVehicleID(playerb));
}
else
{
PlayerSpectatePlayer(playerid, playerb);
}
if(PlayerInfo[playerb][pAdmin] >= PlayerInfo[playerid][pAdmin])
{
format(string, sizeof(string), "SpecWarn: %s is currently spectating you.", RPN(playerid));
SendClientMessage(playerb, COLOR_DARKRED, string);
}
if(!PlayerInfo[playerb][pTutorial]) SendClientMessage(playerid, COLOR_WHITE, " That player is viewing the tutorial, don't assume he's using hacks yet.");
return 1;
}
Okay i maked a health money armour and name in textdraw for the spec command but the problem is, if you spec someone you will see your own name by Name: own health own money not from the other player, Its now in playerid, but i got the same problem by playerb, so what do i need to do to see the other guys/girls status
pawn Код:
|
I think you can see the fault now. You used playerid instead of ID or any defined ID (the ID of the player the spectator is spectating). I guess you defined that as "playerb". I think you can solve the problem now.
|
if(GetPlayerState(playerid) == PLAYER_STATE_SPECTATING)
{
new id, string[235], Float:H, Float:A;
GetPlayerHealth(id, H); GetPlayerArmour(id, A);
format(string,sizeof(string),"Health: %0.1f",H);
TextDrawSetString(Health1, string);
format(string,sizeof(string),"Armour: %0.1f",A);
TextDrawSetString(Armour1, string);
format(string,sizeof(string),"Money: %d",GetPlayerMoney(id));
TextDrawSetString(Money, string);
format(string,sizeof(string),"Name: %s",RPN(id));
TextDrawSetString(Name, string);
}
Okay well, the real problem is, you see the money armour name and health from ID 0 How to fix that
pawn Код:
|
if(GetPlayerState(playerid) == PLAYER_STATE_SPECTATING)
{
new id, string[235], Float:H, Float:A;
GetPlayerHealth(playerb, H); GetPlayerArmour(idplayerbA);
format(string,sizeof(string),"Health: %0.1f",H);
TextDrawSetString(Health1, string);
format(string,sizeof(string),"Armour: %0.1f",A);
TextDrawSetString(Armour1, string);
format(string,sizeof(string),"Money: %d",GetPlayerMoney(playerb));
TextDrawSetString(Money, string);
format(string,sizeof(string),"Name: %s",RPN(playerb));
TextDrawSetString(Name, string);
}
CMD:spec(playerid, params[])
{
if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You need to login first before using any command.");
if(!PlayerInfo[playerid][pAdmin]) return SendClientMessage(playerid, COLOR_GREY, "You are not authorized to use this command.");
if(!strcmp(params, "off", true))
{
if(Spec[playerid] == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_GREY, "You aren't spectating anybody.");
new string[65];
TogglePlayerSpectating(playerid, 0);
SetPlayerHealth(playerid, PlayerInfo[playerid][pHealth]);
SetPlayerArmour(playerid, PlayerInfo[playerid][pArmor]);
SetPlayerVirtualWorld(playerid, PlayerInfo[playerid][pVW]);
SetPlayerInterior(playerid, PlayerInfo[playerid][pInt]);
SetPlayerPos(playerid, PlayerInfo[playerid][pX], PlayerInfo[playerid][pY], PlayerInfo[playerid][pZ]);
SendClientMessage(playerid, COLOR_WHITE, " You have stopped spectating players.");
TextDrawHideForPlayer(playerid, Health1);
TextDrawHideForPlayer(playerid, Money);
TextDrawHideForPlayer(playerid, Name);
TextDrawHideForPlayer(playerid, Armour);
if(PlayerInfo[Spec[playerid]][pAdmin] >= PlayerInfo[playerid][pAdmin])
{
format(string, sizeof(string), "SpecWarn: %s has stopped spectating you.", RPN(playerid));
SendClientMessage(Spec[playerid], COLOR_DARKRED, string);
}
Spec[playerid] = INVALID_PLAYER_ID;
return 1;
}
new playerb;
if(sscanf(params, "u", playerb)) return SendClientMessage(playerid, COLOR_WHITE, "[Usage]: /spec [playerid]");
if(playerid == playerb) return SendClientMessage(playerid, COLOR_GREY, "You can't spectate yourself.");
if(!IsPlayerLoggedIn(playerb) || !IsPlayerConnected(playerb) || playerb == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_GREY, "Invalid player id.");
if(Spec[playerb] != INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_GREY, "Player is spectating someone.");
if(!PlayerInfo[playerb][pTutorial]) SendClientMessage(playerid, COLOR_WHITE, " That player is viewing the tutorial, don't assume he's using hacks yet.");
PlayerInfo[playerid][pModel] = GetPlayerSkin(playerid);
new string[65];
if(Spec[playerid] == INVALID_PLAYER_ID)
{
PlayerInfo[playerid][pVW] = GetPlayerVirtualWorld(playerid);
PlayerInfo[playerid][pInt] = GetPlayerInterior(playerid);
GetPlayerPos(playerid, PlayerInfo[playerid][pX], PlayerInfo[playerid][pY], PlayerInfo[playerid][pZ]);
}
Spec[playerid] = playerb;
TogglePlayerSpectating(playerid, 1);
SetPlayerInterior(playerid, GetPlayerInterior(playerb));
SetPlayerVirtualWorld(playerid, GetPlayerVirtualWorld(playerb));
format(string, sizeof(string), " Currently spectating %s", RPN(playerb));
SendClientMessage(playerid, COLOR_WHITE, string);
TextDrawShowForPlayer(playerid, Health1);
TextDrawShowForPlayer(playerid, Money);
TextDrawShowForPlayer(playerid, Name);
TextDrawShowForPlayer(playerid, Armour);
if(IsPlayerInAnyVehicle(playerb)) PlayerSpectateVehicle(playerid, GetPlayerVehicleID(playerb));
else PlayerSpectatePlayer(playerid, playerb);
if(PlayerInfo[playerb][pAdmin] >= PlayerInfo[playerid][pAdmin])
{
format(string, sizeof(string), "SpecWarn: %s is currently spectating you.", RPN(playerid));
SendClientMessage(playerb, COLOR_DARKRED, string);
}
return 1;
}
The playerid (id) is not defined so the server will go for 0. playerb is defined as the id, so you should use that.
Here you go :- pawn Код:
|