PDA

View Full Version : Tag mismatch, BUT WHY!?


Twisted_Insane
01/04/2012, 12:38 AM
On the following line:

COMMAND:spec(playerid,params[])
{
#if EnableSpectate == true

if(gPlayerSpectating[playerid] == 0)
{
new Target;
if(sscanf(params, "u", Target)) return SendClientMessage(playerid, COLOR_ORANGE, "USAGE: /spec [playerid]");

if(gPlayerSpectating[Target] == 0)
{
if(Target == playerid) return SendClientMessage(playerid, COLOR_RED, "SERVER: You can't spec yourself!");
if(!IsPlayerConnected(Target))
return SendClientMessage(playerid, COLOR_RED, "ERROR: Player is not connected!");

TogglePlayerSpectating(playerid, 1);
PlayerSpectatePlayer(playerid, Target);
SetPlayerInterior(playerid,GetPlayerInterior(Targe t));
gSpectateID[playerid] = Target;
gPlayerSpectating[playerid] = 1;
gSpectateType[playerid] = ADMIN_SPEC_TYPE_PLAYER;
new tname[MAX_PLAYER_NAME];
GetPlayerName(Target,tname,sizeof(tname));
new MyString[128];
format(MyString,sizeof MyString, "You are now spectating %s! Type /specoff to stop!", tname);
SendClientMessage(playerid, COLOR_GREEN, MyString);
new Float:hp, Float:ar;
GetPlayerHealth(Target, hp);
GetPlayerArmour(Target, ar);
//format(specstring, sizeof(specstring), "~g~SPECTATING PLAYER: ~w~%s(%d)~n~~w~Type ~y~/specoff ~w~to stop!\nHealth: %d\nArmour: %d",tname, Target, GetPlayerHealth(Target, health), GetPlayerArmour(Target,armour));
format(MyString, 256, "~w~- %s(%d) -~n~~n~~y~Health: ~w~%0.1f ~l~- ~y~Armour: ~w~%0.1f ~l~- ~y~Money: ~w~$%d~n~~n~~r~< Sprint - Jump >", MyString,tname,hp,ar,GetPlayerMoney(tname));
TextDrawSetString(SpectationText, MyString);
TextDrawShowForPlayer(playerid,SpectationText);


}
else return SendClientMessage(playerid,COLOR_RED,"ERROR: Player is in spectate mode!");
}
else return SendClientMessage(playerid,COLOR_RED,"ERROR: You are already in spectate mode!");

#endif
return 1;
}

format(MyString, 256, "~w~- %s(%d) -~n~~n~~y~Health: ~w~%0.1f ~l~- ~y~Armour: ~w~%0.1f ~l~- ~y~Money: ~w~$%d~n~~n~~r~< Sprint - Jump >", MyString,tname,hp,ar,GetPlayerMoney(tname));

[ABK]Antonio
01/04/2012, 12:39 AM
....Learn what parameters of functions are before you use them...


GetPlayerMoney(Target)

Twisted_Insane
01/04/2012, 12:56 AM
Ah, okay, thanks! Yeah sorry bro, I'm a little tired, it's 5:00 AM here...

Twisted_Insane
01/04/2012, 05:00 PM
Okay, I've tried to spectate someone now on my server, but the textdraw won't appear! WHY?

CMD:spec(playerid,params[])
{


if(gPlayerSpectating[playerid] == 0)
{
new Target;
if(sscanf(params, "u", Target)) return SendClientMessage(playerid, COLOR_ORANGE, "USAGE: /spec [playerid]");

if(gPlayerSpectating[Target] == 0)
{
if(Target == playerid) return SendClientMessage(playerid, COLOR_RED, "SERVER: You can't spec yourself!");
if(!IsPlayerConnected(Target))
return SendClientMessage(playerid, COLOR_RED, "ERROR: Player is not connected!");

TogglePlayerSpectating(playerid, 1);
PlayerSpectatePlayer(playerid, Target);
SetPlayerInterior(playerid,GetPlayerInterior(Targe t));
gSpectateID[playerid] = Target;
gPlayerSpectating[playerid] = 1;
gSpectateType[playerid] = ADMIN_SPEC_TYPE_PLAYER;
new tname[MAX_PLAYER_NAME];
GetPlayerName(Target,tname,sizeof(tname));
new MyString[128];
format(MyString,sizeof MyString, "You are now spectating %s! Type /specoff to stop!", tname);
SendClientMessage(playerid, COLOR_GREEN, MyString);
new Float:hp, Float:ar;
GetPlayerHealth(Target, hp);
GetPlayerArmour(Target, ar);
//format(specstring, sizeof(specstring), "~g~SPECTATING PLAYER: ~w~%s(%d)~n~~w~Type ~y~/specoff ~w~to stop!\nHealth: %d\nArmour: %d",tname, Target, GetPlayerHealth(Target, health), GetPlayerArmour(Target,armour));
format(MyString, 256, "~w~- %s(%d) -~n~~n~~y~Health: ~w~%0.1f ~l~- ~y~Armour: ~w~%0.1f ~l~- ~y~Money: ~w~$%d~n~~n~~r~< Sprint - Jump >", MyString,tname,hp,ar,GetPlayerMoney(Target));
TextDrawSetString(SpectationText, MyString);
TextDrawShowForPlayer(playerid,SpectationText);


}
else return SendClientMessage(playerid,COLOR_RED,"ERROR: Player is in spectate mode!");
}
else return SendClientMessage(playerid,COLOR_RED,"ERROR: You are already in spectate mode!");

return 1;
}

CMD:specoff(playerid,params[])
{

if(gPlayerSpectating[playerid] == 1)
{
TogglePlayerSpectating(playerid, 0);
gSpectateID[playerid] = INVALID_PLAYER_ID;
gPlayerSpectating[playerid] = 0;
gSpectateType[playerid] = ADMIN_SPEC_TYPE_NONE;
SendClientMessage(playerid, COLOR_GREEN, "You have stopped spectating!");
TextDrawHideForPlayer(playerid,SpectationText);
}
else SendClientMessage(playerid,COLOR_RED,"ERROR: You are not in spectate mode!");


return 1;
}

ReneG
01/04/2012, 07:15 PM
You are formatting "MyString" with MyString? Doesn't make sense.
this is what you are doing.
format(MyString, 256, "%s",MyString);

Twisted_Insane
01/04/2012, 07:16 PM
Oh, I just saw that now, lol! So it gotta look like that?

format(MyString, sizeof(MyString) " %s");

Jonny5
01/04/2012, 07:19 PM
well if your useing format(MyString, sizeof(MyString) " %s",MyString);

it would just update itself with itself
it would be like writing somevar = somevar;

Twisted_Insane
01/04/2012, 09:07 PM
So how shall I use it? I thought the way I've posted was right!?

Jonny5
01/04/2012, 09:16 PM
well it can be used like that just what your doing i not correct,

look at this line

format(MyString, 256, "~w~- %s(%d) -~n~~n~~y~Health: ~w~%0.1f ~l~- ~y~Armour: ~w~%0.1f ~l~- ~y~Money: ~w~$%d~n~~n~~r~< Sprint - Jump >", MyString,tname,hp,ar,GetPlayerMoney(Target));


format expects :
string
int
float
float
int


and your passing:

string (old mystring var) read below
string (tname)
float (hp)
float (armor)
int (GetPlayerMoney(Target))



as far as mystring goes it contains "You are now spectating %s! Type /specoff to stop!"
already, and enless you want that included in your TD string....
this is why it was questioned.

but I have used it like this also in my code looks something like

new i,aSize,strDialog[1024];
aSize = sizeof(aWeaponNames);
for (i=0;i<aSize;i++){
if (i==0) format(strDialog, sizeof (strDialog), "%s", aWeaponNames[i][eWeaponN_Name]);
else format(strDialog, sizeof (strDialog), "%s\n%s",strDialog, aWeaponNames[i][eWeaponN_Name]);
}




hope this clears it up

Twisted_Insane
01/04/2012, 09:29 PM
Yes, I certainly know now what I did wrong. But I still don't know how the new code should look like.

Jonny5
01/04/2012, 10:07 PM
well it depends on what you want the TD to show but if it was me id do


format(MyString, 256, "~w~- %s(%d) -~n~~n~~y~Health: ~w~%0.1f ~l~- ~y~Armour: ~w~%0.1f ~l~- ~y~Money: ~w~$%d~n~~n~~r~< Sprint - Jump >", tname,Target,hp,ar,GetPlayerMoney(Target));



if your other code works ok it should display


Name(id)
Health:value
Armor:value
Money:value