Object problem
#2

Here's the new code.

pawn Код:
new bool:cHarvest[MAX_PLAYERS] = false;
new PlantObject[MAX_PLAYERS]; // We will save the object onto this variable.

timer cWait[6000](playerid)
{
    cHarvest[playerid] = true;
    SendClientMessage(playerid,COLOR_RED,"Plant ready!");
}

CMD:plant(playerid, params[])
{
    if(pInfo[playerid][Seeds] > 2)
    {
            new Float:x,Float:y,Float:z;
            GetPlayerPos(playerid,x,y,z);
            PlantObject[playerid] = CreateObject(19473,x,y,z-2,0,0,0); // By doing this, you save the object onto this variable. We will use this to destroy the object later.
            pInfo[playerid][Seeds]-=3;
            SendClientMessage(playerid,COLOR_GRAY,"Your plant will be ready in six seconds.");
            defer cWait(playerid);
    }
    else SendClientMessage(playerid,COLOR_RED,"You don't have enough seeds!");
    return 1;
}

CMD:harvest(playerid, params[])
{
    // new Float:x,Float:y,Float:z;
    // GetObjectPos(19473,x,y,z);
    // if(IsPlayerInRangeOfPoint(playerid,7,x,y,z))
    //{
    if(cHarvest[playerid])
    {
         //DestroyObject(19473);
         DestroyObject(PlantObject[playerid]); // After you use /harvest it should delete the object the player created.
         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!");
    //}
    return 1;
}
EDIT: This will only work if you only use /plant once. If you use /plant again it will assign PlantObject to the new object, which will cause problems.

EDIT2: I have updated the script so the player won't be able to plant another plant if has already planted one.
pawn Код:
new bool:cHarvest[MAX_PLAYERS] = false;
new PlantObject[MAX_PLAYERS][5]; // We will save the object onto this variable.
new PlantsPlanted[MAX_PLAYERS]; // We will use this variable to see if the player has a plant planted already.

timer cWait[6000](playerid)
{
    cHarvest[playerid] = true;
    SendClientMessage(playerid,COLOR_RED,"Plant ready!");
}

CMD:plant(playerid, params[])
{
    if(pInfo[playerid][Seeds] > 2)
    {
        if(PlantsPlanted[playerid] == 0) // If the player doesn't have a plant planted yet, the object will appear.
        {
            new Float:x,Float:y,Float:z;
            GetPlayerPos(playerid,x,y,z);
            PlantObject[playerid] = CreateObject(19473,x,y,z-2,0,0,0); // By doing this, you save the object onto this variable. We will use this to destroy the object later.
            pInfo[playerid][Seeds]-=3;
            SendClientMessage(playerid,COLOR_GRAY,"Your plant will be ready in six seconds.");
            PlantsPlanted[playerid] = 1; // Sets the variable to 1, so the player won't be able to plant a new object.
            defer cWait(playerid);
        }
        else return SendClientMessage(playerid, COLOR_RED, "You have already planted a plant."); // If the player has a plant planted already, he will get an error message.
    }
    else SendClientMessage(playerid,COLOR_RED,"You don't have enough seeds!");
    return 1;
}

CMD:harvest(playerid, params[])
{
    // new Float:x,Float:y,Float:z;
    // GetObjectPos(19473,x,y,z);
    // if(IsPlayerInRangeOfPoint(playerid,7,x,y,z))
    //{
    if(cHarvest[playerid])
    {
         //DestroyObject(19473);
         DestroyObject(PlantObject[playerid]); // After you use /harvest it should delete the object the player created.
         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!");
    //}
    return 1;
}
If you want I can rescript the system so the player is able to plant more than one plant at a time.
Reply


Messages In This Thread
Object problem - by Noles2197 - 14.02.2013, 23:10
Re: Object problem - by JJB562 - 15.02.2013, 00:55

Forum Jump:


Users browsing this thread: 1 Guest(s)