Fishing works on fishing spot but not on reefer boat
#13

By on the boat you mean not actually IN the boat? I guess you could create a variable which saves the last entered vehicle ID, then when they exit the boat see if they're in range of it:
pawn Код:
new g_iLastVehicle[MAX_PLAYERS]; // Top of script

forward OnPlayerEnterVehicle(playerid, vehicleid, ispassenger); public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger) // Add to your existing callback, not overwrite.
    return g_iLastVehicle[playerid] = vehicleid;
Then it would be:
pawn Код:
CMD:fish(playerid, params[])
{
    new string[128], query[500], pname[24], vehid;
    vehid = GetPlayerVehicleID(playerid);
    GetPlayerName(playerid, pname, 24);
    if(!IsPlayerLoggedIn(playerid))
    {
        SendClientMessage(playerid, COLOR_LIGHTRED, "Error{FFFFFF}: You are not logged in.");
        return 1;
    }
    if(PlayerInfo[playerid][pFishPermit] < 1)
    {
        SendClientMessage(playerid, COLOR_LIGHTRED, "Error{FFFFFF}: You do not have a fishing permit.");
        return 1;
    }
    if(PlayerInfo[playerid][pFishingRod] < 1)
    {
        SendClientMessage(playerid, COLOR_LIGHTRED, "Error{FFFFFF}: You do not have a fishing rod.");
        return 1;
    }
    if(PlayerInfo[playerid][pBait] < 1)
    {
        SendClientMessage(playerid, COLOR_LIGHTRED, "Error{FFFFFF}: You do not have any bait.");
        return 1;
    }
    if(PlayerInfo[playerid][pFishes] == 5)
    {
        SendClientMessage(playerid, COLOR_LIGHTRED, "Error{FFFFFF}: You cannot hold any more fish in your inventory.");
        return 1;
    }
    if(PlayerInfo[playerid][pRodDurab] == 1)
    {
        format(string, sizeof(string), "* %s's rod has worn out and snapped into two pieces.", Name(playerid));
        SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
        PlayerInfo[playerid][pFishingRod] = 0;
        PlayerInfo[playerid][pRodDurab] = 0;
        format(query, sizeof(query), "UPDATE playerdata SET FishingRod=%d, RodDurab=%d WHERE Username='%s'",
        PlayerInfo[playerid][pFishingRod],
        PlayerInfo[playerid][pRodDurab],
        pname);
        mysql_query(query);
        return 1;
    }
    new Float:vehx, Float:vehy, Float:vehz;
    GetVehiclePos(g_iLastVehicle[playerid], vehx, vehy, vehz);

    if(IsPlayerInRangeOfPoint(playerid, 2.0, 2103.9148, -103.5168, 2.2754) || GetPlayerVehicleID(playerid) == 453 || IsPlayerInRangeOfPoint(playerid, 5.0, vehx, vehy, vehz) //< Fishing Boat
    {
        TogglePlayerControllable(playerid, 0);
        PlayerInfo[playerid][pRodDurab] -= 1;
        PlayerInfo[playerid][pBait] -= 1;
        format(query, sizeof(query), "UPDATE playerdata SET RodDurab=%d, Bait=%d WHERE Username='%s'",
        PlayerInfo[playerid][pRodDurab],
        PlayerInfo[playerid][pBait],
        pname);
        mysql_query(query);
        format(string, sizeof(string), "* %s casts their rod out into the sea.", Name(playerid));
        SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
        SetTimerEx("FishingTime", 15000, false, "i", playerid);
        return 1;
    }
    else
    {
        SendClientMessage(playerid, COLOR_LIGHTRED, "Error{FFFFFF}: You are not at a fishing spot.");
        return 1;
    }
}
Or you could loop though all the vehicles: (The public wouldn't be that accurate as it just searches for the vehicle regardless of the distance. Use a similar method but check players position from the vehicle)
pawn Код:
forward GetClosestVehicleFromPlayer(playerid); public GetClosestVehicleFromPlayer(playerid) {
    new Float:iDistance = 99999999.0;
    new iVehicleID = -1;
    new Float:p_fPos[3];
    GetPlayerPos(playerid, p_fPos[0], p_fPos[1], p_fPos[2]);
    for(new i = 1; i < MAX_VEHICLES; i++) {
        new Float:iTempDistance = GetVehicleDistanceFromPoint(i, p_fPos[0], p_fPos[1], p_fPos[2]);
        if(iTempDistance < iDistance) {
            iDistance = iTempDistance;
            iVehicleID = i;
        }
    }
    return iVehicleID;
}
Then it would be:
pawn Код:
CMD:fish(playerid, params[])
{
    new string[128], query[500], pname[24], vehid;
    vehid = GetPlayerVehicleID(playerid);
    GetPlayerName(playerid, pname, 24);
    if(!IsPlayerLoggedIn(playerid))
    {
        SendClientMessage(playerid, COLOR_LIGHTRED, "Error{FFFFFF}: You are not logged in.");
        return 1;
    }
    if(PlayerInfo[playerid][pFishPermit] < 1)
    {
        SendClientMessage(playerid, COLOR_LIGHTRED, "Error{FFFFFF}: You do not have a fishing permit.");
        return 1;
    }
    if(PlayerInfo[playerid][pFishingRod] < 1)
    {
        SendClientMessage(playerid, COLOR_LIGHTRED, "Error{FFFFFF}: You do not have a fishing rod.");
        return 1;
    }
    if(PlayerInfo[playerid][pBait] < 1)
    {
        SendClientMessage(playerid, COLOR_LIGHTRED, "Error{FFFFFF}: You do not have any bait.");
        return 1;
    }
    if(PlayerInfo[playerid][pFishes] == 5)
    {
        SendClientMessage(playerid, COLOR_LIGHTRED, "Error{FFFFFF}: You cannot hold any more fish in your inventory.");
        return 1;
    }
    if(PlayerInfo[playerid][pRodDurab] == 1)
    {
        format(string, sizeof(string), "* %s's rod has worn out and snapped into two pieces.", Name(playerid));
        SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
        PlayerInfo[playerid][pFishingRod] = 0;
        PlayerInfo[playerid][pRodDurab] = 0;
        format(query, sizeof(query), "UPDATE playerdata SET FishingRod=%d, RodDurab=%d WHERE Username='%s'",
        PlayerInfo[playerid][pFishingRod],
        PlayerInfo[playerid][pRodDurab],
        pname);
        mysql_query(query);
        return 1;
    }
    if(IsPlayerInRangeOfPoint(playerid, 2.0, 2103.9148, -103.5168, 2.2754) || GetPlayerVehicleID(playerid) == 453 || GetClosestVehicleFromPlayer(playerid) == 453) //< Fishing Boat
    {
        TogglePlayerControllable(playerid, 0);
        PlayerInfo[playerid][pRodDurab] -= 1;
        PlayerInfo[playerid][pBait] -= 1;
        format(query, sizeof(query), "UPDATE playerdata SET RodDurab=%d, Bait=%d WHERE Username='%s'",
        PlayerInfo[playerid][pRodDurab],
        PlayerInfo[playerid][pBait],
        pname);
        mysql_query(query);
        format(string, sizeof(string), "* %s casts their rod out into the sea.", Name(playerid));
        SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
        SetTimerEx("FishingTime", 15000, false, "i", playerid);
        return 1;
    }
    else
    {
        SendClientMessage(playerid, COLOR_LIGHTRED, "Error{FFFFFF}: You are not at a fishing spot.");
        return 1;
    }
}
I created the extra functions in the reply box so it will probably will have errors/warnings. (I don't have access to PAWN at the moment)

Hope it helps.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 6 Guest(s)