Scripting help please -
LoganStone - 14.01.2013
Hi i try to set my admin colours
if(PlayerInfo[playerid][pAdmin] >= 7) format(string,sizeof(string),"(( {FF0000}%s {FFFFFF} %s: %s ))", RPN(playerid), params);
if(PlayerInfo[playerid][pAdmin] >= 6) format(string,sizeof(string),"(( {0000FF}%s {FFFFFF} %s: %s ))", RPN(playerid), params);
if(PlayerInfo[playerid][pAdmin] >= 5) format(string,sizeof(string),"(( {00FF00}%s {FFFFFF} %s: %s ))", RPN(playerid), params);
if(PlayerInfo[playerid][pAdmin] >= 4) format(string,sizeof(string),"(( {FFD400}%s {FFFFFF} %s: %s ))", RPN(playerid), params);
if(PlayerInfo[playerid][pAdmin] >= 3) format(string,sizeof(string),"(( {800080}%s {FFFFFF} %s: %s ))", RPN(playerid), params);
if(PlayerInfo[playerid][pAdmin] >= 2) format(string,sizeof(string),"(( {FFD400}%s {FFFFFF} %s: %s ))", RPN(playerid), params);
if(PlayerInfo[playerid][pAdmin] >= 1) format(string,sizeof(string),"(( {FFFFFF}%s {FFFFFF} %s: %s ))", RPN(playerid), params);
It shows no errors in script but when i go ingame it still shows White for everything admin level
Any help?
Respuesta: Scripting help please -
Fabio11 - 14.01.2013
Add { before format and } after it.
Re: Scripting help please -
CoaPsyFactor - 14.01.2013
{} won't help the thing is you are going from 7 to 1 and that's why is white
cus last if is >= 1 and if you are lvl 7 it will enter that if and set color to white
pawn Код:
if(PlayerInfo[playerid][pAdmin] >= 1) format(string,sizeof(string),"(( {FFFFFF}%s {FFFFFF} %s: %s ))", RPN(playerid), params);
if(PlayerInfo[playerid][pAdmin] >= 2) format(string,sizeof(string),"(( {FFD400}%s {FFFFFF} %s: %s ))", RPN(playerid), params);
if(PlayerInfo[playerid][pAdmin] >= 3) format(string,sizeof(string),"(( {800080}%s {FFFFFF} %s: %s ))", RPN(playerid), params);
if(PlayerInfo[playerid][pAdmin] >= 4) format(string,sizeof(string),"(( {FFD400}%s {FFFFFF} %s: %s ))", RPN(playerid), params);
if(PlayerInfo[playerid][pAdmin] >= 5) format(string,sizeof(string),"(( {00FF00}%s {FFFFFF} %s: %s ))", RPN(playerid), params);
if(PlayerInfo[playerid][pAdmin] >= 6) format(string,sizeof(string),"(( {0000FF}%s {FFFFFF} %s: %s ))", RPN(playerid), params);
if(PlayerInfo[playerid][pAdmin] >= 7) format(string,sizeof(string),"(( {FF0000}%s {FFFFFF} %s: %s ))", RPN(playerid), params);
this will work
Re: Scripting help please -
LoganStone - 14.01.2013
I already have that, found problem i needed to have [ else if ] instead of if thx though
Re: Scripting help please -
CoaPsyFactor - 14.01.2013
you dont have
with code i post here will do the job, but its not wrong to do with else if
Re: Scripting help please -
jessejanssen - 14.01.2013
Quote:
Originally Posted by LoganStone
I already have that, found problem i needed to have [ else if ] instead of if thx though
|
Quote:
Originally Posted by CoaPsyFactor
you dont have with code i post here will do the job, but its not wrong to do with else if
|
It's even better to use "else if" instead of "if" over and over because with the "if - else if" structure if the first "if" statement is correct it won't read all the "else if" statements after it, it would even be better to use a switch:
pawn Код:
switch(PlayerInfo[playerid][pAdmin])
{
case 1:
{
format(string,sizeof(string),"(( {FFFFFF}%s {FFFFFF} %s: %s ))", RPN(playerid), params);
}
case 2:
{
format(string,sizeof(string),"(( {FFD400}%s {FFFFFF} %s: %s ))", RPN(playerid), params);
}
case 3:
{
format(string,sizeof(string),"(( {800080}%s {FFFFFF} %s: %s ))", RPN(playerid), params);
}
case 4:
{
format(string,sizeof(string),"(( {FFD400}%s {FFFFFF} %s: %s ))", RPN(playerid), params);
}
case 5:
{
format(string,sizeof(string),"(( {00FF00}%s {FFFFFF} %s: %s ))", RPN(playerid), params);
}
case 6:
{
format(string,sizeof(string),"(( {0000FF}%s {FFFFFF} %s: %s ))", RPN(playerid), params);
}
case 7:
{
format(string,sizeof(string),"(( {FF0000}%s {FFFFFF} %s: %s ))", RPN(playerid), params);
}
}
That's it for my advice.
Best regards,
Jesse
Re: Scripting help please -
CoaPsyFactor - 15.01.2013
but if you ask me i would do that this way
pawn Код:
AdminColors[7][7] = {
"FFFFFF",
"FFD400",
"800080",
"FFD400",
"00FF00",
"0000FF",
"FF0000"
}
format(string,sizeof(string),"(( {%s}%s {FFFFFF} %s: %s ))", AdminColors[PlayerInfo[playerid][pAdmin]-1], RPN(playerid), params);
I don't know why would I, but I would make it this way, only there could be problem if Admin is bigger than 7 or smaller than 1
Re: Scripting help please -
jessejanssen - 15.01.2013
Quote:
Originally Posted by ******
jessejanssen you were so close - the description of why "else"should be used was spot on, then you used "switch" and got it all wrong! The original code had ">=", yours is equivalent to "==".
|
I'm not going to argue or anything but as you can see his code:
pawn Код:
if(PlayerInfo[playerid][pAdmin] >= 1) format(string,sizeof(string),"(( {FFFFFF}%s {FFFFFF} %s: %s ))", RPN(playerid), params);
if(PlayerInfo[playerid][pAdmin] >= 2) format(string,sizeof(string),"(( {FFD400}%s {FFFFFF} %s: %s ))", RPN(playerid), params);
if(PlayerInfo[playerid][pAdmin] >= 3) format(string,sizeof(string),"(( {800080}%s {FFFFFF} %s: %s ))", RPN(playerid), params);
if(PlayerInfo[playerid][pAdmin] >= 4) format(string,sizeof(string),"(( {FFD400}%s {FFFFFF} %s: %s ))", RPN(playerid), params);
if(PlayerInfo[playerid][pAdmin] >= 5) format(string,sizeof(string),"(( {00FF00}%s {FFFFFF} %s: %s ))", RPN(playerid), params);
if(PlayerInfo[playerid][pAdmin] >= 6) format(string,sizeof(string),"(( {0000FF}%s {FFFFFF} %s: %s ))", RPN(playerid), params);
if(PlayerInfo[playerid][pAdmin] >= 7) format(string,sizeof(string),"(( {FF0000}%s {FFFFFF} %s: %s ))", RPN(playerid), params);
It will also do things when numbers are equal, just in a code using way. I see how you mean the bigger then point but for example if PlayerInfo[playerid][pAdmin] == 1 ( Or higher. ) it sets the name color to {FFFFFF} but if it gets == 2 ( Or higher ) it will set it to {FFD400} what will cause the first if statement ( if(PlayerInfo[playerid][pAdmin] >= 1 )
will only be usefully applied when it is actually exactly 1. And so you can continue with all the else if statements, there is however indeed a mistake in my code, but I'd fix it like this:
pawn Код:
if(PlayerInfo[playerid][pAdmin] >= 1 && PlayerInfo[playerid][pAdmin] <= 6)
{
switch(PlayerInfo[playerid][pAdmin])
{
case 1:
{
format(string,sizeof(string),"(( {FFFFFF}%s {FFFFFF} %s: %s ))", RPN(playerid), params);
}
case 2:
{
format(string,sizeof(string),"(( {FFD400}%s {FFFFFF} %s: %s ))", RPN(playerid), params);
}
case 3:
{
format(string,sizeof(string),"(( {800080}%s {FFFFFF} %s: %s ))", RPN(playerid), params);
}
case 4:
{
format(string,sizeof(string),"(( {FFD400}%s {FFFFFF} %s: %s ))", RPN(playerid), params);
}
case 5:
{
format(string,sizeof(string),"(( {00FF00}%s {FFFFFF} %s: %s ))", RPN(playerid), params);
}
case 6:
{
format(string,sizeof(string),"(( {0000FF}%s {FFFFFF} %s: %s ))", RPN(playerid), params);
}
}
}
else if(PlayerInfo[playerid][pAdmin] >= 7)
{
format(string,sizeof(string),"(( {FF0000}%s {FFFFFF} %s: %s ))", RPN(playerid), params);
}
Best regards,
Jesse
Re: Scripting help please -
jessejanssen - 15.01.2013
Quote:
Originally Posted by ******
That is a VERY good point!
You could also do:
pawn Код:
switch(PlayerInfo[playerid][pAdmin]) { case 0: { // Do nothing. } case 1: { format(string,sizeof(string),"(( {FFFFFF}%s {FFFFFF} %s: %s ))", RPN(playerid), params); } case 2: { format(string,sizeof(string),"(( {FFD400}%s {FFFFFF} %s: %s ))", RPN(playerid), params); } case 3: { format(string,sizeof(string),"(( {800080}%s {FFFFFF} %s: %s ))", RPN(playerid), params); } case 4: { format(string,sizeof(string),"(( {FFD400}%s {FFFFFF} %s: %s ))", RPN(playerid), params); } case 5: { format(string,sizeof(string),"(( {00FF00}%s {FFFFFF} %s: %s ))", RPN(playerid), params); } case 6: { format(string,sizeof(string),"(( {0000FF}%s {FFFFFF} %s: %s ))", RPN(playerid), params); } default: // 7 .. cellmax: { format(string,sizeof(string),"(( {FF0000}%s {FFFFFF} %s: %s ))", RPN(playerid), params); } }
Assuming you know the admin level will never go negative (easy enough in a given script). Or just use an array.
Edit: As a side note, you can write this:
pawn Код:
if(PlayerInfo[playerid][pAdmin] >= 1 && PlayerInfo[playerid][pAdmin] <= 6)
As:
pawn Код:
if (1 <= PlayerInfo[playerid][pAdmin] <= 6)
In PAWN.
|
I just learned two new things haha! Thanks for telling me this and I guess the topic creater has his help too!
Best regards,
Jesse