SA-MP Forums Archive
refill - problem! - 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)
+--- Thread: refill - problem! (/showthread.php?tid=382403)



refill - problem! - Akcent_Voltaj - 03.10.2012

how can i make this "/refill [name] [price] [reason]"

PHP код:
    if(strcmp(cmd"/refill"true) == 0)
                    {
                        if(
IsPlayerConnected(playerid))
                        {
                              if (
PlayerInfo[playerid][pMember] == 15)
                            {
                                
SendClientMessage(playeridCOLOR_GREY"   You are not a Car Mechanic!");
                                return 
1;
                            }
                            
tmp strtok(cmdtextidx);
                            if(!
strlen(tmp))
                            {
                                
SendClientMessage(playeridCOLOR_GRAD2"USAGE: /refill [playerid/PartOfName] [price]");
                                return 
1;
                            }
                            new 
playa;
                            new 
money;
                            
playa ReturnUser(tmp);
                            
tmp strtok(cmdtextidx);
                            
money strval(tmp);
                            if(
money || money 99999) { SendClientMessage(playeridCOLOR_GREY"   Price not lower then 1, or above 99999!"); return 1; }
                            if(
IsPlayerConnected(playa))
                            {
                                if(
playa != INVALID_PLAYER_ID)
                                {
                                    if(
ProxDetectorS(8.0playeridplaya)&& IsPlayerInAnyVehicle(playa))
                                    {
                                        if(
playa == playerid) { SendClientMessage(playeridCOLOR_GREY"   Can't do that!"); return 1; }
                                        
GetPlayerName(playagiveplayersizeof(giveplayer));
                                        
GetPlayerName(playeridsendernamesizeof(sendername));
                                        
format(stringsizeof(string), "* Iai oferit lui %s ca sa-i faci plinu cu %dLei .",giveplayer,money);
                                        
SendClientMessage(playeridCOLOR_PURPLEstring);
                                        
format(stringsizeof(string), "* Mecanicul %s vrea sa-ti faca plinu cu %dLei, (scrie /accepta refill) pentru a accepta.",sendername,money);
                                        
SendClientMessage(playaCOLOR_LIGHTBLUEstring);
                                        
RefillOffer[playa] = playerid;
                                        
RefillPrice[playa] = money;
                                    }
                                    else
                                    {
                                        
SendClientMessage(playeridCOLOR_GREY"   That player is not near you / not in a car.");
                                    }
                                }
                            }
                            else
                            {
                                
SendClientMessage(playeridCOLOR_GREY"   That player is offline.");
                            }
                        }
                        return 
1;
                    } 



Re: refill - problem! - Roel - 03.10.2012

It's possible with the strtok function, but it will get a chaos and I think it also will be bugged.
Why don't you use sscanf, then this is very easy.


Re: refill - problem! - KingHual - 03.10.2012

1st - Use zcmd, it's a faster command processer. 2nd - Use sscanf, sinc strtok is slow.


Re: refill - problem! - Roel - 03.10.2012

Quote:
Originally Posted by king_hual
Посмотреть сообщение
1st - Use zcmd, it's a faster command processer. 2nd - Use sscanf, sinc strtok is slow.
Are you sure, because I don't think zcmd is faster, it's only a little easier to write commands.
I think you should use dcmd, because this also allows you to easy write cmds.
And because it is a define thingy, it is not faster and not slower then the normal cmd definition.
Not sure if zcmd is slower but it's a include with maybe 100 lines, so I think it is slower.
I'm sure it isn't faster.

And the thing i like with dcmd is that it allows to to group the cmds in onplayercommand.
in zcmd you have to put in every single cmd that he isn't allowed to use it when he is in a vehicle.
Using dcmd you can just put the dcmd in the if(onfoot) thing.


Re: refill - problem! - Akcent_Voltaj - 03.10.2012

i would like information ,how is it slow?i only know strtok..what inc.do i need for zcmd?or..


Re: refill - problem! - KingHual - 03.10.2012

Zcmd - https://sampforum.blast.hk/showthread.php?tid=91354
Sscanf - https://sampforum.blast.hk/showthread.php?tid=120356 (It's a plugin)

And zcmd is not slower than the default processor. Also, speed has nothing to do with number of lines.


Re: refill - problem! - Roel - 03.10.2012

For dcmd you only need to put this line below your includes at the top of your script:
Код:
#define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd__%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd__%1(playerid, (%3)[(%2) + 2]))))) return 1
Then you can make a cmd like this:
Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
	dcmd(heal, 4, cmdtext);
	return 0;
}
 
dcmd_heal(playerid, params[])
{
        new id;
	if (strlen(params))
	{
		id = strval(params);
		if (IsPlayerConnected(id))
		{
			SetPlayerHealth(id, 100.0);
			SendClientMessage(id, 0x00FF00AA, "You have been healed");
			SendClientMessage(playerid, 0x00FF00AA, "Player healed");
		}
		else
		{
			SendClientMessage(playerid, 0xFF0000AA, "Player not found");
		}
	}
	else
	{
		SendClientMessage(playerid, 0xFF0000AA, "Usage: \"/heal <playerid>\"");
	}
	return 1;
}
And I looked on wiki, it seems the zcmd is faster, I don't know how but it seems to be: here you can find zcmd: clicky


Re: refill - problem! - Roel - 03.10.2012

Quote:
Originally Posted by king_hual
Посмотреть сообщение
Zcmd - https://sampforum.blast.hk/showthread.php?tid=91354
Sscanf - https://sampforum.blast.hk/showthread.php?tid=120356 (It's a plugin)

And zcmd is not slower than the default processor. Also, speed has nothing to do with number of lines.
Yea I was wrong lol, this is faster indeed, but still I like dcmd more because it's easy to group them.


Re: refill - problem! - Akcent_Voltaj - 03.10.2012

COMMAND:mycommand(playerid, params[])
{
//my refill for top
} is it good for zcmd??


Re: refill - problem! - KingHual - 03.10.2012

Sure, but remove all the useless strtok-related variables, and use sscanf