Spec problem
#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 Код:
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);
        }
Reply
#2

Show me the entire command please
Reply
#3

Here you go
pawn Код:
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;
}
Reply
#4

Please help me fast <3
Reply
#5

Quote:
Originally Posted by lulo356
Посмотреть сообщение
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 Код:
if(GetPlayerState(playerid) == PLAYER_STATE_SPECTATING)
        {
            new string[235], Float:H, Float:A;
            GetPlayerHealth([COLOR="Red"]playerid[/COLOR], H); GetPlayerArmour([COLOR="Red"]playerid[/COLOR], 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([COLOR="Red"]playerid[/COLOR]));
            TextDrawSetString(Money, string);
            format(string,sizeof(string),"Name: %s",RPN(playerid));
            TextDrawSetString(Name, string);
        }
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.
Reply
#6

Quote:
Originally Posted by inshal
Посмотреть сообщение
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.
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(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);
        }
Reply
#7

Quote:
Originally Posted by lulo356
Посмотреть сообщение
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(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);
        }
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 Код:
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);
        }
I hope it works.
Reply
#8

pawn Код:
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;
}
Also, you are using global textdraws for something that should be kept 'per-player'. So if you have two admins spectating at the same time, you can expect some weird things to happen to the textdraws. What you need to do is create a player textdraw (CreatePlayerTextDraw) which will be created when a player uses spec, and deleted when a player does 'spec off'.

Then you should update the textdraws using either OnPlayerUpdate or the appropriate callbacks depending on the textdraw types. (Eg. updating the money textdraw when you give/take server money rather than doing checks under OnPlayerUpdate)

Unfortunately I don't have your entire code to do this for you, but I can help you through PM further if you'd like. (To prevent you from posting your entire code in this thread)

EDIT: Also, I combined the 'Spec[playerid]' and 'Specid[playerid]' variables into one. This technically doesn't need two variables, because if Specid[playerid] is an invalid player id, that simply means that they are not spectating someone.
Reply
#9

Quote:
Originally Posted by inshal
Посмотреть сообщение
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 Код:
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);
        }
I hope it works.
It still shows the information from ID 0
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)