Hello again!
I have a new problem with c++ and my math skills. I have a new table with this structure
id
int(10) NOT NULL AUTO_INCREMENT
point_mapid
smallint(5) DEFAULT NULL
point_1_x
float DEFAULT ‘0’
point_1_y
float DEFAULT ‘0’
point_2_x
float DEFAULT ‘0’
point_2_y
float DEFAULT ‘0’
point_3_x
float DEFAULT ‘0’
point_3_y
float DEFAULT ‘0’
point_4_x
float DEFAULT ‘0’
point_4_y
float DEFAULT ‘0’
and this data:
‘1’, ‘0’, ‘-9253.11’, ‘355.97’, ‘-9264.71’, ‘370.3’, ‘-9292.29’, ‘347.97’, ‘-9277.21’, ‘332.27’
‘2’, ‘0’, ‘-9280.16’, ‘317.92’, ‘-9287.36’, ‘325.82’, ‘-9293.8’, ‘319.94’, ‘-9287.89’, ‘312.09’
This points create ingame a rectangle around my little house:
http://www11.pic-upload.de/17.06.14/owbpnvnknmy.jpg
Now i want to find out “Is the player in my area?”. I try to create a new function which return the id from the correct entry in the database:
static uint32 AktuellesHaus(float player_x, float player_y, uint32 player_mapid)
{
//Get all entrys which are on the players map
QueryResult getEntrys = WorldDatabase.PQuery(“SELECT point_1_x, point_2_x, point_3_x, point_4_x, point_1_y, point_2_y, point_3_y, point_4_y, point_mapid, id FROM my_table WHERE point_mapid = %u”, player_mapid);
bool found = false;
uint32 entryid = 0;
//no entrys then return 0
if(!getEntrys)
{
return entryid;
}
//check all entrys
do
{
Field* fields = getEntrys->Fetch();
float minValueX = fields[0].GetFloat();
float maxValueX = fields[0].GetFloat();
float minValueY = fields[4].GetFloat();
float maxValueY = fields[4].GetFloat();
uint32 i = 0;
//get the lowest/highest X value from all point coords
for(i=0; i<4; i++)
{
if(minValueX > fields[i].GetFloat())
{
minValueX = fields[i].GetFloat();
}
if(maxValueX < fields[i].GetFloat())
{
maxValueX = fields[i].GetFloat();
}
}
//get the lowest/highest Y value from all point coords
for(i=4; i<8; i++)
{
if(minValueY > fields[i].GetFloat())
{
minValueY = fields[i].GetFloat();
}
if(maxValueY < fields[i].GetFloat())
{
maxValueY = fields[i].GetFloat();
}
}
bool inXCoord = false;
bool inYCoord = false;
//check x value
float resultminValueX = minValueX - player_x;
float resultmaxValueX = maxValueX - player_x;
if(resultminValueX < 0 && resultmaxValueX > 0)
{
inXCoord = true;
}
//check y value
float resultminValueY = minValueY - player_y;
float resultmaxValueY = maxValueY - player_y;
if(resultminValueY < 0 && resultmaxValueY > 0)
{
inYCoord = true;
}
if(inXCoord && inYCoord && player_mapid == fields[8].GetUInt32())
{
found = true;
entry = fields[9].GetUInt32();
}
//crawl all entrys or break if found an correct entry
} while(getEntrys->NextRow() || found == false);
//return entry
return entry;
}
So it works very rough, because the check is inexact. My character can stand 4 feets next to the red line (screenshot). In the screenshot the function tells that my character is in the area with ID 1, but he is not in the area. So everyone an better idea to check it?
The second problem is, that the core crash if i call the function 10 times in 5 secs.