PDA

View Full Version : Does not get that I am at a certain location.


Denying
08/03/2013, 09:24 AM
First of all, thank you for reading this.

Alright, I've been creating my own house system and it used to work perfectly but now it does not. ( Still at the beginning though ) When I type /buyhouse it constantly tells me I am not at any house.

if (strcmp("/buyhouse", cmdtext, true, 10) == 0)
{
for( new i = 0; i <= MAX_HOUSES; i++)
{
format(file, sizeof(file), "House_%d.ini", i );
x = dini_Float(file, "enterX");
y = dini_Float(file, "enterY");
z = dini_Float(file, "enterZ");
forSale = dini_Get(file, "ForSale");
if(IsPlayerInRangeOfPoint(playerid, 3.0, x ,y ,z ))
{
if(strval(forSale) == 0) return SendClientMessage(playerid, 0xFFFFFFFF, "ERROR: This house is not for sale!");
GetPlayerName(playerid, name, sizeof(name));
if(strval(name) == strval(dini_Get(file, "Owner"))) return SendClientMessage(playerid, 0xFFFFFFFF, "ERROR: You may not buy your own house!");
SendClientMessage(playerid, 0xFFFFFFFF, "gsdgsdgsdsdgsdgsdgsdg");
atHouse[playerid] = true;
}
if(atHouse[playerid] == false) return SendClientMessage(playerid, 0xFFFFFFFF, "ERROR: You are not at any house.");
}
return 1;
}

NOTE: It currently has no price involved, as I test every line I add and now it does not work.

zxc1
08/03/2013, 09:52 AM
EDIT: Your loop goes through all the houses, which is the source of your bug. You have to get the ID of the current house, use some stock or so. (e.g. GetHouseID(playerid)).

Denying
08/03/2013, 09:55 AM
Your cmd works like the following:
Gets the XYZ of the house, check if the player at the entrance, if yes continues into the brackets and with the code at the same time.
So you have to delay the checking, which is kinda not needed mess. I recommend you to delete the variable "atHouse". and return simply:else return SendClientMessage(playerid, 0xFFFFFFFF, "ERROR: You are not at any house.");
But it's up to you.

It would send it at the amount of MAX_HOUSES, example: MAX_HOUSES = 50

You are not at any house x50 will be sent to the same player. That's why I am using a bool.

Denying
08/03/2013, 10:00 AM
I see. I will do that. I will reply here in a few hours after doing it. ( Not going to be at home for a while )

Thank you.

Denying
08/03/2013, 05:00 PM
I can not think of a way to do it as my mind is stuck in the same way as I done it above, getting the coordinates and if the player is at one of those houses it will set a certain bool to true etc..

Could you suggest any way to do it?

EDIT: I have this on my OnGameModeInit


for( new i = 0; i <= MAX_HOUSES; i++)
{
format(file, sizeof(file), "House_%d", i);
if(fexist(file))
{
x = dini_Float(file, "EnterX");
y = dini_Float(file, "EnterY");
z = dini_Float(file, "EnterZ");
HouseInfo[i][EnterX] = x;
HouseInfo[i][EnterY] = y;
HouseInfo[i][EnterZ] = z;
}
}

But it still does the same problem.

Denying
09/03/2013, 07:59 AM
I've just noticed that I used dini_Float(file, "enterX"); instead of dini_Float(file, "EnterX""); although it did not change a single thing.

Denying
09/03/2013, 08:07 AM
Okay, so I made the following stock just to check if it works, and.. it does not:

stock GetHouseID(playerid)
{
for(new i = 0; i <= MAX_HOUSES; i++)
{
format(file, sizeof(file), "House_%d.ini", i);
if(fexist(file))
{
x = dini_Float(file, "EnterX");
y = dini_Float(file, "EnterY");
z = dini_Float(file, "EnterZ");
if(IsPlayerInRangeOfPoint(playerid, 3.0, x, y, z))
{
format(str, sizeof(str), "%d", i); // Debugging.
SendClientMessage(playerid, 0xFFFFFFFF, str); // Debugging.
}
}
}
return 1;
}

It just does not send the message as I used the same form as I used in /buyhouse. My mind is stuck in that form, I can not think about any other way. May anyone help me out with this?

Denying
09/03/2013, 08:39 AM
Okay, I modified it a bit and now it SendClientMessage the ID of the house as I wanted it to do. I'll work on the buyhouse and reply here as soon as I'm done. Thank you.

Denying
09/03/2013, 08:49 AM
One little question, how may I know if a player's name is the same as a certain pre-choesn name?
Simple words.. comparing two strings. I tried using strcmp but it kept saying that the player's name is the same as the chosen name but it was not.

zxc1
09/03/2013, 08:52 AM
I can't think of any other way than 'strcmp'.
Perhaps you didn't changed the 'bool:ignorecase'.

Denying
09/03/2013, 08:57 AM
Let's say we have the following;

GetPlayerName(playerid, name, sizeof(name)); // name = Daniel
GetPlayerName(randomguy, pname, sizeof(pname)); // pname = Jack

How will I compare them using strcmp? I tried strcmp( name, pname, false) but it kept on saying that pname is the same as name.

zxc1
09/03/2013, 10:23 AM
if(strcmp(name,pname,false,strlen(name)) == 0) { }
== 0 means they are the same.

Denying
09/03/2013, 11:41 AM
I did not see the message but anyway I figured how to use strcmp. xD
Thank you anyway! Everything now works perfectly. You deserve a reputation point.
EDIT: I can not give you a reputation point, seems like I already gave you.