how to find case's value
#1

PHP код:
CMD:setfreq(playerid,params[])
{
    if(
PlayerHasItem(playerid,"Statie Radio"))
    {
        new 
slotvaloare ,string[128];
        if(
sscanf(params"i"slotvalue)) return SendClientMessage(playerid,-1,""COL_RED"Cmds: /setfreq [Slot] [Freq]");
        switch(
slot)
        {
        case 
1pInfo[playerid][pRadioFreq1] = value;
        case 
2pInfo[playerid][pRadioFreq2] = value;
        case 
3pInfo[playerid][pRadioFreq3] = value;
        }
        
format(string,sizeof(string),""COL_RED"Cmds: You have changed slot number %i frequency at %i.",slotvalue);
        
SendClientMessage(playerid,-1,string);
    }
    else {
        
SendClientMessage(playerid,-1,""COL_RED"ERROR: Where's your radio?");
    } 
Known errors:
  • At server log it shows "sscanf warning: Format specifier does not match parameter count."
  • When I type /setfreq, any of pRadioFreq won't change. It remains at 0
Reply
#2

Show us full code.. switch( ? ) .
Reply
#3

PHP код:
 new slotvalue,string[128];
        if(
sscanf(params"i"slotvalue)) return SendClientMessage(playerid,-1,""COL_RED"Cmds: /setfreq [Slot] [Freq]");
        switch(
slot)
        {
        case 
1pInfo[playerid][pRadioFreq1] = value;
        case 
2pInfo[playerid][pRadioFreq2] = value;
        case 
3pInfo[playerid][pRadioFreq3] = value;
        }
        
format(string,sizeof(string),""COL_RED"Cmds: You have changed slot number %i at frequency %i.",?????????, valoare);
        
SendClientMessage(playerid,-1,string);
    } 
Reply
#4

Why don't you use a multi dimensional array for the radio freq and do:

Код:
pInfo[playerid][pRadioFreq][slot] = value;
Then assign the slots -1 by default (which means invalid).

To find a slot simply loop through it, the first slot that is -1 will be the new slot you can use.

This will also allow you to change the amount of slots at any time dynamically, if you ever need more.
Reply
#5

?? = "slot" !?

Код:
 new slot, value,string[128]; 
        if(sscanf(params, "i", slot, value)) return SendClientMessage(playerid,-1,""COL_RED"Cmds: /setfreq [Slot] [Freq]"); 
        switch(slot) 
        { 
        case 1: pInfo[playerid][pRadioFreq1] = value; 
        case 2: pInfo[playerid][pRadioFreq2] = value; 
        case 3: pInfo[playerid][pRadioFreq3] = value; 
        } 
        format(string,sizeof(string),""COL_RED"Cmds: You have changed slot number %i at frequency %i.",slot, value); 
        SendClientMessage(playerid,-1,string); 
    }
Reply
#6

Well, I made

PHP код:
/r1  (slot1)
/
r2 (Slot2)
/
r3 (slot3
PHP код:
And if you type /r1  it shows:  [CH %S1
At /r2 it shows S2
At 
/r3 it shows S3

But command /setfreq it won't set the value of the "pRadioFreqX" (i have replaced ?? ?? ? with slot)

It sets 0 every pradiofreq



"sscanf warning: Format specifier does not match parameter count."
Reply
#7

You have an mistake here in sscanf ( params, "i" ) need to be ( params, "ii" )

replace

Код:
        if(sscanf(params, "ii", slot, value)) return SendClientMessage(playerid,-1,""COL_RED"Cmds: /setfreq [Slot] [Freq]");
Reply
#8

Thanks
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)