IsPlayerInRangeOfPoint/Command problem
#1

(Sry for bad English )
Hi all,
i have a problem,
this is my cmd:

Код:
if(strcmp(cmd,"/kaufen",true)==0)
	{
		for(new i=0;i<MAX_HOUSES;i++)
		{
		  if(IsPlayerInRangeOfPoint(playerid, 3.0, HausInfo[i][eX], HausInfo[i][eY], HausInfo[i][eZ]))
		  {
		    if(GetPlayerMoney(playerid) < HausInfo[i][Preis])
				{
		    	new Name[MAX_PLAYER_NAME];
			    GetPlayerName(playerid, Name, MAX_PLAYER_NAME);
					GivePlayerMoney(playerid, - HausInfo[i][Preis]);
					strmid(HausInfo[i][Besitzer], Name, 0, strlen(Name), 24);
					HausInfo[i][Vergeben] = 1;
					SendClientMessage(playerid, FARBE_WEIЯ,"Du hast das Haus gekauft, um Befehle anzusehen schreibe /hauscmds !");
					return 1;
				}
				else
				{
				  SendClientMessage(playerid,FARBE_WEIЯ,"Du hast zu wenig Geld, du musst zuerst das Geld auf der Hand haben.");
				  return 1;
			 	}
		  }
		  else
		  {
        SendClientMessage(playerid, FARBE_WEIЯ,"Du befindest dich nicht an einem Haus das zum Verkauf steht!");
        return 1;
   		}
		}
		return 1;
	}
It does not matter whether I have enough money or not at the house bin, there is always the last SendClientMessage.
What is the problem?
Reply
#2

Ich weiЯ nicht, Ich kann nicht Deutsch sprechen
(Not very good xD)
Reply
#3

Simply the command checks for all houses within for() looping with returns, so it's wrong. Example: 1 house, it checks, and it's not found, it sends a message, when returns and don't check for 2 house... am i right? I suggest you to use continue; function in for() loops. In for() loops return stops looping, continue just ends variable looping.

BTW. If you want to send end message, send it before for() looping.

Код:
if(strcmp(cmd,"/kaufen",true)==0)
	{
		for(new i=0;i<MAX_HOUSES;i++)
		{
		  if(!IsPlayerInRangeOfPoint(playerid, 3.0, HausInfo[i][eX], HausInfo[i][eY], HausInfo[i][eZ])) continue;
		    if(GetPlayerMoney(playerid) < HausInfo[i][Preis])
				{
		    	new Name[MAX_PLAYER_NAME];
			    GetPlayerName(playerid, Name, MAX_PLAYER_NAME);
					GivePlayerMoney(playerid, - HausInfo[i][Preis]);
					strmid(HausInfo[i][Besitzer], Name, 0, strlen(Name), 24);
					HausInfo[i][Vergeben] = 1;
					SendClientMessage(playerid, FARBE_WEIЯ,"Du hast das Haus gekauft, um Befehle anzusehen schreibe /hauscmds !");
					return 1;
				}
				else
				{
				  SendClientMessage(playerid,FARBE_WEIЯ,"Du hast zu wenig Geld, du musst zuerst das Geld auf der Hand haben.");
				  return 1;
			 	}
		}
		return 1;
	}
Reply
#4

Quote:
Originally Posted by KuHS
Simply the command checks for all houses within for() looping with returns, so it's wrong. Example: 1 house, it checks, and it's not found, it sends a message, when returns and don't check for 2 house... am i right? I suggest you to use continue; function in for() loops. In for() loops return stops looping, continue just ends variable looping.

BTW. If you want to send end message, send it before for() looping.

Код:
if(strcmp(cmd,"/kaufen",true)==0)
	{
		for(new i=0;i<MAX_HOUSES;i++)
		{
		  if(!IsPlayerInRangeOfPoint(playerid, 3.0, HausInfo[i][eX], HausInfo[i][eY], HausInfo[i][eZ])) continue;
		    if(GetPlayerMoney(playerid) < HausInfo[i][Preis])
				{
		    	new Name[MAX_PLAYER_NAME];
			    GetPlayerName(playerid, Name, MAX_PLAYER_NAME);
					GivePlayerMoney(playerid, - HausInfo[i][Preis]);
					strmid(HausInfo[i][Besitzer], Name, 0, strlen(Name), 24);
					HausInfo[i][Vergeben] = 1;
					SendClientMessage(playerid, FARBE_WEIЯ,"Du hast das Haus gekauft, um Befehle anzusehen schreibe /hauscmds !");
					return 1;
				}
				else
				{
				  SendClientMessage(playerid,FARBE_WEIЯ,"Du hast zu wenig Geld, du musst zuerst das Geld auf der Hand haben.");
				  return 1;
			 	}
		}
		return 1;
	}
Thanks for the answer, but I have still one error,
namely from here:

Код:
new Name[MAX_PLAYER_NAME];
GetPlayerName(playerid, Name, MAX_PLAYER_NAME);
GivePlayerMoney(playerid, - HausInfo[i][Preis]);
strmid(HausInfo[i][Besitzer], Name, 0, strlen(Name), 24);
HausInfo[i][Vergeben] = 1;
SendClientMessage(playerid, FARBE_WEIЯ,"Du hast das Haus gekauft, um Befehle anzusehen schreibe /hauscmds !");
return 1;
The 2 lines are not running:

Код:
strmid(HausInfo[i][Besitzer], Name, 0, strlen(Name), 24);
HausInfo[i][Vergeben] = 1;
Whats here the problem?
Thx
Reply
#5

strmid(HausInfo[i][Besitzer], Name, 0, Besitzer_lenght);

Try this.
Reply
#6

What do you mean?
The lenght is 24 yes or no? xD sry, im a newbie.
Код:
enum hInfo
{
	Float:eX,
	Float:eY,
	Float:eZ,
	Float:aX,
	Float:aY,
	Float:aZ,
	Preis,
	Besitzer[24],
	Vergeben,
	Miete,
};
new HausInfo[MAX_HOUSES][hInfo];
If I /kaufen write should actually refer to the house written file will be and as I have a loop have should the game text to change even as I the / kaufen command HausInfo[house] [Vergeben] = 1;
and my loop looks like from:

Код:
if(HausInfo[i][Vergeben] == 1)
				{
    			format(bString, 64, "Preis%d", i);
				 	HausInfo[i][Preis] = INI_ReadInt(bString);
				  	format(bString, 64, "Besitzer%d", i);
					INI_ReadString(HausInfo[i][Besitzer],bString,24);
					format(bString,sizeof(bString),"~g~.:Haus Informationen:.~n~~w~Mietkosten: %d ~y~~n~Besitzer: %s~n~~w~Tippe /mieten um ein Zimmer zu mieten ~b~",HausInfo[i][Preis],HausInfo[i][Besitzer]);
					GameTextForPlayer(playerid,bString,2500,3);
				}
  			else
				{
    			format(bString, 64, "Preis%d", i);
				 	HausInfo[i][Preis] = INI_ReadInt(bString);
				 	format(bString, 64, "Besitzer%d", i);
					INI_ReadString(HausInfo[i][Besitzer],bString,24);
		 		 	format(bString,sizeof(bString),"~g~.:Haus Informationen:.~n~~w~Haus Preis: %d ~y~~n~Besitzer: %s ~b~~n~~w~Tippe /kaufen um das Haus zu kaufen",HausInfo[i][Preis],HausInfo[i][Besitzer]);
					GameTextForPlayer(playerid,bString,2500,3);
  			}
But is it still HausInfo.....[Vergeben] == 0
My english is very bad i hope u understand it xD
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)