Problem with a callback
#1

This is the callback (which I'd like to use just like the PlayerToPoint function) which doesn't work:

Код:
public IsVehicleInRadius(playerid)
{
	for(new c=0;c<MAX_VEHICLES;c++)
	{
	    new Float:x, Float:y, Float:z;
		GetVehiclePos(c,x,y,z);
		if(PlayerToPoint(5.0, playerid, x, y, z))
		{
		    return 1;
		}
		else
		{
		    SendClientMessage(playerid, COLOR_YELLOW, "You're not at your car!");
		    return 1;
		}
	}
	return 1;
}
It should check if there is a car near the player, but even if I am on top of a car it says the else thing.
At the return 1; it should continue with the command:

Код:
		else if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
		{
      		GetVehicleParamsEx(carid,engine,lights,alarm,doors,bonnet,boot,objective);
			if(doors == 0)
			{
   				if(IsVehicleInRadius(playerid))
			    {
   		    		if(PlayerInfo[playerid][pCar] == DynamicCars[VehicleLockedPlayer[playerid]][CarID])
   		    		{
						if(PlayerInfo[playerid][pSex] == 1)
						{
							PlayerActionMessage(playerid,15.0,"has just unlocked his vehicle.");
						}
						else
						{
							PlayerActionMessage(playerid,15.0,"has just unlocked her vehicle.");
						}
						SendClientMessage(playerid,COLOR_LIGHTYELLOW2,"[INFO:] Vehicle Unlocked.");
						SetVehicleParamsEx(carid,VEHICLE_PARAMS_OFF,VEHICLE_PARAMS_OFF,VEHICLE_PARAMS_OFF,VEHICLE_PARAMS_OFF,VEHICLE_PARAMS_OFF,VEHICLE_PARAMS_OFF,VEHICLE_PARAMS_OFF);
					}
					else
					{
					    SendClientMessage(playerid, COLOR_RED, "You do not have the keys for this vehicle!");
					}
			    }
			}
But it doesn't
Reply
#2

Quote:
Originally Posted by Ice-cup
Посмотреть сообщение
This is the callback (which I'd like to use just like the PlayerToPoint function) which doesn't work:

Код:
public IsVehicleInRadius(playerid)
{
	for(new c=0;c<MAX_VEHICLES;c++)
	{
	    new Float:x, Float:y, Float:z;
		GetVehiclePos(c,x,y,z);
		if(PlayerToPoint(5.0, playerid, x, y, z))
		{
		    return 1;
		}
		else
		{
		    SendClientMessage(playerid, COLOR_YELLOW, "You're not at your car!");
		    return 1;
		}
	}
	return 1;
}
It should check if there is a car near the player, but even if I am on top of a car it says the else thing.
At the return 1; it should continue with the command:

Код:
		else if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
		{
      		GetVehicleParamsEx(carid,engine,lights,alarm,doors,bonnet,boot,objective);
			if(doors == 0)
			{
   				if(IsVehicleInRadius(playerid))
			    {
   		    		if(PlayerInfo[playerid][pCar] == DynamicCars[VehicleLockedPlayer[playerid]][CarID])
   		    		{
						if(PlayerInfo[playerid][pSex] == 1)
						{
							PlayerActionMessage(playerid,15.0,"has just unlocked his vehicle.");
						}
						else
						{
							PlayerActionMessage(playerid,15.0,"has just unlocked her vehicle.");
						}
						SendClientMessage(playerid,COLOR_LIGHTYELLOW2,"[INFO:] Vehicle Unlocked.");
						SetVehicleParamsEx(carid,VEHICLE_PARAMS_OFF,VEHICLE_PARAMS_OFF,VEHICLE_PARAMS_OFF,VEHICLE_PARAMS_OFF,VEHICLE_PARAMS_OFF,VEHICLE_PARAMS_OFF,VEHICLE_PARAMS_OFF);
					}
					else
					{
					    SendClientMessage(playerid, COLOR_RED, "You do not have the keys for this vehicle!");
					}
			    }
			}
But it doesn't
Don't use it as a callback, use it as function. Just remove the 'public'-tag and it should work I think.
Reply
#3

That is because you are checking only the first vehicle to see if the player is near it. Here is, hopefully, the working code. I suggest you look up some structures on how to properly execute loops. Note that 'return' stops the rest of the code from executing, and since you have it in both places, it's useless. I also slightly optimized this code. You can also use IsPlayerInRangeOfPoint. Seeing it's a native function, it will be slightly faster.
pawn Код:
public IsVehicleInRadius(playerid)
{
        new Float:x, Float:y, Float:z;
    for(new c=0;c<MAX_VEHICLES;c++)
    {
        GetVehiclePos(c,x,y,z);
        if( IsPlayerInRangeOfPoint( playerid, 5.0, x, y, z ) ) return 1;
        continue;
    }
        SendClientMessage( playerid, COLOR_YELLOW, "You are not near the car!" );
    return 0;
}
This function has also been slightly changed to return 0 if the player is not near the vehicle.
Reply
#4

Doesn't work,
No message pops up (the you are not near..) and it returns logically Unknown command.
Although, I am 1 step away from my car.
Reply
#5

Tried without the publc infront and still doesn't work.
It return 0 and doesn't continues
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)