PDA

View Full Version : CMD:defend


Connor Smith
24/03/2015, 01:17 PM
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]

fuckingcruse
24/03/2015, 03:29 PM
What does /defend gives and how much?

maximthepain
24/03/2015, 03:37 PM
Try this with only ID:

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;
}

fuckingcruse
24/03/2015, 03:41 PM
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

maximthepain
24/03/2015, 03:42 PM
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.

fuckingcruse
24/03/2015, 03:50 PM
Ok, say me what defend gives the player? Armour or hp? And how much it gives?

Konstantinos
24/03/2015, 04:20 PM
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":

// change:
if (sscanf(string, "ud", userid, price))
return SendSyntaxMessage(playerid, "/defend [Name_Lastname/ID] [price]");

// to:
if (sscanf(params, "ud", userid, price))
return SendSyntaxMessage(playerid, "/defend [Name_Lastname/ID] [price]");

maximthepain
24/03/2015, 04:29 PM
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":

// change:
if (sscanf(string, "ud", userid, price))
return SendSyntaxMessage(playerid, "/defend [Name_Lastname/ID] [price]");

// to:
if (sscanf(params, "ud", userid, price))
return SendSyntaxMessage(playerid, "/defend [Name_Lastname/ID] [price]");


Ohhh! I was sure it is params there haha :) Good notice!

Connor Smith
24/03/2015, 08:41 PM
Thanks guys very much! I dont know how I did this..:D And how I didnt noticed it