IsPlayerInRangeOfPoint
#1

i tried checking if the player is in range of point then the value set to the id of business and if not in range of point then it set to 0 and i set the timer for this public repeat each second. but when i get in game and go to the area. it doesnt work. but when i deleted the detect if i am not in the area. the command work. but ofcourse when i get out of the area i can still use the command because the value is not 0 anymore. i just wonder how to detect if i am not in the area correctly
Код:
public InBusinessCheck(playerid)
{
    for(new i = 0; i < sizeof(Businesses); i++)
	if(IsPlayerInRangeOfPoint(playerid, 3, Businesses[i][bInteriorX], Businesses[i][bInteriorY], Businesses[i][bInteriorZ]))
	{
		Player[playerid][InBusiness] = i;
	}
	for(new i = 0; i < sizeof(Businesses); i++)
	if(!IsPlayerInRangeOfPoint(playerid, 3, Businesses[i][bInteriorX], Businesses[i][bInteriorY], Businesses[i][bInteriorZ]))
	{
	    Player[playerid][InBusiness] = 0;
	}
	return 1;
}
Reply
#2

PHP код:
public InBusinessCheck(playerid)
{
    
Player[playerid][InBusiness] = -1;
    
    for(new 
0sizeof(Businesses); i++)
    {
        if(
IsPlayerInRangeOfPoint(playerid3Businesses[i][bInteriorX], Businesses[i][bInteriorY], Businesses[i][bInteriorZ]))
        {
            
Player[playerid][InBusiness] = i;
            break;
        }
    }
    return 
1;

You set it to 0 at first and if the player is in range, it sets the new value and stops the loop otherwise (not in range of any business) it will remain 0.

EDIT: Actually 0 is a valid business ID so set it to -1. You must check if the variable is not -1 in case you use it in arrays though to prevent run time error 4.
Reply
#3

no. i have aldready set it to 0 at first. i made this timer to check if he/or she enter the business areas, if he is in then the value is i(value of the business). so the command /buy will show the right dialog with the i as the id of the business. but when he is not in the business areaes then the value return 0. /buy should not work.
here is the/buy command
Код:
command(buy, playerid, params[])
{
    #pragma unused params
    if(Businesses[Player[playerid][InBusiness]][bType] == 1)
    {
        new string[160], price1 = Businesses[Player[playerid][InBusiness]][bProductPrice1];
        new price2 = Businesses[Player[playerid][InBusiness]][bProductPrice2];
        new price3 = Businesses[Player[playerid][InBusiness]][bProductPrice3];
        new price4 = Businesses[Player[playerid][InBusiness]][bProductPrice4];
        new price5 = Businesses[Player[playerid][InBusiness]][bProductPrice5];
//        new price6 = Businesses[Player[playerid][InBusiness]][bProductPrice6];
        new price7 = Businesses[Player[playerid][InBusiness]][bProductPrice7];
        new price8 = Businesses[Player[playerid][InBusiness]][bProductPrice8];
//        new price9 = Businesses[Player[playerid][InBusiness]][bProductPrice9];
        format(string, sizeof(string), "Rope ($%d)\nRags ($%d)\nPhone ($%d)\nPhonebook ($%d)\nBottle o' Sprunk ($%d)\nSpraycan ($%d)\nWalkie Talkie ($%d)", price1, price2, price3, price4, price5, price7, price8);
        ShowPlayerDialog(playerid, 631, DIALOG_STYLE_LIST, "Select the product you wish to purchase.", string, "Purchase", "Cancel");
    }
    else if(Businesses[Player[playerid][InBusiness]][bType] == 11)
    {
        new string[128];
        format(string, sizeof(string), "5 grams of Pot ($%d)\n5 grams of Cocaine ($%d)", Businesses[Player[playerid][InBusiness]][bProductPrice1], Businesses[Player[playerid][InBusiness]][bProductPrice2]);
        ShowPlayerDialog(playerid, 8561, DIALOG_STYLE_LIST, "Select the product you wish to purchase.", string, "Purchase", "Cancel");
    }
    else if(Businesses[Player[playerid][InBusiness]][bType] == 12)
    {
        new string[128];
        new price1 = Businesses[Player[playerid][InBusiness]][bProductPrice1];
        new price2 = Businesses[Player[playerid][InBusiness]][bProductPrice2];
        new price3 = Businesses[Player[playerid][InBusiness]][bProductPrice3];
        format(string, sizeof(string), "Sprunk ($%d)\nVegetarian Surprise ($%d)\nMeat Feast Pizza ($%d)\n", price1, price2, price3);
        ShowPlayerDialog(playerid, 81, DIALOG_STYLE_LIST, "Select the product you wish to purchase.", string, "Purchase", "Cancel");
    }
    else if(Businesses[Player[playerid][InBusiness]][bType] == 5)
    {
        new string[135];
		new price1 = Businesses[Player[playerid][InBusiness]][bProductPrice1];
        new price2 = Businesses[Player[playerid][InBusiness]][bProductPrice2];
        new price3 = Businesses[Player[playerid][InBusiness]][bProductPrice3];
        new price4 = Businesses[Player[playerid][InBusiness]][bProductPrice4];
        new price5 = Businesses[Player[playerid][InBusiness]][bProductPrice5];
        new price6 = Businesses[Player[playerid][InBusiness]][bProductPrice6];
        new price7 = Businesses[Player[playerid][InBusiness]][bProductPrice7];
        format(string, sizeof(string), "Rope ($%d)\nSmall White Vibrator ($%d)\nSilver Vibrator ($%d)\nLarge White Vibrator ($%d)\nPriest ($%d)\nNaughty Girl Cop Costume ($%d)\nCat Woman Costume ($%d)", price1, price2, price3, price4, price5, price6, price7);
        ShowPlayerDialog(playerid, 257, DIALOG_STYLE_LIST, "Select the product you wish to purchase.", string, "Purchase", "Cancel");
    }
    return 1;
}
and all the business is saved in .ini files thats why i need to make it like this
Reply
#4

I then realized I forgot about 0 completely that it's a valid one and I edited the post. Set to -1 and in the /buy command:
pawn Код:
if (Player[playerid][InBusiness] == -1) return // error: not in range of any business
// rest of code..
But the best solution would be to loop once in the /buy command, I don't see any point of using a timer and looping over and over again.
Reply
#5

i got the solution now thank to your suggestion . thank you very much. i would have rep + you if i can do it again . thanks for helping me (replied all of my threads)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)