Weed system problem
#1

When a player does /harvest after the six second timer is up, it harvests the weed (destroys object), but doesn't give and "pInfo[playerid][Weed]" and says, "This isn't ready yet".
Can someone help?

pawn Код:
#define MAX_WEED 25

enum WeedInfo
{
    Float:Xpos,
    Float:Ypos,
    Float:Zpos,
    Planter,
    Created,
    Ready,
    Plant,
}

new wInfo[MAX_WEED][WeedInfo];
new planted[MAX_PLAYERS];

stock CreatePlant(playerid,Float:x,Float:y,Float:z)
{
    for(new i = 0; i < sizeof(wInfo); i++)
    {
        if(wInfo[i][Created] == 0)
        {
            wInfo[i][Created]=1;
            wInfo[i][Ready] = 0;
            wInfo[i][Planter]=playerid;
            wInfo[i][Xpos]=x;
            wInfo[i][Ypos]=y;
            wInfo[i][Zpos]=z;
            wInfo[i][Plant] = CreateObject(19473,x,y,z-2,0,0,0);
            defer cWait(i);
            return 1;
        }
    }
    return 0;
}


stock GetPlanter(playerid)
{
    new id;
    for(new i = 0; i < sizeof(wInfo); i++)
    {
        if(IsPlayerInRangeOfPoint(playerid,1,wInfo[i][Xpos],wInfo[i][Ypos],wInfo[i][Zpos]))
        {
            if(wInfo[i][Created] == 1)
            {
                id = wInfo[i][Planter];
                return id;
            }
        }
    }
    return 0;
}

stock GetPlant(playerid)
{
    for(new i = 0; i < sizeof(wInfo); i++)
    {
        if(IsPlayerInRangeOfPoint(playerid,1,wInfo[i][Xpos],wInfo[i][Ypos],wInfo[i][Zpos]))
        {
            if(wInfo[i][Created] == 1)
            {
                wInfo[i][Created]=0;
                wInfo[i][Planter]=-1;
                wInfo[i][Ready] = 0;
                wInfo[i][Xpos]=0;
                wInfo[i][Ypos]=0;
                wInfo[i][Zpos]=0;
                DestroyObject(wInfo[i][Plant]);
                return 1;
            }
        }
    }
    return 0;
}



stock IsReady(playerid)
{
    for(new i = 0; i < sizeof(wInfo); i++)
    {
        if(IsPlayerInRangeOfPoint(playerid,1,wInfo[i][Xpos],wInfo[i][Ypos],wInfo[i][Zpos]))
        {
            if(wInfo[i][Created] == 1)
            {
                if(wInfo[i][Ready] == 1)
                {
                        return true;
                }
            }
        }
    }
    return false;
}

CMD:plant(playerid,params[])
{
    if(pInfo[playerid][Seeds] > 2)
    {
        if(!IsPlayerInAnyVehicle(playerid))
        {
            if(pInfo[playerid][Donator]==1)
            {
                if(planted[playerid] <= 5)
                {
                    new Float:x,Float:y,Float:z;
                    GetPlayerPos(playerid,x,y,z);
                    CreatePlant(playerid,x,y,z);
                    SendClientMessage(playerid,COLOR_GRAY,"Your plant will be ready in six seconds."); // adjust time
                    pInfo[playerid][Seeds]-=3;
                    planted[playerid]++;
                }
                else SendClientMessage(playerid,COLOR_RED,"You've already planted five!");
            }
            else
            {
                if(planted[playerid] == 0)
                {
                    new Float:x,Float:y,Float:z;
                    GetPlayerPos(playerid,x,y,z);
                    CreatePlant(playerid,x,y,z);
                    SendClientMessage(playerid,COLOR_GRAY,"Your plant will be ready in six seconds."); // adjust time
                    pInfo[playerid][Seeds]-=3;
                    planted[playerid]++;
                }
                else SendClientMessage(playerid,COLOR_RED,"You've already planted!");
            }
        }
        else SendClientMessage(playerid,COLOR_RED,"You're in a vehicle!");
    }
    else SendClientMessage(playerid,COLOR_RED,"You don't have enough seeds!");
    return 1;
}

CMD:harvest(playerid, params[])
{
    if(!IsPlayerInAnyVehicle(playerid))
    {
        if(GetPlant(playerid))
        {
            if(IsReady(playerid))
            {
                GetPlant(playerid);
                planted[GetPlanter(playerid)]--;
                pInfo[playerid][Weed]+=9;
                SendClientMessage(playerid,COLOR_GRAY,"You've harvested nine grams of weed.");
            }
            else SendClientMessage(playerid, COLOR_RED, "This isn't ready yet!");
        }
        else SendClientMessage(playerid, COLOR_RED, "You're not near a plant!");
    }
    else SendClientMessage(playerid,COLOR_RED,"You're in a vehicle!");
    return 1;
}
Reply
#2

Try to switch this two functions in /harvest.
The problem is that GetPlant is called first, but that function is resetting all the variables and destroys the object.
IsReady checks if there is a plant, but there isn't any plant ready, because you reset that 'ready' variable in GetPlant();

So this:
pawn Код:
if(GetPlant(playerid))
        {
            if(IsReady(playerid))
            {
Needs to be:
pawn Код:
if(IsReady(playerid))
        {
            if(GetPlant(playerid))
            {
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)