SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 01/08/2010, 04:40 PM   #11
Toni
High-roller
 
Toni's Avatar
 
Join Date: Aug 2009
Location: United States
Posts: 1,493
Reputation: 156
Default Re: Making a simple PM system with ZCMD & sscanf

Quote:
Originally Posted by M3ntaL View Post
I got a problem

Did everything right, i gues, put the include
Code:
#include <zcmd>
and the code
Code:
CMD:es(playerid, params[])
{
    new str[256], str2[256], id, Name1[MAX_PLAYER_NAME], Name2[MAX_PLAYER_NAME];
    if(sscanf(params, "us", id, str2))
    {
    	SendClientMessage(playerid, 0xFF0000FF, "Vihje: /es <id> <sõnum>");
  		return 1;
    }
    if(!IsPlayerConnected(id)) return SendClientMessage(playerid, 0xFF0000FF, "VIGA: Player not connected");
    if(playerid != id) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: You cannot pm yourself!");
    {
		GetPlayerName(playerid, Name1, sizeof(Name1));
 		GetPlayerName(id, Name2, sizeof(Name2));
        format(str, sizeof(str), "ES kasutajalt %s(ID %d): %s", Name2, id, str2);
        SendClientMessage(playerid, 0xFF0000FF, str);
        format(str, sizeof(str), "ES kasutajalt %s(ID %d): %s", Name1, playerid, str2);
        SendClientMessage(id, 0xFF0000FF, str);
    }
    return 1;
}

but i keep getting this error while i try to compile it ( just started scripting, i think i'm with good brain... just dont figure this out )

Code:
C:\Documents and Settings\Owner\Desktop\BBRP GM\gamemodes\bbrp.pwn(51) : error 017: undefined symbol "sscanf"
Pawn compiler 3.2.3664	 	 	Copyright (c) 1997-2006, ITB CompuPhase


1 Error.

Btw. It's translated to Estonian, as you can see, dont mind that ^^.
You need the plugin sscanf - or this code;
Code:
stock sscanf(string[], format[], {Float,_}:...)
{
	#if defined isnull
	if (isnull(string))
	#else
	if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
	#endif
	{
		return format[0];
	}
	#pragma tabsize 4
	new
		formatPos = 0,
		stringPos = 0,
		paramPos = 2,
		paramCount = numargs(),
		delim = ' ';
	while (string[stringPos] && string[stringPos] <= ' ')
	{
		stringPos++;
	}
	while (paramPos < paramCount && string[stringPos])
	{
		switch (format[formatPos++])
		{
			case '\0':
			{
				return 0;
			}
			case 'i', 'd':
			{
				new
					neg = 1,
					num = 0,
					ch = string[stringPos];
				if (ch == '-')
				{
					neg = -1;
					ch = string[++stringPos];
				}
				do
				{
					stringPos++;
					if ('0' <= ch <= '9')
					{
						num = (num * 10) + (ch - '0');
					}
					else
					{
						return -1;
					}
				}
				while ((ch = string[stringPos]) > ' ' && ch != delim);
				setarg(paramPos, 0, num * neg);
			}
			case 'h', 'x':
			{
				new
					num = 0,
					ch = string[stringPos];
				do
				{
					stringPos++;
					switch (ch)
					{
						case 'x', 'X':
						{
							num = 0;
							continue;
						}
						case '0' .. '9':
						{
							num = (num << 4) | (ch - '0');
						}
						case 'a' .. 'f':
						{
							num = (num << 4) | (ch - ('a' - 10));
						}
						case 'A' .. 'F':
						{
							num = (num << 4) | (ch - ('A' - 10));
						}
						default:
						{
							return -1;
						}
					}
				}
				while ((ch = string[stringPos]) > ' ' && ch != delim);
				setarg(paramPos, 0, num);
			}
			case 'c':
			{
				setarg(paramPos, 0, string[stringPos++]);
			}
			case 'f':
			{
				setarg(paramPos, 0, _:floatstr(string[stringPos]));
			}
			case 'p':
			{
				delim = format[formatPos++];
				continue;
			}
			case '\'':
			{
				new
					end = formatPos - 1,
					ch;
				while ((ch = format[++end]) && ch != '\'') {}
				if (!ch)
				{
					return -1;
				}
				format[end] = '\0';
				if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
				{
					if (format[end + 1])
					{
						return -1;
					}
					return 0;
				}
				format[end] = '\'';
				stringPos = ch + (end - formatPos);
				formatPos = end + 1;
			}
			case 'u':
			{
				new
					end = stringPos - 1,
					id = 0,
					bool:num = true,
					ch;
				while ((ch = string[++end]) && ch != delim)
				{
					if (num)
					{
						if ('0' <= ch <= '9')
						{
							id = (id * 10) + (ch - '0');
						}
						else
						{
							num = false;
						}
					}
				}
				if (num && IsPlayerConnected(id))
				{
					setarg(paramPos, 0, id);
				}
				else
				{
					#if !defined foreach
						#define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
						#define __SSCANF_FOREACH__
					#endif
					string[end] = '\0';
					num = false;
					new
						name[MAX_PLAYER_NAME];
					id = end - stringPos;
					foreach (Player, playerid)
					{
						GetPlayerName(playerid, name, sizeof (name));
						if (!strcmp(name, string[stringPos], true, id))
						{
							setarg(paramPos, 0, playerid);
							num = true;
							break;
						}
					}
					if (!num)
					{
						setarg(paramPos, 0, INVALID_PLAYER_ID);
					}
					string[end] = ch;
					#if defined __SSCANF_FOREACH__
						#undef foreach
						#undef __SSCANF_FOREACH__
					#endif
				}
				stringPos = end;
			}
			case 's', 'z':
			{
				new
					i = 0,
					ch;
				if (format[formatPos])
				{
					while ((ch = string[stringPos++]) && ch != delim)
					{
						setarg(paramPos, i++, ch);
					}
					if (!i)
					{
						return -1;
					}
				}
				else
				{
					while ((ch = string[stringPos++]))
					{
						setarg(paramPos, i++, ch);
					}
				}
				stringPos--;
				setarg(paramPos, i, '\0');
			}
			default:
			{
				continue;
			}
		}
		while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
		{
			stringPos++;
		}
		while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
		{
			stringPos++;
		}
		paramPos++;
	}
	do
	{
		if ((delim = format[formatPos++]) > ' ')
		{
			if (delim == '\'')
			{
				while ((delim = format[formatPos++]) && delim != '\'') {}
			}
			else if (delim != 'z')
			{
				return delim;
			}
		}
	}
	while (delim > ' ');
	return 0;
}

But I think the plugin is much more effective.

@ Sergei, yeah, as there are lots of ways to do it.
__________________
Toni is offline   Reply With Quote
Old 01/08/2010, 04:47 PM   #12
M3ntaL
Little Clucker
 
Join Date: Jul 2010
Posts: 44
Reputation: 0
Default Re: Making a simple PM system with ZCMD & sscanf

k, tnx, got it work, nice tutorial btw
M3ntaL is offline   Reply With Quote
Old 01/08/2010, 05:01 PM   #13
Sergei
High-roller
 
Sergei's Avatar
 
Join Date: Mar 2008
Location: Slovenia
Posts: 2,906
Reputation: 230
Default Re: Making a simple PM system with ZCMD & sscanf

@The Toni, there should be only one way. I don't know why people who write tutorials put some effort, so other people can learn efficent coding.

Code:
    if(playerid != id) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: You cannot pm yourself!");
    {
Two mistakes in two lines of code.
__________________
Watch out, scouts everywhere!
Sergei is offline   Reply With Quote
Old 01/08/2010, 05:30 PM   #14
Toni
High-roller
 
Toni's Avatar
 
Join Date: Aug 2009
Location: United States
Posts: 1,493
Reputation: 156
Default Re: Making a simple PM system with ZCMD & sscanf

Quote:
Originally Posted by Sergei View Post
@The Toni, there should be only one way. I don't know why people who write tutorials put some effort, so other people can learn efficent coding.

Code:
    if(playerid != id) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: You cannot pm yourself!");
    {
Two mistakes in two lines of code.
I do put effort, but you have to admit, not everyone knows everything. Now I know that you can use a string array for more then one format!
__________________
Toni is offline   Reply With Quote
Old 01/08/2010, 08:02 PM   #15
Sergei
High-roller
 
Sergei's Avatar
 
Join Date: Mar 2008
Location: Slovenia
Posts: 2,906
Reputation: 230
Default Re: Making a simple PM system with ZCMD & sscanf

You could also do without openning pname array!

Code:
new str[128], id;
GetPlayerName(id, str, 24);
format(str, sizeof(str), "PM To %s(ID %d): %s", str, id, params);
__________________
Watch out, scouts everywhere!
Sergei is offline   Reply With Quote
Old 01/08/2010, 08:44 PM   #16
Toni
High-roller
 
Toni's Avatar
 
Join Date: Aug 2009
Location: United States
Posts: 1,493
Reputation: 156
Default Re: Making a simple PM system with ZCMD & sscanf

Quote:
Originally Posted by Sergei View Post
You could also do without openning pname array!

Code:
new str[128], id;
GetPlayerName(id, str, 24);
format(str, sizeof(str), "PM To %s(ID %d): %s", str, id, params);
Thanks, got that now
__________________
Toni is offline   Reply With Quote
Old 18/08/2010, 10:32 AM   #17
Blades
Big Clucker
 
Join Date: Aug 2007
Posts: 76
Reputation: 0
Default Re: Making a simple PM system with ZCMD & sscanf

Thanks for the tutorial, but is there a way to make your PM message in two lines, if your message is too big?

PM from Player: first line here i am talking and how are yo...
...u continue here.
Blades is offline   Reply With Quote
Old 18/08/2010, 11:06 AM   #18
Toni
High-roller
 
Toni's Avatar
 
Join Date: Aug 2009
Location: United States
Posts: 1,493
Reputation: 156
Default Re: Making a simple PM system with ZCMD & sscanf

Quote:
Originally Posted by Blades View Post
Thanks for the tutorial, but is there a way to make your PM message in two lines, if your message is too big?

PM from Player: first line here i am talking and how are yo...
...u continue here.
Increase the string size, that should work.
__________________
Toni is offline   Reply With Quote
Old 19/08/2010, 08:41 AM   #19
Blades
Big Clucker
 
Join Date: Aug 2007
Posts: 76
Reputation: 0
Default Re: Making a simple PM system with ZCMD & sscanf

Quote:
Originally Posted by The Toni View Post
Increase the string size, that should work.
What I mean is, I want it to be scripted somehow so when it reaches a certain amount of the text, it will make a new line and continue it.
Blades is offline   Reply With Quote
Old 08/09/2010, 09:56 AM   #20
Blades
Big Clucker
 
Join Date: Aug 2007
Posts: 76
Reputation: 0
Default Re: Making a simple PM system with ZCMD & sscanf

Sorry for bump, but I really need this. Can anyone help me with what I mentioned above?
Blades is offline   Reply With Quote
Reply

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
ZCMD/SSCANF PROBLEM Zeromanster Help Archive 2 27/02/2010 11:26 PM
Simple ZCMD Tutorial Script (.Aztec); Filterscripts 5 13/01/2010 12:58 AM
ZCMD + SSCANF PROBLEM Zeromanster Help Archive 6 22/11/2009 01:13 AM
sscanf and zcmd question about commands with multi parameters Dujma Help Archive 5 21/11/2009 01:24 AM
[Help]Zcmd & sscanf Dirty_bum Help Archive 3 28/10/2009 12:10 PM


All times are GMT. The time now is 09:29 PM.


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