sscanf
#1

guys as all saying if i use dcmd or sscanf the server run faster,command work faster idk and i try to learn a bit from sa-mp wiki /heal command but i get problems with strings ... if i want playername i need something in script like that ''getplayername ... bla bla bla...''

but here is the code:

Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
		// MEDIC COMMANDS
		dcmd(heal,4,cmdtext);
		return 0;
}
dcmd_heal(playerid,params[])
{
    new
				id;
    if (sscanf(params, "u", id)) SendClientMessage(playerid, 0xFF0000AA, "Usage: \"/heal [ID]\""); ---------------> LINE 614
    else if (id == INVALID_PLAYER_ID) SendClientMessage(playerid, 0xFF0000AA, "Player not found");
    else
    {
    GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayername)); -------------------------------> LINE 618
	GetPlayerName(playerid, sendername, sizeof(healername));
		
		SetPlayerHealth(id, 100.0);
		format(string, sizeof(string),"You Have Been Healed By Medic %s[%d]", healername, playerid);
		SendClientMessage(id, 0x33CCFFAA,string); // Light Blue Color
		format(string, sizeof(string),"You Healed Player %s[%d],You Get $13", giveplayername, id);
		SendClientMessage(playerid, 0x00FF00AA, "Player healed");
		GivePlayerMoney(playerid,13);
	}
	return 1;
}
and here are errors :

Код:
C:\Documents and Settings\samp\Desktop\Server2\gamemodes\WeedsCNR.pwn(614) : error 017: undefined symbol "sscanf"
C:\Documents and Settings\samp\Desktop\Server2\gamemodes\WeedsCNR.pwn(618) : error 017: undefined symbol "giveplayerid"
C:\Documents and Settings\samp\Desktop\Server2\gamemodes\WeedsCNR.pwn(618) : error 017: undefined symbol "giveplayername"
C:\Documents and Settings\samp\Desktop\Server2\gamemodes\WeedsCNR.pwn(618) : error 029: invalid expression, assumed zero
C:\Documents and Settings\samp\Desktop\Server2\gamemodes\WeedsCNR.pwn(618) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


5 Errors.
can anyone help me cuz i am trying to make perfect server
Reply
#2

Use zcmd, it's much easier..

Your command in ZCMD:

pawn Код:
cmd(heal, playerid, params[])
{
new user;
if(!sscanf(params, "u", user))
{
SetPlayerHealth(user, 100);
//Message
}
else return SendClientMessage(playerid, white, "(USAGE): /Heal (Player ID)");
return 1;
}
Yeah, i didn't indent it.
Reply
#3

o.O so much commands ... sscanf , zcmd,strmpc or what ever it is ... dcmd wtf is the best to use ? lol
Reply
#4

Quote:
Originally Posted by Lajko1
o.O so much commands ... sscanf , zcmd,strmpc or what ever it is ... dcmd wtf is the best to use ? lol
zcmd + sscanf.
Reply
#5

Quote:
Originally Posted by Don Correlli
Quote:
Originally Posted by Lajko1
o.O so much commands ... sscanf , zcmd,strmpc or what ever it is ... dcmd wtf is the best to use ? lol
zcmd + sscanf.
but for sscanf i need to download something as ****** say , where to get that ?
Reply
#6

Use the BIG FAT search thing at up at the right corner.
Reply
#7

Quote:
Originally Posted by Lajko1
but for sscanf i need to download something as ****** say , where to get that ?
https://sampwiki.blast.hk/wiki/Sscanf
Reply
#8

Quote:
Originally Posted by Y_Leѕѕ
Quote:
Originally Posted by Lajko1
o.O so much commands ... sscanf , zcmd,strmpc or what ever it is ... dcmd wtf is the best to use ? lol
You need to understand the differences between all of these things as they're very different:

strcmp:

This is just a native function which returns the lexical difference between two strings. You don't need to know what that means, just that if two strings are the same it returns 0. This was originally use to check if the command a person typed was the same as a command you had defined.

dcmd:

This is a wrapper around strcmp. When you have commands with parameters you want to be able to check they typed a command without looking at the parameters. The original way of doing this was to split the string up into multiple strings, but this is very slow, so dcmd was developed to provide a simple way of only looking at part of a string and checking it's value. It also called code in a function so that you didn't have a single huge OnPlayerCommandText, just a list of commands and their code elsewhere.

zcmd:

This is the latest best system for processing commands. It doesn't use strcmp at all, instead uses CallLocalFunction to try call a defined function directly. If the function doesn't exist nothing happens, if it does it's executed. The advantage to this is that you don't have to look through every command (you don't need a list of them anywhere in fact, you just write the code). It takes advantage of the much faster internal lookups of the PAWN VM.

sscanf:

This is nothing to do with any of the three concepts above, it's just often used in the same place. sscanf looks at a string and extracts information from it. You COULD use this information to check parameters entered with a command, but you can also use it anywhere else.

strtok:

I should mention this here for completeness. Before sscanf was developed this was used to split a string up into "tokens" (individual words) and those tokens were used, generally as command parameters, but as with sscanf this wasn't it's only use. The problem with this is code bloat as you have to check a token exists, check it's valid, convert it, check it's still valid and then use it. Any data returned from sscanf is guaranteed to be valid as all the checks are performed internally. This is VERY useful for beginner scripters who may not be aware of every bug and possible exploit so don't check for them then wonder how people hacked their script.

ycmd:

Because I wrote it I want to mention it. ycmd was developed between dcmd and zcmd and although it uses the same call method as zcmd I never put two and two together to create a zcmd like system. The difference to ycmd is that it's integrated into YSI (although a stand alone version is theoretically possible) and has many more options than other command processors. Normal processors have a command, and that is the command, ycmd can dynamically rename commands, give different commands to different people doing the same thing, add and remove commands, add or remove prefixes to all commands from a certain script (including optional spacing) and includes command usage checks internally so you don't need to make the first line of every command "if (IsPlayerAdmin(playerid))". This is also highly optimised for large numbers of commands, but so is zcmd. The downside to all this is that, especially for low numbers of commands, it's slower than dcmd, but frankly I still think it's MUCH better for huge modes.
Ty for so big explanation (i hope i write right) like this i think i will use zcmd or what ever it is but i need to start again o.O i just learn how to make commands with strcmp , and now all from start o.O y less anyway should be nice to make tutorial about using commands and i bet it should be sticky cuz s great explains as this you cant find... tomorow i will read this all again cuz atm i am a bit sleepy ty guys for help now i need just to learn all this omfg
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)