SA-MP Forums Archive
/lockb always returning else - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: /lockb always returning else (/showthread.php?tid=553468)



/lockb always returning else - HighFlyer - 29.12.2014

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;
}



Re: /lockb always returning else - Schneider - 29.12.2014

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?


Re: /lockb always returning else - HighFlyer - 29.12.2014

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.


Re: /lockb always returning else - sammp - 30.12.2014

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


Re: /lockb always returning else - HighFlyer - 30.12.2014

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]))
			{



Re: /lockb always returning else - HighFlyer - 30.12.2014

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;
}



Re: /lockb always returning else - Schneider - 30.12.2014

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;
}



Re: /lockb always returning else - HighFlyer - 30.12.2014

Got it now, thanks!