SA-MP Forums Archive
Need help with creating function - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Need help with creating function (/showthread.php?tid=250430)



Need help with creating function (SOLVED) - Johnson_boy - 23.04.2011

Hi!
I've been thinking that its too complicated when you need to send only one formated message.
You have to create new string, then format it, and then send it. I though it would be better if you could do it in just one function.

I tried to make function to send formatted message (playerid, color, const message[], {Float,_}:...).
That allows you to give any amount of parameters at the end, but I don't know how to use the last parameters in function.
Is it possible? and if so, how?


PROBLEM SOLVED


Re: Need help with creating function - Ash. - 23.04.2011

It is possible, i believe you have to use "getarg" - i will have a go now, it's something i've always wanted to play with, just never had reason

Код:
Ugh, This forum requires that you wait 120 seconds between posts. Please try again in 27 seconds.
I must type to fast, i'm sorry.

This forum requires that you wait 120 seconds between posts. Please try again in 1 seconds.
THAT WAS JUST MEAN



Re: Need help with creating function - Alby Fire - 23.04.2011

pawn Код:
new
    str[150];
#define SendFormattedMessage(%1,%2,%3,%4); \
format(str, sizeof str, %3, %4); \
SendClientMessage(%1, %2, str);
Example
pawn Код:
new
    a = 3;
SendFormattedMessage(playerid, 0xffffffff, "Hello this is a formatted message look -> %d", a);
If you don't know how to use a function, I don't think you can create it correctly.


Re: Need help with creating function - Ash. - 23.04.2011

Quote:
Originally Posted by Alby Fire
Посмотреть сообщение
pawn Код:
new
    str[150];
#define SendFormattedMessage(%1,%2,%3,%4); \
format(str, sizeof str, %3, %4); \
SendClientMessage(%1, %2, str);
Example
pawn Код:
new
    a = 3;
SendFormattedMessage(playerid, 0xffffffff, "Hello this is a formatted message look -> %d", a);
If you don't know how to use a function, I don't think you can create it correctly.
Can this handle more than one argument then?

(eg SendFormattedMessage(playerid, hex, "Test %s - you have %i", name, score);


Re: Need help with creating function - Johnson_boy - 23.04.2011

Ok thanks for replys.
Better to use macro than function.

Код:
new
    str[150];
#define SendFormattedMessage(%1,%2,%3,%4); \
format(str, sizeof str, %3, %4); \
SendClientMessage(%1, %2, str);
works


Re: Need help with creating function - Ash. - 23.04.2011

Quote:
Originally Posted by Johnson_boy
Посмотреть сообщение
Ok thanks for replys.
Better to use macro than function.
Yes, it probably is - it looks more reliable than anything i've come up with (although it is working... )


Re: Need help with creating function - [ADC]Aldi96 - 23.04.2011

Try this script ......
i test this and i tell you it work or no!!


Re: Need help with creating function - Nanory - 24.04.2011

It is better to use str[128] than str[150], because a line in the chatbox has only 128 characters...