Can anyone tell me whats wrong here?
#1

Well, when i am alone on the server, everything works fine.. But when we are 2, or more online
then if i try to /fish, it just come with the message after one second "You pulled your line out of the water"
and it will keep doing that.. I really hope anyone can help me. rep+


This is the timer that will stop fishing if you leave the water
pawn Код:
forward CheckFish();
public CheckFish()
{
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(!IsPlayerNearWater(i))
        {
            if(Fishing[i] == 1)
            {
                SendClientMessage(i, COLOR_GREY, "You pulled your line out of the water.");
                Fishing[i] = 0;
                RemovePlayerAttachedObject(i,0);
                KillTimer(fishtimer[i]);
            }
        }
    }
    return 1;
}
This is the near water stock..
pawn Код:
stock IsPlayerNearWater(playerid)
{
    static Float:pos[3];
    GetPlayerPos(playerid, pos[0], pos[1], pos[2]);//read positions

    static Float:check_pos[3];
    static Float:angle;

    #define THRESHOLD   20.0
    #define RADIUS      4.0
    if(pos[2] > -20.0 && pos[2] < THRESHOLD)
    {
        for(new i = 0; i < 4; i++)
        {
            check_pos[0] = pos[0] + (RADIUS * floatsin(-angle, degrees));
            check_pos[1] = pos[1] + (RADIUS * floatcos(-angle, degrees));
            angle += 90.0;

            MapAndreas_FindZ_For2DCoord(check_pos[0], check_pos[1], check_pos[2]);

            if(check_pos[2] == 0.0) return true;
        }
    }
    return false;
}
Please tell me if you need more info
Reply
#2

PHP код:
forward CheckFish();
public 
CheckFish()
{
    foreach(new 
iPlayer)// this loop will fix it 
    
{
        if(!
IsPlayerNearWater(i))
        {
            if(
Fishing[i] == 1)
            {
                
SendClientMessage(iCOLOR_GREY"You pulled your line out of the water.");
                
Fishing[i] = 0;
                
RemovePlayerAttachedObject(i,0);
                
KillTimer(fishtimer[i]);
            }
        }
    }
    return 
1;

Reply
#3

its giving me this output

C:\Users\Maya\Desktop\gf_july21_2016.pwn(11602) : error 017: undefined symbol "foreach"
C:\Users\Maya\Desktop\gf_july21_2016.pwn(11602) : error 029: invalid expression, assumed zero
C:\Users\Maya\Desktop\gf_july21_2016.pwn(11602) : error 017: undefined symbol "Player"
Reply
#4

I just wrote this quickly. It's supposed to work:
Код:
IsPlayerNearWater(playerid)
{
    new
        Float:x, Float: y, Float: z, Float: a,
        Float: cX, Float: cY, Float: cZ;
    GetPlayerPos(playerid, x, y, z);

    while (a <= 360.0)
    {
        cX = x + (4.0 * floatsin(-a, degrees));
        cY = y + (4.0 * floatcos(-a, degrees));
        a += 90.0;

        MapAndreas_FindZ_For2DCoord(cX, cY, cZ);
        if(cZ == 0.0)
            return true;
    }
    return false;
}
Also, if you're using 0.3.7, you should use this for looping:
Код:
for (new i, j = GetPlayerPoolSize(); i <= j; i++)
And not the MAX_PLAYERS one. It's much better.
Reply
#5

Okay thanks alot both of you, rep +
Reply
#6

And, this
pawn Код:
for (new i, j = GetPlayerPoolSize(); i <= j; i++)
instead of this?
pawn Код:
for(new i=0; i<=MAX_PLAYERS; i++)
Reply
#7

Yes. If it doesn't work, it means the problem is in your timer, so show how you call it.
Reply
#8

Quote:
Originally Posted by Stinged
Посмотреть сообщение
Yes. If it doesn't work, it means the problem is in your timer, so show how you call it.
It works thanks alot.

I have another question, sometimes when i catch a fish, it says the weight for example -45Lbs
and sometimes 32Lbs, also it goes minus- How come?

pawn Код:
new Caught;
                    new Level = PlayerInfo[playerid][pFishSkill];
                    if(Level >= 0 && Level < 50) { Caught = random(20)-7; }
                    else if(Level >= 50 && Level < 100) { Caught = random(50)-20; }
                    else if(Level >= 100 && Level < 200) { Caught = random(100)-50; }
                    else if(Level >= 200 && Level < 400) { Caught = random(140)-60; }
                    else if(Level >= 400 && Level < 500) { Caught = random(170)-60; }
                    if(luck <= 70)
                    {
                        new string[85];
                        HidePlayerFishText(playerid);
                        PlayerInfo[playerid][pFishes] += 1;
                        PlayerInfo[playerid][pFishSkill] += 1;
                        format(fstring, sizeof(fstring), "%s", FishNames[rand]);
                        strmid(Fishes[playerid][pFish], fstring, 0, strlen(fstring), 255);
                        Fishes[playerid][pWeight4] = Caught;
                        format(string, sizeof(string), "* %s reels in a %s weighing %d lbs!", RemoveUnderScore(playerid), Fishes[playerid][pFish], Caught);
                        ProxDetector(30.0, playerid, string, COLOR_RED,COLOR_RED,COLOR_RED,COLOR_RED,COLOR_RED);
                        RemovePlayerAttachedObject(playerid,0);
                        KillTimer(fishtimer[playerid]);
                        FishCaught[playerid] = 0;
                        Fishing[playerid] = 0;
                        Fishes[playerid][pLastWeight] = Caught;
                        Fishes[playerid][pLastFish] = 4;
                        Fishes[playerid][pFid4] = rand;
                        Fishes[playerid][pFishID] = rand;
                        if(Caught > PlayerInfo[playerid][pBiggestFish])
                        {
                            format(string, sizeof(string), "* You've beaten your old record of %d pounds!  Your new biggest fish is: %d pounds.", PlayerInfo[playerid][pBiggestFish], Caught);
                            SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
                            PlayerInfo[playerid][pBiggestFish] = Caught;
                        }
                        return 1;
                    }
Reply
#9

Answer to your question (in your other topic)

@offtopic
I am just wondering about the usage of cos and sin in IsPlayerNearWater if you only check for North / East / South / West
Also if its a small loop you should unroll it for speed
PHP код:
IsPlayerNearWater(playerid) {
    const
        
FloatTHRESHOLD 20.0,
        
FloatRADIUS 4.0;
    new
        
Floatx,
        
Floaty,
        
Floatz;
    if(
GetPlayerPos(playeridxyz) && (-THRESHOLD THRESHOLD)) {
        
MapAndreas_FindZ_For2DCoord(xRADIUSz);
        if(
== 0.0) return true;
        
MapAndreas_FindZ_For2DCoord(RADIUSyz);
        if(
== 0.0) return true;
        
MapAndreas_FindZ_For2DCoord(xRADIUSz);
        if(
== 0.0) return true;
        
MapAndreas_FindZ_For2DCoord(RADIUSyz);
        if(
== 0.0) return true;
    }
    return 
false;

You should add a IsPlayerNearWater check in /fish if it isn't already there
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)