/lockb always returning else
#1

The command I have written always returns the else clause of IsPlayerInRangeOfPoint. Even if I am right inside the pickup, it will still display that I'm not near my business. The coords are correct, as /enter /exit commands teleport move the player to these coords when they leave the interior. Am I missing something?

Код:
command(lockb, playerid, params[])
{
	if(IsPlayerInRangeOfPoint(playerid, 5.0, Business[playerid][BusinessExteriorX], Business[playerid][BusinessExteriorY], Business[playerid][BusinessExteriorZ]))
	{
		if(strmatch(Business[playerid][BusinessOwner], pName(playerid)))
		{
    		new string[256];
    		format(string, sizeof(string), "You have locked: %s. No one can enter this business now. Type /lockb again to unlock property.", Business[playerid][BusinessName]);
    		SendClientMessage(playerid, WHITE, string);
    		Business[playerid][BusinessLocked] = 1;
		}
		else return SendClientMessage(playerid, WHITE, "You are not the owner of this business.");
	}
	else return SendClientMessage(playerid, WHITE, "You are not near the business you want to lock.");
	return 1;
}
Reply
#2

Are you really, really, realllyy sure the coordinates are correct?

Try to add these prints this and see what it prints:

pawn Код:
command(lockb, playerid, params[])
{
    new Float:tmpX, Float:tmpY, Float:tmpZ;
    GetPlayerPos(playerid, tmpX, tmpY, tmpZ);
    printf("PlayerPos:   %.1f, %.1f, %.1f", tmpX, tmpY, tmpZ);
    printf("BuisnessPos: %.1f, %.1f, %.1f", Business[playerid][BusinessExteriorX], Business[playerid][BusinessExteriorY], Business[playerid][BusinessExteriorZ]);
    if(IsPlayerInRangeOfPoint(playerid, 5.0, Business[playerid][BusinessExteriorX], Business[playerid][BusinessExteriorY], Business[playerid][BusinessExteriorZ]))
    {
        print("Player is in range");
are you sure the coordinates are close to eachother?
Reply
#3

This is strange, because I can /enter the business with these coords in the database:

BusinessExteriorX: -2455.44
BusinessExteriorY: 2254.09
BusinessExteriorZ: 4.9805

However, on the console, I get 0.0 coords for BusinessPos, and identical coordinates as above for PlayerPos.
Reply
#4

Your BusinessExteriorX, Y and Z aren't being loaded in if it's showing 0.0
Reply
#5

Quote:
Originally Posted by sammp
Посмотреть сообщение
Your BusinessExteriorX, Y and Z aren't being loaded in if it's showing 0.0
That's what I guessed, however I can purchase businesses and enter them using the same code, except a parent loop above the if statement, which loops all businesses, like this...

Код:
for(new i = 1; i < MAX_BUSINESS; i++)
		{
			if(IsPlayerInRangeOfPoint(playerid, 3.0, Business[i][BusinessExteriorX], Business[i][BusinessExteriorY], Business[i][BusinessExteriorZ]))
			{
Reply
#6

What would I need to do then? Would this approach solve the issue?

Код:
IsPlayerNearBiz(playerid)
{
	for(new i = 1; i < MAX_BUSINESS; i++)
	{
		if(IsPlayerInRangeOfPoint(playerid, 3.0, Business[i][BusinessExteriorX], Business[i][BusinessExteriorY], Business[i][BusinessExteriorZ])) return i;
	{
    }
    return -1;
}

command(lockb, playerid, params[])
{
	new id = IsPlayerNearBiz(playerid);
	if(id != Business[playerid][BusinessOwner]) return SendClientMessage(playerid, GREY, "You are not the owner of this business.");
	
	// if, else etc.

	return 1;
}
Reply
#7

pawn Код:
command(lockb, playerid, params[])
{
    new id = IsPlayerNearBiz(playerid);
    if(id == -1) return SendClientMessage(playerid, -1, "You're not near a business");
    if(strmatch(Business[id][BusinessOwner], pName(playerid)))
    {
    // if, else etc.
    }
    return 1;
}
Reply
#8

Got it now, thanks!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)