Custom Stocks..
#1

Currently I have a stock (SuccessMessage):

pawn Код:
stock SuccessMessage(Player, Message[])
{
    new
        string[128];

    format(string, sizeof(string), "{60BD09}SUCCESS: {FFFFFF}%s", Message);
    return SendClientMessage(Player, -1, string);
}
I want to make it so the stock supports strings, such as:

Код:
SuccessMessage(playerid, "Sky has %d bananas.", Bananas[playerid]);
Is this possible?
Reply
#2

Yes.. You can use format to format the string before sending a SuccessMessage then sending the formatted text.
pawn Код:
format(string, sizeof(string), "Sky has %d bananas.", Bananas[playerid]);
SuccesMessage(playerid, string);
Reply
#3

if You want only for integers:
pawn Код:
stock SendClientMessageEx(playerid,Message[],...)
{
    new str[10],string[128],pos,num=2;
    strcat(string,Message);
    while((pos = strfind(string,"%d")) != -1)
    {
        strdel(string,pos,(pos + 2));
        valstr(str,getarg(num));
        strins(string,str,pos);
        num++;
    }
    SendClientMessage(playerid,-1,string);
    return 1;
}
Example:
pawn Код:
SendClientMessageEx(playerid,"{60BD09}SUCCESS: {FFFFFF}Sky has %d %d %d %d %d %d %d %d bananas.",1,2,3,4,5,6,7,8);
Reply
#4

Quote:
Originally Posted by ******
Посмотреть сообщение
That is the basis of the required code, but only a very basic basis. There are three ways of doing this:

The first is to re-implement the code of format in your function. An example of this can be seen in the old YSI in YSI_format.own.

The second is to pass all the variable parameters from your function through to another variable parameters function. This requires playing about with PAWN assembly directly as the compiler doesn't support it. An example of this can be found in the new YSI in y_debug.inc.

The last is to wrap your function call up in macro and call format in there. This is by far the easiest method and examples of this can be found in many "SendClientMessageEx" functions in the Useful Functions topic.

Any way it is very possible to do and there are plenty of examples for you to look at. Note that this isn't a plug for YSI, it just happens to be a system which I know has the required information off the top of my head.
Holy mother of god. This sounds difficult, I suppose i'll do some scavenging and look through the Useful Functions topic as you stated it's by far the easiest method.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)