Help Command Problem
#1

I need to make the command to detect the closest player when the params aren't used, I tried this but it doesn't work.

Код:
CMD:rob(playerid, params[])
	{
	    if(sscanf(params, "U", params[0])) return SendClientMessage(playerid, ERROR, "Usage: /rob [player/id]");
     	if(params[0] == INVALID_PLAYER_ID) params[0] = GetClosestPlayerToPlayer(playerid);
	    if(GetDistanceBetweenPlayers(playerid, params[0]) >= 9) return SendClientMessage(playerid, ERROR, "No player is close to you.");
	    else
	    {
		    if(IsPlayerSpawned(playerid))
		    {
				if(gTeam[playerid] == CIVILIAN)
				{
				    if(params[0] != playerid)
				    {
						if(!IsPlayerInAnyVehicle(playerid))
						{
						    if(!IsPlayerInAnyVehicle(params[0]))
						    {
						        if(IsPlayerConnected(params[0]))
					        	{
						                if(GetPlayerMoney(params[0] > 0))
						                {
						                    if(GetDistanceBetweenPlayers(playerid, params[0]) <= 8)
						                    {
											    if(RecentlyRobbed[params[0]] == 0)
											    {
												if(GetPlayerMoney(params[0]) >= 4999)
												{
												    new string[250], string2[250], string3[250], robbedcash;
												    robbedcash = random(GetPlayerMoney(params[0])/2);
												    format(string, sizeof(string), "You have robbed $%d from %s[ID:%d]", robbedcash, PlayerName(params[0]), params[0]);
												    SendClientMessage(playerid, ERROR, string);
												    format(string2, sizeof(string2), "%s[ID:%d] has robbed $%d from you!", PlayerName(playerid), playerid, robbedcash);
												    SendClientMessage(params[0], ERROR, string2);
												    format(string3, sizeof(string3), "[HQ] %s has robbed $%d from %s.", PlayerName(playerid), PlayerName(params[0]), robbedcash);
               									    SendRadioMessageToCops(string3);
													GivePlayerMoney(playerid, robbedcash);
													GivePlayerMoney(params[0], -robbedcash);
													RecentlyRobbed[params[0]] = 60;
													GivePlayerScore(playerid, 1);
													if(gTeam[params[0]] == CIVILIAN)
													{
														SetPlayerWantedLevel(playerid,GetPlayerWantedLevel(playerid)+ 2);
													}
													if(gTeam[params[0]] == COP || gTeam[params[0]] == SWAT || gTeam[params[0]] == FBI || gTeam[params[0]] == ARMY || gTeam[params[0]] == Medic)
													{
														SetPlayerWantedLevel(playerid,GetPlayerWantedLevel(playerid)+ 5);
													}
													SetPlayerRobbingSkill(playerid, GetPlayerRobbingSkill(playerid)+1);
												    return true;
												}
												else if(GetPlayerMoney(params[0]) < 4999)
												{
													new string[250];
													format(string, sizeof(string), "%s[ID:%d] doesn't have enough money.", PlayerName(params[0]), params[0]);
													return SendClientMessage(playerid, ERROR, string);
												}
												}
												else if(RecentlyRobbed[params[0]] > 0)
												{
													new string[250];
													format(string, sizeof(string), "%s[ID:%d] has been robbed recently. Try again later.", PlayerName(params[0]), params[0]);
													return SendClientMessage(playerid, ERROR, string);
												}
											else
											{
												new string[250];
											    format(string, sizeof(string), "%s[ID:%d] is too far away.", PlayerName(params[0]), params[0]);
												return SendClientMessage(playerid, ERROR, string);
											}
										}
										else if(GetPlayerMoney(params[0]) == 0)
										{
										    new string[250];
										    format(string, sizeof(string), "%s[ID:%d] does not have any money.", PlayerName(params[0]), params[0]);
											return SendClientMessage(playerid, ERROR, string);
										}
									}
								}
								else if(!IsPlayerConnected(params[0]))
								{
									new string[250];
									format(string, sizeof(string), "ID %d is not connected.", params[0]);
									return SendClientMessage(playerid, ERROR, string);
								}
							}
							else if(IsPlayerInAnyVehicle(params[0]))
							{
							    new string[250];
								format(string, sizeof(string), "%s[ID:%d] is in a vehicle. You cannot rob him.", PlayerName(params[0]), params[0]);
								return SendClientMessage(playerid, ERROR, string);
							}
						}
						else if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, ERROR, "You cannot rob anyone from inside a vehicle.");
					}
					else return SendClientMessage(playerid, ERROR, "You cannot rob yourself.");
				}
				else return SendClientMessage(playerid, ERROR, "Only CIVILIANS can use this command!");
		    }
	    }
	    return 1;
	}
Thanks,
NeTSk8.
Reply
#2

Use params and not params[0]
Reply
#3

For the whole command or just only the first part?
Reply
#4

Hola. Igual hablo espaсol, ї Cual es el problema exactamente ?.
Reply
#5

The command needs to detect the closest player if no params are given, I did that code but it bugs and gives me a high value ID. Do you have Skype so you can help me?
(En este foro se esta obligado a hablar en ingles.)
Thanks.
Reply
#6

Just to say, you need to trim down on those if statements... Do it in a better order, and in a more optimized way.

If you did just that, the code would be a lot easier to read.
Reply
#7

But its only lнnea 3, 4 and 5 that are not working well, how can I do it more optimized, should I not use sscanf?
Thanks for the help guys.
Reply
#8

Quote:
Originally Posted by NeTSk8
Посмотреть сообщение
But its only lнnea 3, 4 and 5 that are not working well, how can I do it more optimized, should I not use sscanf?
Thanks for the help guys.
Write it in a proper order.
Reply
#9

Sorry, but I still can't understand, could you give me an example? Thanks a lot.
Reply
#10

Quote:
Originally Posted by NeTSk8
Посмотреть сообщение
Sorry, but I still can't understand, could you give me an example? Thanks a lot.
Alright, so first off, instead of checking all of those checks without checking that the ID (Not playerid, but the targetid) given is even connected first...

As you go through the checks it should be a logical, and quick method to find the information you need.

You do check if the target is connected, but only after you've checked that he's in a vehicle.


I'm sure you can cut down on these checks by either pairing them up and using combinations to make the code easier to digest.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)