SA-MP Forums Archive
Fishing works on fishing spot but not on reefer boat - 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: Fishing works on fishing spot but not on reefer boat (/showthread.php?tid=414599)



Fishing works on fishing spot but not on reefer boat - AphexCCFC - 10.02.2013

pawn Код:
if(!IsPlayerInRangeOfPoint(playerid, 2.0, 2103.9148, -103.5168, 2.2754) || !IsPlayerInVehicle(playerid, 451))
    {
        SendClientMessage(playerid, COLOR_LIGHTRED, "Error{FFFFFF}: You are not at a fishing spot.");
        return 1;
    }
My /fish command works at the fishing spot, but not on the reefer boat (vehicle ID 451) ^^
Does anyone have any idea why? Cheers!


Re: Fishing works on fishing spot but not on reefer boat - ryansheilds - 10.02.2013

Change the or ("||") to and ("&&"):
pawn Код:
if(!IsPlayerInRangeOfPoint(playerid, 2.0, 2103.9148, -103.5168, 2.2754) && !IsPlayerInVehicle(playerid, 451))
    {
        SendClientMessage(playerid, COLOR_LIGHTRED, "Error{FFFFFF}: You are not at a fishing spot.");
        return 1;
    }



Re: Fishing works on fishing spot but not on reefer boat - AphexCCFC - 10.02.2013

Quote:
Originally Posted by ryansheilds
Посмотреть сообщение
Change the or ("||") to and ("&&"):
pawn Код:
if(!IsPlayerInRangeOfPoint(playerid, 2.0, 2103.9148, -103.5168, 2.2754) && !IsPlayerInVehicle(playerid, 451))
    {
        SendClientMessage(playerid, COLOR_LIGHTRED, "Error{FFFFFF}: You are not at a fishing spot.");
        return 1;
    }
That would basically be saying "if you're not at the fishing spot AND the boat both at once, the command will display the error."


Re: Fishing works on fishing spot but not on reefer boat - ryansheilds - 10.02.2013

Sorry but I'm pretty sure I'm right? (It may be late and I may be a tired but if you're NOT at the specified point and NOT in the specified vehicle, it will return the error message? - From another point, if you're at the point and not in the vehicle it will skip the error message?)

You could always try it and see if it works...


Re: Fishing works on fishing spot but not on reefer boat - AphexCCFC - 10.02.2013

Quote:
Originally Posted by ryansheilds
Посмотреть сообщение
Sorry but I'm pretty sure I'm right? (It may be late and I may be a tired but if you're NOT at the specified point and NOT in the specified vehicle, it will return the error message? - From another point, if you're at the point and not in the vehicle it will skip the error message?)

You could always try it and see if it works...
I've tried, but with no success :P
I want it so if you're either driving the boat or atleast on the boat it will allow me to use /fish.
The fishing spot works, just not the boat :/


Re: Fishing works on fishing spot but not on reefer boat - AphexCCFC - 10.02.2013

Someone please help.
New script:
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) || IsPlayerInVehicle(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;
    }
}
But it still says the error message when I'm on the boat!


Re: Fishing works on fishing spot but not on reefer boat - AphexCCFC - 10.02.2013

Bump, please help.


Re: Fishing works on fishing spot but not on reefer boat - MP2 - 10.02.2013

Ryan was halfway there by telling you that you need to use &&.

pawn Код:
if(!IsPlayerInRangeOfPoint(playerid, 2.0, 2103.9148, -103.5168, 2.27) && GetVehicleModel(GetPlayerVehicleID(playerid)) != 451)
{
    return SendClientMessage(playerid, COLOR_LIGHTRED, "Error{FFFFFF}: You are not at a fishing spot.");
}
That means:

If they are not at the point, and not in a reefer, they can't fish.


Re: Fishing works on fishing spot but not on reefer boat - AphexCCFC - 10.02.2013

Yeah, I've tried with || AKA "or" too, but doesn't seem to work still.


Re: Fishing works on fishing spot but not on reefer boat - AphexCCFC - 10.02.2013

Sorry I mean I've tried with && too.


Re: Fishing works on fishing spot but not on reefer boat - MP2 - 10.02.2013

Okay, I'm confused. Is the fishing spot somewhere you go on-foot, or do you want players to park a boat there and fish?


Re: Fishing works on fishing spot but not on reefer boat - AphexCCFC - 10.02.2013

I want it so if they are at the fishing spot or if they are either on the fishing boat or even at the steering wheel it will allow them to /fish. I did mess up with reefer boat ID which I posted as 451 but it is actually 453, even after changing the ID it didn't work


Re: Fishing works on fishing spot but not on reefer boat - ryansheilds - 10.02.2013

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.


Re: Fishing works on fishing spot but not on reefer boat - spreilly - 05.03.2013

What it means is that you have to be DRIVING the reefer, not just near it. The post above can make it so that it is near the Reefer (as in, in the back after you drive it out)