IF to SWITCH
#1

Sooooo... i can make this command:
Код:
YCMD:set(playerid, params[], help)
{
	if(playerVariables[playerid][pAdmin] <= 4) return AdminOnly(playerid, 5);
	if (isnull(params))
	{
		Syntax(playerid, "/set <option> <playerid> <value>");
		SCM(playerid, COLOR_SERVER, "Options: {FFFFFF}money, level");
		return 1;
	}
	new toplayerid, value;
	if (!strcmp(params, "money", true, 5))
	{
		if(sscanf(params[5], "ui", toplayerid, value)) return Syntax(playerid, "/set money <playerid> <value>");
		if(toplayerid == INVALID_PLAYER_ID) return Syntax(playerid, "/set money <playerid> <value>");
		SetMoney(toplayerid, value);
		return 1;
	}
	if (!strcmp(params, "level", true, 5))
	{
		if(sscanf(params[5], "ui", toplayerid, value)) return Syntax(playerid, "/set level <playerid> <value>");
		if(toplayerid == INVALID_PLAYER_ID) return Syntax(playerid, "/set level <playerid> <value>");
		UpdateVar(playerid, "Level", value);
		return 1;
	}
	return 1;
}
with SWITCH?
I tried something like switch(params) { case money:{} } but i'm getting error.
Reply
#2

well in php you can use switch for strings, but pwn doesn't allow it.
and i would suggest you to use pawn.cmd fastest command engine.
PHP код:
CMD:set(pid,p[]){
    if(
sscanf(p,"us[30]d",id,p,val)){
        
scm(pid,-1,"/set <playerid> <option> <value>");
        return 
scm(pid,-1,"options: money, level";
    }
    if(!
IsPlayerConnected(id))return scm(pid,-1,"player isn't connected.");
    if(!
strcmp(p,"money")){
        
SetMoney(idval);
    }else if(!
strcmp(p,"level")){
        if(
lvl 0)return scm(pid,-1,"Level can't be lower then 0!");
        
UpdateVar(id"Level"val);
    }
    return 
1;

Reply
#3

Quote:
Originally Posted by CodeStyle175
Посмотреть сообщение
well in php you can switch between strings, but pwn doesn't allow it.
You have obviously no idea what you are talking about.

@OP what about showing us the error you get? Are we to guess the errors you received?
Im not sure if params is to be used in switch but here is an example of how to use switch:

PHP код:
switch(var[playerid])
{
    case 
0// when var[playerid] is 0 
    
case 1// when var[playerid] is 1 

Reply
#4

i mean string you stupid ass don't argue with me
pawn only allows numbers in switch
PHP код:
switch(p){
        case 
"level":{}
        case 
"money":{}
    } 
you can't do that, can you?
Reply
#5

Quote:
Originally Posted by CodeStyle175
Посмотреть сообщение
i mean string you stupid ass don't argue with me
I advise you to watch your language. No place for internet warriors like you here.
Reply
#6

jaspers why are you arguing with me you already failed why are you trying again?
Reply
#7

Quote:
Originally Posted by CodeStyle175
Посмотреть сообщение
jaspers why are you arguing with me you already failed why are you trying again?
You failed to see that you've failed. Now stop shit posting irrelevant bullshit and get back ontopic smartass.
Reply
#8

I will recommend you to rewrite the command not using switch because it don't need to.
Код:
YCMD:set(playerid, params[], help)
{
	if(playerVariables[playerid][pAdmin] <= 4) return AdminOnly(playerid, 5);
	new option[32], id, value;
	if(sscanf(params, "sud", option, id, value))
	{
		Syntax(playerid, "/set <option> <playerid> <value>");
		SCM(playerid, COLOR_SERVER, "Options: {FFFFFF}money, level");
		return 1;
	}
	new bool:foundOption = false;
	if(!strcmp(option, "money", true, 5))
	{
		if(id == INVALID_PLAYER_ID) return Syntax(playerid, "/set money <playerid> <value>");
		SetMoney(id, value);
		foundOption = true;
	}
	else if(!strcmp(option, "level", true))
	{
		if(id == INVALID_PLAYER_ID) return Syntax(playerid, "/set level <playerid> <value>");
		UpdateVar(playerid, "Level", value);
		foundOption = true;
	}
	if(!foundOption)
		SCM(playerid, COLOR_SERVER, "Options: {FFFFFF}money, level");
	return 1;
}
Reply
#9

By using y_stringhash, you can do it.

PHP код:
switch(YHash(option))
{
    case 
_H<money>:
    {
    }
    case 
_H<level>:
    {
    }

Reply
#10

Quote:
Originally Posted by CodeStyle175
Посмотреть сообщение
well in php you can use switch for strings, but pwn doesn't allow it.
and i would suggest you to use pawn.cmd fastest command engine.
PHP код:
CMD:set(pid,p[]){
    if(
sscanf(p,"us[30]d",id,p,val)){
        
scm(pid,-1,"/set <playerid> <option> <value>");
        return 
scm(pid,-1,"options: money, level";
    }
    if(!
IsPlayerConnected(id))return scm(pid,-1,"player isn't connected.");
    if(!
strcmp(p,"money")){
        
SetMoney(idval);
    }else if(!
strcmp(p,"level")){
        if(
lvl 0)return scm(pid,-1,"Level can't be lower then 0!");
        
UpdateVar(id"Level"val);
    }
    return 
1;

Some friends use ysi library instead of pawn.cmd, they recommanded me to use it.

Quote:
Originally Posted by Dutheil
Посмотреть сообщение
By using y_stringhash, you can do it.

PHP код:
switch(YHash(option))
{
    case 
_H<money>:
    {
    }
    case 
_H<level>:
    {
    }

That's what i wanted, thanks.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)