Problem with autoassign
#1

Hey,

Got this Code

Код:
ocmd:start(playerid,params[])
{
	PrepTimer = SetTimer("prepcd",1000,true);//20 Sekunden countdown
	ShowTextForPlayer();
	
	
	

 	Textdraw1 = TextDrawCreate(550.000000, 399.000000, "  --:--");
	TextDrawBackgroundColor(Textdraw1, 255);
	TextDrawFont(Textdraw1, 1);
	TextDrawLetterSize(Textdraw1, 0.500000, 2.000000);
	TextDrawColor(Textdraw1, -1);
	TextDrawSetOutline(Textdraw1, 0);
	TextDrawSetProportional(Textdraw1, 1);
	TextDrawSetShadow(Textdraw1, 1);
	TextDrawUseBox(Textdraw1, 1);
	TextDrawBoxColor(Textdraw1, 255);
	TextDrawTextSize(Textdraw1, 630.000000, 0.000000);
	

	Textdraw2 = TextDrawCreate(542.000000, 392.000000, ".");
	TextDrawBackgroundColor(Textdraw2, 255);
	TextDrawFont(Textdraw2, 1);
	TextDrawLetterSize(Textdraw2, 9.249999, 1.000000);
	TextDrawColor(Textdraw2, -1);
	TextDrawSetOutline(Textdraw2, 0);
	TextDrawSetProportional(Textdraw2, 1);
	TextDrawSetShadow(Textdraw2, 1);

    TextDrawShowForAll(Textdraw1);
	TextDrawShowForAll(Textdraw2);


	return 1;
}

public prepcd()
{
	if(prepcount > 1)
	{
	    prepcount --;
		new string[20];
		format(string,sizeof(string)," 00:%02d",prepcount);
		TextDrawSetString(Textdraw1,string);
	}
	else
	{
	    KillTimer(PrepTimer);
	 //   SetTimer("Duration",4*60*100,false);
	    new i;
	    for(;i<MAX_PLAYERS;i++)
	    {
	        if(!IsPlayerConnected(i))continue;
	        SetClass(i);
	    }
	}
}


stock ShowTextForPlayer()
{
	new i;
	for(;i<MAX_PLAYERS;i++)
	{
	    if(!IsPlayerConnected(i))continue;
    	Textdraw0[i] = CreatePlayerTextDraw(i,550.000000, 377.000000, "Preparing");
		PlayerTextDrawBackgroundColor(i,Textdraw0[i], 255);
		PlayerTextDrawFont(i,Textdraw0[i], 1);
		PlayerTextDrawLetterSize(i,Textdraw0[i], 0.500000, 2.000000);
		PlayerTextDrawColor(i,Textdraw0[i], -1);
		PlayerTextDrawSetOutline(i,Textdraw0[i], 0);
		PlayerTextDrawSetProportional(i,Textdraw0[i], 1);
		PlayerTextDrawSetShadow(i,Textdraw0[i], 1);
		PlayerTextDrawUseBox(i,Textdraw0[i], 1);
		PlayerTextDrawBoxColor(i,Textdraw0[i], 255);
		PlayerTextDrawTextSize(i,Textdraw0[i], 630.000000, 0.000000);
		PlayerTextDrawShow(i,PlayerText:Textdraw0[i]);
	}
	return 1;
}

stock SetClass(playerid)
{
	new randclass = random(3);
	printf("%d",randclass);
	if(randclass == 1)//inno
	{
	    m_inno ++;
	    Class[playerid] = 1;
	}
	else if(randclass == 2)//trait
	{
		m_trait++;
		if(m_trait > 2)
		{
		    new rand2 = random(2);
			if(rand2 == 1)
			{
			    printf("%d",rand2);
			    m_inno ++;
			    Class[playerid] = 1;
			}
			else if(rand2 == 2)
			{
			    if(m_det == 1)return Class[playerid] = 1, m_inno ++;
			    else Class[playerid] = 3; m_det ++;
			}
		}
		else Class[playerid] = 2;//sonst
	}
	else if(randclass == 3)//det
	{

	    m_det ++;
	    if(m_det > 1)
	    {
	        new rand3 = random(2);
	        if(rand3 == 1)
	        {
	            m_inno++;
	            Class[playerid] = 1;
	        }
	        else if(rand3 == 2)
	        {
	            if(m_trait > 2)return Class[playerid] = 1, m_inno++;
	            else Class[playerid] = 2; m_det++;
	        }
	    }
	    else Class[playerid] = 3;
	}
	new string[17];
 	format(string,sizeof(string),"%s",CNames[Class[playerid]]);
	PlayerTextDrawSetString(playerid,Textdraw0[playerid],string);
	printf("class: %d %d",Class[playerid],playerid);
	return 1;
}
The Problem is: Only 1 Player textdraw gets updated. e.g Player A, Player b & player C are on the server. Player A has class 1, player b has class 2 & player c has class 3. Now the textdraw should update, but it updates just for on player. And the class, which should be 1 & 2 is 0.
So the class and the textdraw updates for just one player.

(sorry for my bad english)
I hope, you understand it.

Where's the mistake?
Reply
#2

push. Need to hurry :/
Reply
#3

What errors do you get during compiling?
Reply
#4

There are no Errors.

whole Code
Код:
ocmd:start(playerid,params[])
{
	PrepTimer = SetTimer("prepcd",1000,true);

	ShowTextForPlayer();//Spielertd wird geladen (Traitor, Innocent, Detective)
	
	
	
	// Uhrzeit
 	Textdraw1 = TextDrawCreate(550.000000, 399.000000, "  --:--");
	TextDrawBackgroundColor(Textdraw1, 255);
	TextDrawFont(Textdraw1, 1);
	TextDrawLetterSize(Textdraw1, 0.500000, 2.000000);
	TextDrawColor(Textdraw1, -1);
	TextDrawSetOutline(Textdraw1, 0);
	TextDrawSetProportional(Textdraw1, 1);
	TextDrawSetShadow(Textdraw1, 1);
	TextDrawUseBox(Textdraw1, 1);
	TextDrawBoxColor(Textdraw1, 255);
	TextDrawTextSize(Textdraw1, 630.000000, 0.000000);
	
	//Trennstrich
	Textdraw2 = TextDrawCreate(542.000000, 392.000000, ".");
	TextDrawBackgroundColor(Textdraw2, 255);
	TextDrawFont(Textdraw2, 1);
	TextDrawLetterSize(Textdraw2, 9.249999, 1.000000);
	TextDrawColor(Textdraw2, -1);
	TextDrawSetOutline(Textdraw2, 0);
	TextDrawSetProportional(Textdraw2, 1);
	TextDrawSetShadow(Textdraw2, 1);

    TextDrawShowForAll(Textdraw1);
	TextDrawShowForAll(Textdraw2);


	return 1;
}

public prepcd()
{
	if(prepcount > 1)
	{
	    prepcount --;
		new string[20];
		format(string,sizeof(string)," 00:%02d",prepcount);
		TextDrawSetString(Textdraw1,string);
	}
	else
	{
	    KillTimer(PrepTimer);
	 //   SetTimer("Duration",4*60*100,false);
	    new i;
	    for(;i<MAX_PLAYERS;i++)
	    {
	        if(!IsPlayerConnected(i))continue;
	        SetClass(i);
	    }
	}
}


stock ShowTextForPlayer()
{
	new i;
	for(;i<MAX_PLAYERS;i++)
	{
	    if(!IsPlayerConnected(i))continue;
    	Textdraw0[i] = CreatePlayerTextDraw(i,550.000000, 377.000000, "Preparing");
		PlayerTextDrawBackgroundColor(i,Textdraw0[i], 255);
		PlayerTextDrawFont(i,Textdraw0[i], 1);
		PlayerTextDrawLetterSize(i,Textdraw0[i], 0.500000, 2.000000);
		PlayerTextDrawColor(i,Textdraw0[i], -1);
		PlayerTextDrawSetOutline(i,Textdraw0[i], 0);
		PlayerTextDrawSetProportional(i,Textdraw0[i], 1);
		PlayerTextDrawSetShadow(i,Textdraw0[i], 1);
		PlayerTextDrawUseBox(i,Textdraw0[i], 1);
		PlayerTextDrawBoxColor(i,Textdraw0[i], 255);
		PlayerTextDrawTextSize(i,Textdraw0[i], 630.000000, 0.000000);
		PlayerTextDrawShow(i,PlayerText:Textdraw0[i]);
	}
	return 1;
}

stock SetClass(playerid)
{
	new randclass = random(3);
	printf("%d",randclass);
	if(randclass == 1)//inno
	{
	    m_inno ++;
	    Class[playerid] = 1;
	}
	else if(randclass == 2)//trait
	{
		m_trait++;
		if(m_trait > 2)
		{
		    new rand2 = random(2);
			if(rand2 == 1)
			{
			    printf("%d",rand2);
			    m_inno ++;
			    Class[playerid] = 1;
			}
			else if(rand2 == 2)
			{
			    if(m_det == 1)return Class[playerid] = 1, m_inno ++;
			    else Class[playerid] = 3; m_det ++;
			}
		}
		else Class[playerid] = 2;
	}
	else if(randclass == 3)//det
	{

	    m_det ++;
	    if(m_det > 1)
	    {
	        new rand3 = random(2);
	        if(rand3 == 1)
	        {
	            m_inno++;
	            Class[playerid] = 1;
	        }
	        else if(rand3 == 2)
	        {
	            if(m_trait > 2)return Class[playerid] = 1, m_inno++;
	            else Class[playerid] = 2; m_det++;
	        }
	    }
	    else Class[playerid] = 3;
	}
	new string[17];
 	format(string,sizeof(string),"%s",CNames[Class[playerid]]);
	PlayerTextDrawSetString(playerid,Textdraw0[playerid],string);
	printf("class: %d %d",Class[playerid],playerid);
	return 1;
}
Reply
#5

When you type the command start, Only update 1 text draw and then make a public and forward it. In the public function show the second text draw and call another public and do the same thing for the third. If that does not work then there's something wrong with your code which I can't figure out.
Reply
#6

Global textdraws should always be created on a global scale, i.e. in OnGameModeInit. With this structure you will eventually go over the textdraw limit because you're not actually destroying them after use, you're merely overwriting the variable.
Reply
#7

Okay.
Код:
 ocmd:start(playerid,params[])
{
	PrepTimer = SetTimer("prepcd",1000,true);//20 Sekunden countdown
	SendClientMessageToAll(-1," Countdow n gestartet! 20 Sekunden!");
	ShowTextForPlayer();//Spielertd wird geladen (Traitor, Innocent, detec)

    TextDrawShowForAll(Textdraw1);
	TextDrawShowForAll(Textdraw2);


	return 1;
}

public prepcd()
{
	if(prepcount > 1)
	{
	    prepcount --;
		new string[20];
		format(string,sizeof(string)," 00:%02d",prepcount);
		TextDrawSetString(Textdraw1,string);
	}
	else
	{
	    KillTimer(PrepTimer);
	 //   SetTimer("Duration",4*60*100,false);
	    new i;
	    for(;i<MAX_PLAYERS;i++)
	    {
	        if(!IsPlayerConnected(i))continue;
	        SetClass(i);
	    }
	}
}


stock ShowTextForPlayer()
{
	new i;
	for(;i<MAX_PLAYERS;i++)
	{
	    if(!IsPlayerConnected(i))continue;
    	Textdraw0[i] = CreatePlayerTextDraw(i,550.000000, 377.000000, "Preparing");
		PlayerTextDrawBackgroundColor(i,Textdraw0[i], 255);
		PlayerTextDrawFont(i,Textdraw0[i], 1);
		PlayerTextDrawLetterSize(i,Textdraw0[i], 0.500000, 2.000000);
		PlayerTextDrawColor(i,Textdraw0[i], -1);
		PlayerTextDrawSetOutline(i,Textdraw0[i], 0);
		PlayerTextDrawSetProportional(i,Textdraw0[i], 1);
		PlayerTextDrawSetShadow(i,Textdraw0[i], 1);
		PlayerTextDrawUseBox(i,Textdraw0[i], 1);
		PlayerTextDrawBoxColor(i,Textdraw0[i], 255);
		PlayerTextDrawTextSize(i,Textdraw0[i], 630.000000, 0.000000);
		PlayerTextDrawShow(i,PlayerText:Textdraw0[i]);
	}
	return 1;
}

stock SetClass(playerid)
{
	new randclass = random(3);
	printf("%d",randclass);
	if(randclass == 1)//inno
	{
	    m_inno ++;
	    Class[playerid] = 1;
	}
	else if(randclass == 2)//trait
	{
		m_trait++;
		if(m_trait > 2)// wenn mehr als 2
		{
		    new rand2 = random(2);
			if(rand2 == 1)
			{
			    printf("%d",rand2);
			    m_inno ++;
			    Class[playerid] = 1;
			}
			else if(rand2 == 2)
			{
			    if(m_det == 1)return Class[playerid] = 1, m_inno ++;
			    else Class[playerid] = 3; m_det ++;
			}
		}
		else Class[playerid] = 2;//sonst
	}
	else if(randclass == 3)//det
	{

	    m_det ++;
	    if(m_det > 1)
	    {
	        new rand3 = random(2);
	        if(rand3 == 1)
	        {
	            m_inno++;
	            Class[playerid] = 1;
	        }
	        else if(rand3 == 2)
	        {
	            if(m_trait > 2)return Class[playerid] = 1, m_inno++;
	            else Class[playerid] = 2; m_det++;
	        }
	    }
	    else Class[playerid] = 3;
	}
	new string[17];
 	format(string,sizeof(string),"%s",CNames[Class[playerid]]);
	PlayerTextDrawSetString(playerid,Textdraw0[playerid],string);
	printf("class: %d %d",Class[playerid],playerid);
	return 1;
}
Код:
 public OnGameModeInit()
{
	// Don't use these lines if it's a filterscript
	SetGameModeText("Blank Script");
	AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);

 	Textdraw1 = TextDrawCreate(550.000000, 399.000000, "  --:--");
	TextDrawBackgroundColor(Textdraw1, 255);
	TextDrawFont(Textdraw1, 1);
	TextDrawLetterSize(Textdraw1, 0.500000, 2.000000);
	TextDrawColor(Textdraw1, -1);
	TextDrawSetOutline(Textdraw1, 0);
	TextDrawSetProportional(Textdraw1, 1);
	TextDrawSetShadow(Textdraw1, 1);
	TextDrawUseBox(Textdraw1, 1);
	TextDrawBoxColor(Textdraw1, 255);
	TextDrawTextSize(Textdraw1, 630.000000, 0.000000);

	//Trennstrich
	Textdraw2 = TextDrawCreate(542.000000, 392.000000, ".");
	TextDrawBackgroundColor(Textdraw2, 255);
	TextDrawFont(Textdraw2, 1);
	TextDrawLetterSize(Textdraw2, 9.249999, 1.000000);
	TextDrawColor(Textdraw2, -1);
	TextDrawSetOutline(Textdraw2, 0);
	TextDrawSetProportional(Textdraw2, 1);
	TextDrawSetShadow(Textdraw2, 1);
	return 1;
}
It's still the same problem. Only 1 person gets a class. The others stay @Class 0.
Reply
#8

/edit. Only for 1 person the class changes. The other players still have class 0
Reply
#9

Problem solved ( more or less)
Код:
stock SetClass(playerid)
{
	new randclass = random(2)+1;
	printf("%d",randclass);
	if(randclass == 1)//inno
	{
	    m_inno ++;
	    Class[playerid] = 1;
	}
	else if(randclass == 2)//trait
	{
		m_trait++;
		if(m_trait > 2)// wenn mehr als 2
		{
		    new rand2 = random(1)+1;
			if(rand2 == 1)
			{
			    printf("%d",rand2);
			    m_inno ++;
			    Class[playerid] = 1;
			}
			else if(rand2 == 2)
			{
			    if(m_det == 1)return Class[playerid] = 1, m_inno ++;
			    else Class[playerid] = 3; m_det ++;
			}
		}
		else Class[playerid] = 2;//sonst
	}
	else if(randclass == 3)//det
	{

	    m_det ++;
	    if(m_det > 1)
	    {
	        new rand3 = random(1)+1;
	        if(rand3 == 1)
	        {
	            m_inno++;
	            Class[playerid] = 1;
	        }
	        else if(rand3 == 2)
	        {
	            if(m_trait > 2)return Class[playerid] = 1, m_inno++;
	            else Class[playerid] = 2; m_det++;
	        }
	    }
	    else Class[playerid] = 3;
	}
	new string[17];
 	format(string,sizeof(string),"%s",CNames[Class[playerid]]);
	PlayerTextDrawSetString(playerid,Textdraw0[playerid],string);
	printf("class: %d %d",Class[playerid],playerid);
	return 1;
}
But got another problem.
Class 1 & 2 are working, but noone gets class 3
To solve that problem i wrote this code
Код:
public Check()
{
	new i,trait,det;
	for(;i<MAX_PLAYERS;i++)
	{
	    if(!IsPlayerConnected(i))continue;
	    if(Class[i] == 2) {trait ++;}
		else if(Class[i] == 3) {det ++;}
	}
	if(det != 1)
	{
		new id = random(GetMaxPlayers());
		Class[id] = 3;
	}
	if(trait != 2)
	{
		new pl = random(GetMaxPlayers());
		if(Class[pl] != 2){
		    Class[pl] = 2;
		}
		else return 1;
	}
	printf("CLASS NEW %d %d",Class[i], i);
	return 1;
}
It should check if a class has not the given amount of players. Would that work?
Reply
#10

Push. Still the problem that noone gets class 3
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)