SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Help Archive

 
 
Thread Tools Display Modes
Old 23/04/2011, 10:12 AM   #1
Johnson_boy
Huge Clucker
 
Join Date: Mar 2011
Location: Finland
Posts: 215
Reputation: 80
Default Need help with creating function (SOLVED)

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

Last edited by Johnson_boy; 23/04/2011 at 10:48 AM.
Johnson_boy is offline  
Old 23/04/2011, 10:16 AM   #2
Ash.
High-roller
 
Ash.'s Avatar
 
Join Date: Jan 2010
Location: England
Posts: 2,084
Reputation: 163
Default Re: Need help with creating function

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

Code:
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
__________________
TruckingWorld
Work, Play, Make Friends
Written from scratch, and originally released in 2011, play today!
Visit the forum | Play the game
Ash. is offline  
Old 23/04/2011, 10:18 AM   #3
Alby Fire
Big Clucker
 
Join Date: Dec 2010
Posts: 125
Reputation: 2
Default Re: Need help with creating function

pawn Code:
new
    str[150];
#define SendFormattedMessage(%1,%2,%3,%4); \
format(str, sizeof str, %3, %4); \
SendClientMessage(%1, %2, str);
Example
pawn Code:
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.
__________________

Thank blewert for this signature
Alby Fire is offline  
Old 23/04/2011, 10:25 AM   #4
Ash.
High-roller
 
Ash.'s Avatar
 
Join Date: Jan 2010
Location: England
Posts: 2,084
Reputation: 163
Default Re: Need help with creating function

Quote:
Originally Posted by Alby Fire View Post
pawn Code:
new
    str[150];
#define SendFormattedMessage(%1,%2,%3,%4); \
format(str, sizeof str, %3, %4); \
SendClientMessage(%1, %2, str);
Example
pawn Code:
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);
__________________
TruckingWorld
Work, Play, Make Friends
Written from scratch, and originally released in 2011, play today!
Visit the forum | Play the game
Ash. is offline  
Old 23/04/2011, 10:30 AM   #5
Johnson_boy
Huge Clucker
 
Join Date: Mar 2011
Location: Finland
Posts: 215
Reputation: 80
Default Re: Need help with creating function

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

Code:
new
    str[150];
#define SendFormattedMessage(%1,%2,%3,%4); \
format(str, sizeof str, %3, %4); \
SendClientMessage(%1, %2, str);
works
Johnson_boy is offline  
Old 23/04/2011, 10:31 AM   #6
Ash.
High-roller
 
Ash.'s Avatar
 
Join Date: Jan 2010
Location: England
Posts: 2,084
Reputation: 163
Default Re: Need help with creating function

Quote:
Originally Posted by Johnson_boy View Post
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... )
__________________
TruckingWorld
Work, Play, Make Friends
Written from scratch, and originally released in 2011, play today!
Visit the forum | Play the game
Ash. is offline  
Old 23/04/2011, 10:37 AM   #7
[ADC]Aldi96
Big Clucker
 
[ADC]Aldi96's Avatar
 
Join Date: Apr 2011
Location: GREECE
Posts: 72
Reputation: 0
Default Re: Need help with creating function

Try this script ......
i test this and i tell you it work or no!!
__________________
Register in ADC-Forum : Click Me
Contact with me in email : aldi@hotmail.gr


You need to Host your Site & Forum for free go there :
Click me to host your Website&forum&Blog Free Or Premium


[ADC]Aldi96 is offline  
Old 24/04/2011, 11:35 AM   #8
Nanory
Big Clucker
 
Nanory's Avatar
 
Join Date: Feb 2009
Posts: 118
Reputation: 12
Default Re: Need help with creating function

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

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Function just stops other function Blay09 Help Archive 2 01/01/2011 01:26 PM
Creating a function [ Need help ] Cameltoe Help Archive 3 23/08/2010 07:10 PM


All times are GMT. The time now is 10:16 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.