SA-MP Forums Archive
CMD:defend - 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: CMD:defend (/showthread.php?tid=568709)



CMD:defend - Connor Smith - 24.03.2015

Код:
CMD:defend(playerid, params[])
{
	static
	    userid,
		price;
	    
	if (PlayerData[playerid][pJob] != JOB_LAWYER)
	    return SendErrorMessage(playerid, "You cant use that command.");
	    
    if (!IsPlayerNearPlayer(playerid, userid, 6.0))
        return SendErrorMessage(playerid, "Player is not below you.");
        
	if (userid == INVALID_PLAYER_ID)
	    return SendErrorMessage(playerid, "Player is offline.");
	    
    if (userid == playerid)
        return SendErrorMessage(playerid, "You cant defend yourself.");

	new string[128];
	if(PlayerData[playerid][pLawyerTime] >= 1)
	{
		format(string, sizeof(string), "You must wait %d seconds!", PlayerData[playerid][pLawyerTime]);
		SendClientMessage(playerid, COLOR_GREY,string);
		return 1;
	}

	if (sscanf(string, "ud", userid, price))
		return SendSyntaxMessage(playerid, "/defend [Name_Lastname/ID] [price]");
		
    if (PlayerData[userid][pWanted] == 0)
		return SendErrorMessage(playerid, "Player dont have warrants!");
		
 	new playermoney = PlayerData[playerid][pMoney];
	if(price > 0 && playermoney >= price)
	{
		format(string, sizeof(string), "* You offered to %s to defend him for $%d.", ReturnName(userid, 0), price);
		SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
		format(string, sizeof(string), "* Lawyer %s offered you to defend u for $%d, (usage /accept defend) to accept.", ReturnName(playerid, 0), price);
		SendClientMessage(userid, COLOR_LIGHTBLUE, string);
		PlayerData[playerid][pLawyerTime] = 60;
		DefendOffer[userid] = playerid;
		DefendPrice[userid] = price;
	}
	return 1;
}
Whats wrong with that command?When i use /defend (example)Connor_Smith 500, its telling me /defend [Name_Lastname/ID] [price]


Re: CMD:defend - fuckingcruse - 24.03.2015

What does /defend gives and how much?


Re: CMD:defend - maximthepain - 24.03.2015

Try this with only ID:
pawn Код:
CMD:defend(playerid, params[])
{
    new userid, price, string[128];
    new playermoney = PlayerData[playerid][pMoney];
   
    if(sscanf(params, "ud", userid, price)) return SendSyntaxMessage(playerid, "/defend [Name/ID] [price]");
    if(PlayerData[playerid][pJob] != JOB_LAWYER) return SendErrorMessage(playerid, "You cant use that command.");
    if(!IsPlayerConnected(userid)) return SendErrorMessage(playerid, "Player is offline.");
    if(!IsPlayerNearPlayer(playerid, userid, 6.0)) return SendErrorMessage(playerid, "Player is not below you.");
    if(userid == playerid) return SendErrorMessage(playerid, "You cant defend yourself.");
    if(PlayerData[userid][pWanted] == 0) return SendErrorMessage(playerid, "Player dont have warrants!");
   
    if(PlayerData[playerid][pLawyerTime] >= 1)
    {
        format(string, sizeof(string), "You must wait %d seconds!", PlayerData[playerid][pLawyerTime]);
        SendClientMessage(playerid, COLOR_GREY,string);
        return 1;
    }
    if(price > 0 && playermoney >= price)
    {
        format(string, sizeof(string), "* You offered to %s to defend him for $%d.", ReturnName(userid, 0), price);
        SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
        format(string, sizeof(string), "* Lawyer %s offered you to defend u for $%d, (usage /accept defend) to accept.", ReturnName(playerid, 0), price);
        SendClientMessage(userid, COLOR_LIGHTBLUE, string);
        PlayerData[playerid][pLawyerTime] = 60;
        DefendOffer[userid] = playerid;
        DefendPrice[userid] = price;
    }
    return 1;
}



Re: CMD:defend - fuckingcruse - 24.03.2015

You changed " ud " into " dd " ..
And he didn't gave the player anything.. so ofc the cmd goes waste,

Let him say what he wants to give the player.. and how much..

Good day


Re: CMD:defend - maximthepain - 24.03.2015

Quote:
Originally Posted by fuckingcruse
Посмотреть сообщение
You changed " ud " into " dd " ..
And he didn't gave the player anything.. so ofc the cmd goes waste,

Let him say what he wants to give the player.. and how much..

Good day
The function works. Its just that the sscanf doesn't really check what he writes in it.
Read the thread. I know what i changed because thats how im using codes with sscanf for userids, and thats how it works for me, so that would be my ideal solution for this.
You may want to look again at the fixed code. I have made it more... readable.


Re: CMD:defend - fuckingcruse - 24.03.2015

Ok, say me what defend gives the player? Armour or hp? And how much it gives?


Re: CMD:defend - Konstantinos - 24.03.2015

He used "u" specifier and that's correct if he wants to use the name too instead of only the player's ID.

The problem is that you used sscanf on "string" which is actually empty instead of "params":
PHP код:
// change:
if (sscanf(string"ud"useridprice))
        return 
SendSyntaxMessage(playerid"/defend [Name_Lastname/ID] [price]");
// to:
if (sscanf(params"ud"useridprice))
        return 
SendSyntaxMessage(playerid"/defend [Name_Lastname/ID] [price]"); 



Re: CMD:defend - maximthepain - 24.03.2015

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
He used "u" specifier and that's correct if he wants to use the name too instead of only the player's ID.

The problem is that you used sscanf on "string" which is actually empty instead of "params":
PHP код:
// change:
if (sscanf(string"ud"useridprice))
        return 
SendSyntaxMessage(playerid"/defend [Name_Lastname/ID] [price]");
// to:
if (sscanf(params"ud"useridprice))
        return 
SendSyntaxMessage(playerid"/defend [Name_Lastname/ID] [price]"); 
Ohhh! I was sure it is params there haha Good notice!


Re: CMD:defend - Connor Smith - 24.03.2015

Thanks guys very much! I dont know how I did this.. And how I didnt noticed it