SA-MP Forums Archive
Some script quirk I can't figure out - 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: Some script quirk I can't figure out (/showthread.php?tid=585218)



Some script quirk I can't figure out - Caupo - 11.08.2015

I have a simple logic to lock door and unlock door.
Logic itself is following:Building direct owners or if building is assigned to some group the building door can be locked and unlocked by people who are relate to those parameters.

The weird problem with the logic which apperas with players is that they can unlock and lock building door when being in the entrance position of the building but if they are at the exit position then they receive non-succesful notification text "You're not the building owner or don't belong to building group!".

Funny part of that is, I tested it out, and it worked with no problems, I even changed different parameters which could influence those if statements, but everything worked as it should.
I just want to know does someone see something what I can't see in the picture right now.
I know how to fix it by writing some disasteres hardcoded if's with virtual world parameters (which im setting to player by the building id if they enter one), but I don't want to flush down the toilet nicely writed code. Because the current state of code should work in any case by the looks of it.

Code itself is as following, should be clear to understand.
Код:
CMD:doorlock(playerid, params[])
{
    for(new i = 1; i <= gBuildingsTotal; i++)
    {
        if(IsPlayerNearBuildingEntrance(playerid, i) || IsPlayerNearBuildingExit(playerid, i))
        {
            if(IsPlayerBuildingOwner(playerid, i) || IsPlayerGroupBuildingMember(playerid, i))
            {
                if(GetPlayerRank(playerid) < 3 && IsPlayerGroupBuildingMember(playerid, i) && !IsPlayerBuildingOwner(playerid, i))
                {
                    SendNotification(playerid, 3, "You need to be atleast rank 3 to (un)lock that building doors!");
                    return 1;
                }
	        if(IsBuildingLocked(i))
	        {
	            bS[i][buLocked] = 0;
	            SendNotification(playerid, 1, "Opened door!");
	        }
	        else
	        {
	            bS[i][buLocked] = 1;
	            SendNotification(playerid, 1, "Locked door!");
		}
	        UpdateBuildingInt(bS[i][buID], "isLocked", bS[i][buLocked]);
	    }
	    else
	    {
		 SendNotification(playerid, 3, "You're not the building owner or don't belong to building group!");
	    }
	    return 1;
	}
    }
    SendNotification(playerid, 3, "You're not near any building.");
    return 1;
}



Re: Some script quirk I can't figure out - HBG - 11.08.2015

You use way to many custom functions lmao, but uh show your IsPlayerNearBuildingExit code.


Re: Some script quirk I can't figure out - Caupo - 12.08.2015

These custom functions make overall gamemode script management very easy and nicely to understand for others. I also work in web-development, so it's more comfortable to write script this way (with words) than spamming [[}}}]\}[}[] all the way to get shit done when using arrays/arraylike variable types.

Код:
IsPlayerNearBuildingEntrance(playerid, idx, Float:_range = 1.0)
{
	if(IsPlayerInRangeOfPoint(playerid, _range, bS[idx][buEX], bS[idx][buEY], bS[idx][buEZ]))
	{
	    return true;
	}
	return false;
}
IsPlayerNearBuildingExit(playerid, idx, Float:_range = 1.0)
{
	if(IsPlayerInRangeOfPoint(playerid, _range, bS[idx][buQX], bS[idx][buQY], bS[idx][buQZ]))
	{
	    return true;
	}
	return false;
}