PDA

View Full Version : Problem with TextLabels


Jarnu
06/08/2012, 11:58 AM
I want different Labels for different classes..
my code is

if(gClass[playerid] == SOLDIER_CLASS)
{
TogglePlayerControllable(playerid, 1);
ResetPlayerWeapons(playerid);
GivePlayerWeapon(playerid, 5, 1);
GivePlayerWeapon(playerid, 31, 100);
GivePlayerWeapon(playerid, 17, 5);
GivePlayerWeapon(playerid, 27, 200);
GivePlayerWeapon(playerid, 24, 50);
Soldier[playerid] = Create3DTextLabel("Soldier",0x008080FF,30.0,40.0,50.0,40.0, 0);
Attach3DTextLabelToPlayer(Soldier[playerid], playerid, 0.0, 0.0, 0.5);
Delete3DTextLabel(Bomber[playerid]);
Delete3DTextLabel(Sniper[playerid]);
Delete3DTextLabel(Agent[playerid]);
Delete3DTextLabel(Engineer[playerid]);
Delete3DTextLabel(Airforce[playerid]);
}
if(gClass[playerid] == Bomber_CLASS)
{
TogglePlayerControllable(playerid, 1);
ResetPlayerWeapons(playerid);
GivePlayerWeapon(playerid, 18, 5);
GivePlayerWeapon(playerid, 23, 100);
GivePlayerWeapon(playerid, 25, 100);
GivePlayerWeapon(playerid, 27, 100);
Bomber[playerid] = Create3DTextLabel("Bomber",0x008080FF,30.0,40.0,50.0,40.0, 0);
Attach3DTextLabelToPlayer(Bomber[playerid], playerid, 0.0, 0.0, 0.5);
Delete3DTextLabel(Soldier[playerid]);
Delete3DTextLabel(Sniper[playerid]);
Delete3DTextLabel(Agent[playerid]);
Delete3DTextLabel(Engineer[playerid]);
Delete3DTextLabel(Airforce[playerid]);
}
if(gClass[playerid] == Sniper_CLASS)
{
TogglePlayerControllable(playerid, 1);
ResetPlayerWeapons(playerid);
GivePlayerWeapon(playerid, 34, 250);
GivePlayerWeapon(playerid, 29, 250);
GivePlayerWeapon(playerid, 16, 2);
GivePlayerWeapon(playerid, 27, 100);
Sniper[playerid] = Create3DTextLabel("Sniper",0x008080FF,30.0,40.0,50.0,40.0, 0);
Attach3DTextLabelToPlayer(Sniper[playerid], playerid, 0.0, 0.0, 0.5);
Delete3DTextLabel(Bomber[playerid]);
Delete3DTextLabel(Soldier[playerid]);
Delete3DTextLabel(Agent[playerid]);
Delete3DTextLabel(Engineer[playerid]);
Delete3DTextLabel(Airforce[playerid]);
}
if(gClass[playerid] == ENGINEER_CLASS)
{
TogglePlayerControllable(playerid, 1);
ResetPlayerWeapons(playerid);
GivePlayerWeapon(playerid, 27, 200);
GivePlayerWeapon(playerid, 23, 200);
GivePlayerWeapon(playerid, 35, 2);
GivePlayerWeapon(playerid, 16, 2);
Engineer[playerid] = Create3DTextLabel("Engineer",0x008080FF,30.0,40.0,50.0,40.0, 0);
Attach3DTextLabelToPlayer(Engineer[playerid], playerid, 0.0, 0.0, 0.5);
Delete3DTextLabel(Bomber[playerid]);
Delete3DTextLabel(Sniper[playerid]);
Delete3DTextLabel(Agent[playerid]);
Delete3DTextLabel(Soldier[playerid]);
Delete3DTextLabel(Airforce[playerid]);
}
if(gClass[playerid] == AIRFORCE_CLASS)
{
TogglePlayerControllable(playerid, 1);
ResetPlayerWeapons(playerid);
GivePlayerWeapon(playerid, 7, 1);
GivePlayerWeapon(playerid, 17, 3);
GivePlayerWeapon(playerid, 25, 300);
GivePlayerWeapon(playerid, 27, 100);
Airforce[playerid] = Create3DTextLabel("Airforce",0x008080FF,30.0,40.0,50.0,40.0,0);
Attach3DTextLabelToPlayer(Airforce[playerid], playerid, 0.0, 0.0, 0.5);
Delete3DTextLabel(Bomber[playerid]);
Delete3DTextLabel(Sniper[playerid]);
Delete3DTextLabel(Agent[playerid]);
Delete3DTextLabel(Engineer[playerid]);
Delete3DTextLabel(Soldier[playerid]);
}
if(gClass[playerid] == AGENT_CLASS)
{
TogglePlayerControllable(playerid, 1);
ResetPlayerWeapons(playerid);
GivePlayerWeapon(playerid, 9, 1);
GivePlayerWeapon(playerid, 16, 5);
GivePlayerWeapon(playerid, 24, 50);
GivePlayerWeapon(playerid, 35, 1);
GivePlayerWeapon(playerid, 27, 500);
GivePlayerWeapon(playerid, 34, 50);
Agent[playerid] = Create3DTextLabel("Agent",0x008080FF,30.0,40.0,50.0,40.0,0);
Attach3DTextLabelToPlayer(Agent[playerid], playerid, 0.0, 0.0, 0.5);
Delete3DTextLabel(Bomber[playerid]);
Delete3DTextLabel(Sniper[playerid]);
Delete3DTextLabel(Soldier[playerid]);
Delete3DTextLabel(Engineer[playerid]);
Delete3DTextLabel(Airforce[playerid]);
}

This was for OnPlayerSpawn
and when the player select class.. same happens. the above one..

Now the problem is it just shows the Soldier label ONLY! even if the class is Sniper, Agent or anything.. so please help me fixing it. +REP for sure.

Dan.
06/08/2012, 12:04 PM
Delete3DTextLabel(Bomber[playerid]);
Delete3DTextLabel(Sniper[playerid]);
Delete3DTextLabel(Agent[playerid]);
Delete3DTextLabel(Engineer[playerid]);
Delete3DTextLabel(Airforce[playerid]);

Why are you using so many textlabels? Why won't you just use this instead:

new RankLabel[MAX_PLAYERS];

And:

if(gClass[playerid] == SOLDIER_CLASS)
{
TogglePlayerControllable(playerid, 1);
ResetPlayerWeapons(playerid);
GivePlayerWeapon(playerid, 5, 1);
GivePlayerWeapon(playerid, 31, 100);
GivePlayerWeapon(playerid, 17, 5);
GivePlayerWeapon(playerid, 27, 200);
GivePlayerWeapon(playerid, 24, 50);
Delete3DTextLabel(RankLabel[playerid]);
RankLabel[playerid] = Create3DTextLabel("Soldier",0x008080FF,30.0,40.0,50.0,40.0, 0);
Attach3DTextLabelToPlayer(RankLabel[playerid], playerid, 0.0, 0.0, 0.5);
}

Also, are you sure that when a player is choosing his class, you do this? gClass[playerid] = CLASSNAME

Jarnu
06/08/2012, 12:06 PM
i tried.. only with once.. but it bugs.
it Messes up and shows each and every label.

Dan.
06/08/2012, 12:12 PM
If you delete the previous one they won't bug up. But about your problem, when a player chooses his class from the dialog, does it have like:
gClass[playerid] = CLASSNAME

when the player presses Choose Class or whatever button you have?

Jarnu
06/08/2012, 12:31 PM
yeah.

RelaxCafe
06/08/2012, 12:33 PM
This is easier.

new Text3D:teamlabel[MAX_PLAYERS];
new TeamNames[][]=
{
"Team 1",
"Team 2",
"Team 3"//the last one must not have a comma ","
};
public OnGameModeInit()
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
teamlabel[i]=Create3DTextLabel("TeamLabel",0x008080FF,30.0,40.0,50.0,40.0, 0);
}
return 1;
}
public OnPlayerConnect(playerid)
{
Update3DTextLabelText(teamlabel[playerid], 0x008080FF, " ");//making it invisible
return 1;
}
public OnPlayerSpawn(playerid)
{
new string[60];
format(string,60,"%s",TeamNames[gClass[playerid]]);
Update3DTextLabelText(teamlabel[playerid], 0x008080FF, string);
Attach3DTextLabelToPlayer(teamlabel[playerid], playerid, 0.0, 0.0, 0.6);
return 1;
}
public OnPlayerDeath(playerid....)
{
Update3DTextLabelText(teamlabel[playerid], 0x008080FF, " ");//making it invisible
return 1;
}

Adornil
15/08/2015, 02:07 AM
Where I have to paste it amx file