PDA

View Full Version : Problem with autoassign


yellow
31/07/2014, 07:51 PM
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?

yellow
01/08/2014, 09:57 AM
push. Need to hurry :/

McBan
01/08/2014, 09:59 AM
What errors do you get during compiling?

yellow
01/08/2014, 10:04 AM
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;
}

McBan
01/08/2014, 10:08 AM
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.

Vince
01/08/2014, 10:22 AM
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.

yellow
01/08/2014, 01:04 PM
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.

yellow
01/08/2014, 04:39 PM
/edit. Only for 1 person the class changes. The other players still have class 0

yellow
02/08/2014, 01:34 PM
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?

yellow
03/08/2014, 01:12 PM
Push. Still the problem that noone gets class 3

yellow
03/08/2014, 03:56 PM
Problem solved.
stock SetClass(playerid)
{
new r = random(3);
switch(r){
case 0:{
m_inno++;
Class[playerid] = 1;
}
case 1:{
m_trait++;
Class[playerid]=2;
if(m_trait > 2){
m_trait--;
new r2 = random(2);
switch(r2){
case 0:{
m_inno++;
Class[playerid] = 1;
}
case 1:{
if(m_det >= 1) {Class[playerid]=1;m_inno++;}
else {Class[playerid]=3;m_det++;}
}
}
}
}
case 2:{
m_det++;
Class[playerid]=3;
if(m_det > 1){
m_det--;
new r2 = random(2);
switch(r2){
case 0:{
m_inno++;
Class[playerid]=1;
}
case 1:{
if(m_trait >= 2) {Class[playerid]=1;m_inno++;}
else {Class[playerid]=2;m_trait++;}
}
}
}
}
}
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;
}