if player position don't change exist?
#1

i need to do here:
Код:
			if(SweepTime[i] > 0)
			{
			    if(SweepTime[i] >= 16)
				{
					SweepTime[i] = 1;
					if(SweepDriver[i] < 999)
					{
						if(IsPlayerConnected(SweepDriver[i]))
						{
	      				return 1;
						}
					}
				}		
			    SweepTime[i] += 1;
				SweepCost[i] += 3;
			    format(string, sizeof(string), "~g~Salariul:%d$", SweepCost[i]);
			    GameTextForPlayer(i, string, 15000, 1);
			}
I want to SweepCost + 3 ONLY if Player drive the car ! and if stop to don't give money for him!
Reply
#2

you should save previous position and compare with current position. Declare variables with previous pos.
pawn Код:
new Float:lastPosition[MAX_PLAYERS][3];
As float isn't accurate type, it's better to use this foo
pawn Код:
stock IsPointInRangeOfPoint(Float:x, Float:y, Float:z, Float:x2, Float:y2, Float:z2, Float:range)
{
    x2 -= x;
    y2 -= y;
    z2 -= z;
    return ((x2 * x2) + (y2 * y2) + (z2 * z2)) < (range * range);
}
and your finale code can be like
pawn Код:
if(SweepTime[i] > 0)
            {
                if(SweepTime[i] >= 16)
                {
                    SweepTime[i] = 1;
                    if(SweepDriver[i] < 999)
                    {
                        if(IsPlayerConnected(SweepDriver[i]))
                        {
                                return 1;
                        }
                    }
                }
                new Float:x, Float:y, Float:z;
                GetPlayerPos(playerid, x, y, z);
                if(!IsPointInRangeOfPoint(x, y, z, lastPosition[playerid][0], lastPosition[playerid][1], lastPosition[playerid][2], 0.1))
                {      
                    SweepTime[i] += 1;
                    SweepCost[i] += 3;
                    lastPosition[playerid][0] = x;
                    lastPosition[playerid][1] = y;
                    lastPosition[playerid][2] = z;
                }
                format(string, sizeof(string), "~g~Salariul:%d$", SweepCost[i]);
                GameTextForPlayer(i, string, 15000, 1);
            }
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)