SA-MP Forums Archive
Public() help - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Public() help (/showthread.php?tid=591157)



Public() help - Face9000 - 08.10.2015

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;
}



Re: Public() help - Jefff - 08.10.2015

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;
}



Re: Public() help - Face9000 - 09.10.2015

Now it says "Your next mission will be 0.."


Re: Public() help - Hessu - 09.10.2015

Well first off, in the code you got on top, you are swithing random(4). This is ok, but you then want to send a message (with the selected gamemode?) so, as Jeff posted, assign the random to a array.

Take help from here : https://sampwiki.blast.hk/wiki/Random


Re: Public() help - Evocator - 09.10.2015

Код:
static const GameModes[][] = 
{
	{"Gamemode0"},
	{"Gamemode1"},
	{"Gamemode2"},
	{"Gamemode3"}
}

public GMChange()
{
	new 
		rand = random(sizeof (GameModes)),
		string[128]
	;

	format(string, sizeof(string), "changemode %s", GameModes[rand]);
	SendRconCommand(string);
	
	new ;
	
	format(string,sizeof(string), ">> Your next mission will be: {F2C80C}%s {FFFFFF}...please wait.", GameModes[rand]);
	SendClientMessageToAll(-1,string);
	
	format(string,sizeof(string), ">> Changing mission, next will be: %s", GameModes[rand]);
	IRC_GroupSay(groupID, IRC_CHANNEL, string);
	return 1;
}



Re: Public() help - jlalt - 09.10.2015

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(groupIDIRC_CHANNELircs);
   
format(modestring,sizeof(modestring),"changemode %s",GMChange[randmode]);
   
SendRconCommand(modestring);
   return 
1;




Re: Public() help - AbyssMorgan - 09.10.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(groupIDIRC_CHANNELbuffer);
    
    switch(
rand)
    {
        case 
0SendRconCommand("changemode gmone");
        case 
1SendRconCommand("changemode gmtwo");
        case 
2SendRconCommand("changemode gmthree");
        case 
3SendRconCommand("changemode gmfour");
    }
    
    return 
1;




Re: Public() help - Sew_Sumi - 09.10.2015

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(groupIDIRC_CHANNELbuffer);
    
    switch(
rand)
    {
        case 
0SendRconCommand("changemode gmone");
        case 
1SendRconCommand("changemode gmtwo");
        case 
2SendRconCommand("changemode gmthree");
        case 
3SendRconCommand("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.


Re: Public() help - Face9000 - 09.10.2015

Ralfie & fjlalt, your code doesn't even do the restart. AbyssMorgan, same thing, it shows "0".


Re: Public() help - AbyssMorgan - 09.10.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(groupIDIRC_CHANNELbuffer);