Question about 'stock'
#1

I'd like to make my own stock like this, how is this possible?
pawn Код:
stock SendMessage(playerid, case,string[]) // something like 'case' or something ?
{
     if(case = yellow) SendClientMessage(playerid, COLOR_YELLOW, string);
     if(case = red) SendClientMessage(playerid, COLOR_RED, string);
     if(case = blue) SendClientMessage(playerid, COLOR_BLUE, string);
     else return 0;
}
Please dont ask me why i want it like this, because this is just a quick example of how i want to make my other stock.

PS. Is it possible to make it formated, like this: SendMessage(playerid, yellow, "%s", Name(playerid)); ?
Reply
#2

here goes.
pawn Код:
stock SendMessage(playerid,color[],string[])
{
     if(strcmp(color,#yellow)) return SendClientMessage(playerid, COLOR_YELLOW, string);
     else if(strcmp(color,#red)) return SendClientMessage(playerid, COLOR_RED, string);
     else if(strcmp(color,#blue)) return SendClientMessage(playerid, COLOR_BLUE, string);
     return 0;
}

//usage
SendMessage(playerid,#yellow,#Fuck Yeah);
Reply
#3

Quote:
Originally Posted by leonardo1434
Посмотреть сообщение
here goes.
pawn Код:
stock SendMessage(playerid,color[],string[])
{
     if(strcmp(color,#yellow)) return SendClientMessage(playerid, COLOR_YELLOW, string);
     else if(strcmp(color,#red)) return SendClientMessage(playerid, COLOR_RED, string);
     else if(strcmp(color,#blue)) return SendClientMessage(playerid, COLOR_BLUE, string);
     return 0;
}

//usage
SendMessage(playerid,#yellow,#Fuck Yeah);
'#' is the only way? Okay, thank you for help!
Reply
#4

i just use "#" cause it's practical, it does the same as " ".
Reply
#5

[quote]
Quote:
Originally Posted by leonardo1434
Посмотреть сообщение
here goes.
pawn Код:
stock SendMessage(playerid,color[],string[])
{
     if(strcmp(color,#yellow)) return SendClientMessage(playerid, COLOR_YELLOW, string);
     else if(strcmp(color,#red)) return SendClientMessage(playerid, COLOR_RED, string);
     else if(strcmp(color,#blue)) return SendClientMessage(playerid, COLOR_BLUE, string);
     return 0;
}

//usage
SendMessage(playerid,#yellow,#Fuck Yeah);
Umm, this doesnt work. I made this:
pawn Код:
SendMessage(playerid, #yellow, "YELLOW MESSAGE");
SendMessage(playerid, #red, "RED MESSAGE");
SendMessage(playerid, #blue, "BLUE MESSAGE");
and i got:
pawn Код:
YELLOW MESSAGE
RED MESSAGE
YELLOW MESSAGE
The blue message was replaced with yellow message, why?
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)