Posts: 3,351
Threads: 780
Joined: Jan 2010
Can someone tell me why this GMChange public doesn't show the random game that has been changed in a message?
Код:
public GMChange()
{
switch(random(4))
{
case 0: SendRconCommand("changemode gmone");
case 1: SendRconCommand("changemode gmtwo");
case 2: SendRconCommand("changemode gmthree");
case 3: SendRconCommand("changemode gmfour");
}
new modestring[128], ircs[128];
format(modestring,sizeof(modestring),">> Your next mission will be: {F2C80C}%s {FFFFFF}...please wait.",random(4));
SendClientMessageToAll(-1,modestring);
format(ircs,sizeof(ircs),">> Changing mission, next will be: %s", random(4));
IRC_GroupSay(groupID, IRC_CHANNEL, ircs);
return 1;
}
Posts: 2,593
Threads: 34
Joined: Dec 2007
random is integer so should be %d
pawn Код:
public GMChange()
{
new str[128], rnd = random(4);
format(str,sizeof(str),">> Your next mission will be: {F2C80C}%d {FFFFFF}...please wait.",rnd);
SendClientMessageToAll(-1,str);
format(str,sizeof(str),">> Changing mission, next will be: %d", rnd);
IRC_GroupSay(groupID, IRC_CHANNEL, str);
switch(rnd)
{
case 0: SendRconCommand("changemode gmone");
case 1: SendRconCommand("changemode gmtwo");
case 2: SendRconCommand("changemode gmthree");
default: SendRconCommand("changemode gmfour");
}
return 1;
}
Posts: 3,351
Threads: 780
Joined: Jan 2010
Now it says "Your next mission will be 0.."
Posts: 1,266
Threads: 6
Joined: Oct 2014
PHP код:
new GMChange[][] =
{
"gmone",
"gmtwo",
"gmthree",
"gmfour"
};
forward GMChange1();
public GMChange1() {
new modestring[128],ircs[128];
new randmode = random(sizeof(GMChange));
format(modestring,sizeof(modestring),">> Your next mission will be: {F2C80C}%s {FFFFFF}...please wait.",GMChange[randmode]);
SendClientMessageToAll(-1,modestring);
format(ircs,sizeof(ircs),">> Changing mission, next will be: %s", GMChange[randmode]);
IRC_GroupSay(groupID, IRC_CHANNEL, ircs);
format(modestring,sizeof(modestring),"changemode %s",GMChange[randmode]);
SendRconCommand(modestring);
return 1;
}
Posts: 1,208
Threads: 36
Joined: Apr 2015
PHP код:
public GMChange(){
new rand = random(4), buffer[128];
format(buffer,sizeof(buffer),">> Your next mission will be: {F2C80C}%d {FFFFFF}...please wait.",rand);
SendClientMessageToAll(-1,buffer);
format(buffer,sizeof(buffer),">> Changing mission, next will be: %d", rand);
IRC_GroupSay(groupID, IRC_CHANNEL, buffer);
switch(rand)
{
case 0: SendRconCommand("changemode gmone");
case 1: SendRconCommand("changemode gmtwo");
case 2: SendRconCommand("changemode gmthree");
case 3: SendRconCommand("changemode gmfour");
}
return 1;
}
Posts: 6,242
Threads: 8
Joined: Jun 2008
Quote:
Originally Posted by AbyssMorgan
PHP код:
public GMChange(){
new rand = random(4), buffer[128];
format(buffer,sizeof(buffer),">> Your next mission will be: {F2C80C}%d {FFFFFF}...please wait.",rand);
SendClientMessageToAll(-1,buffer);
format(buffer,sizeof(buffer),">> Changing mission, next will be: %d", rand);
IRC_GroupSay(groupID, IRC_CHANNEL, buffer);
switch(rand)
{
case 0: SendRconCommand("changemode gmone");
case 1: SendRconCommand("changemode gmtwo");
case 2: SendRconCommand("changemode gmthree");
case 3: SendRconCommand("changemode gmfour");
}
return 1;
}
|
^^ This fellas got the better idea... Re-arranged your code to simply run through in a different order, which is more logical in a sense.
Posts: 3,351
Threads: 780
Joined: Jan 2010
Ralfie & fjlalt, your code doesn't even do the restart. AbyssMorgan, same thing, it shows "0".
Posts: 1,208
Threads: 36
Joined: Apr 2015
because it gives random from 0 to 3, and names are from 1 to 4
fix:
PHP код:
format(buffer,sizeof(buffer),">> Your next mission will be: {F2C80C}%d {FFFFFF}...please wait.",rand+1);
SendClientMessageToAll(-1,buffer);
format(buffer,sizeof(buffer),">> Changing mission, next will be: %d", rand+1);
IRC_GroupSay(groupID, IRC_CHANNEL, buffer);