[Help] Planting weed function.
#1

Concept: Allow someone to /plant, this will allow a weed plant to grow until it has grown enough to /pickplant where you are rewarded drugs and the plants disappear.

My Issues:

1. The plant skips growth process and jumps out of the initial position into what should be the final

2. Cannot plant more then one plant, because it only registers the first. ( shows up, but doesn't grow and isn't pickable)

My include.
pawn Код:
#define MAX_WEEDPLANTS 250

enum plantInfo
{
    wpCreated,
    Float:wpX,
    Float:wpY,
    Float:wpZ,
    wp,
    grow,
    done,
};

new WeedInfo[MAX_WEEDPLANTS][plantInfo];

stock CreateWeed(Float:X,Float:Y,Float:Z)
{
    for(new i = 0; i < sizeof(WeedInfo); i++)
    {
        if(WeedInfo[i][wpCreated] == 0)
        {
            WeedInfo[i][wpCreated]=1;
            WeedInfo[i][wpX]=X;
            WeedInfo[i][wpY]=Y;
            WeedInfo[i][wpZ]=Z;
            WeedInfo[i][wp] = CreateDynamicObject(3409, X, Y, Z-2, 0, 0, 0);
            return 1;
        }
    }
    return 0;
}

stock DeleteAllWeed()
{
    for(new i = 0; i <sizeof(WeedInfo); i++)
    {
        if(WeedInfo[i][wpCreated] == 1)
        {
            WeedInfo[i][wpCreated]=0;
            WeedInfo[i][wpX]=0.0;
            WeedInfo[i][wpY]=0.0;
            WeedInfo[i][wpZ]=0.0;
            DestroyDynamicObject(WeedInfo[i][wp]);
        }
    }
    return 1;
}

stock DeleteWeed(playerid)
{
    for(new i = 0; i < sizeof(WeedInfo); i++)
    {
        if(IsPlayerInRangeOfPoint(playerid, 4.0, WeedInfo[i][wpX],WeedInfo[i][wpY],WeedInfo[i][wpZ]))
        {
            if(WeedInfo[i][wpCreated] == 1)
            {
                DestroyDynamicObject(WeedInfo[i][wp]);
                WeedInfo[i][wpCreated]=0;
                WeedInfo[i][wpX]=0.0;
                WeedInfo[i][wpY]=0.0;
                WeedInfo[i][wpZ]=0.0;
                DestroyDynamicObject(WeedInfo[i][wp]);
                return 1;
            }
        }
    }
    return 0;
}

#define COLOR_WEED 0x42912BFF

stock GrowWeed(playerid)
{
    new string[128];
    for(new i = 0; i < sizeof(WeedInfo); i++)
    {
        //if(IsPlayerInRangeOfPoint(playerid, 3.0, WeedInfo[i][wpX], WeedInfo[i][wpY], WeedInfo[i][wpZ]))
        //{
            if(WeedInfo[i][wpCreated] == 1)
            {
                MoveDynamicObject(WeedInfo[i][wp],WeedInfo[i][wpX], WeedInfo[i][wpY], WeedInfo[i][wpZ]+0.2, 2);
                //format(string,sizeof(string),"The Weed Has Grown.");
                //ProxDetector(30.0, playerid, string, COLOR_WEED,COLOR_WEED,COLOR_WEED,COLOR_WEED,COLOR_WEED);
                return 1;
            }
        //}
    }
    return 0;
}
The Commands/Timers

pawn Код:
new growtimer[MAX_WEEDPLANTS];
forward WeedTimer(playerid);
forward wpdrawhide(playerid);
forward wpdrawhide2(playerid);


    if(strcmp(cmd, "/plant", true) == 0)
    {
        for(new i = 0; i < sizeof(WeedInfo); i++)
        {
            new Float:X, Float:Y, Float:Z;
            GetPlayerPos(playerid, X, Y, Z);
            //if(PlayerInfo[playerid][pWeed] >= 1)
            //{
            SendClientMessage(playerid, COLOR_CHAT1,"You begin to plant some weed.");
            CreateWeed(X,Y,Z);
            growtimer[i] = SetTimer("WeedTimer", 60000, 1);
            return 1;
            //}
        }
    }
    if(strcmp(cmd, "/pickplant", true) == 0)
    {
        for(new i = 0; i < sizeof(WeedInfo); i++)
        {
            if(IsPlayerInRangeOfPoint(playerid,4.0,WeedInfo[i][wpX],WeedInfo[i][wpY],WeedInfo[i][wpZ]))
            {
                if(WeedInfo[i][done] == 1)
                {
                    DeleteWeed(playerid);
                    KillTimer(growtimer[i]);
                    PlayerInfo[playerid][pDrugs] += 5;
                    SendClientMessage(playerid, COLOR_WEED,"Drugs picked.");
                    return 1;
                }
                else
                {
                    SendClientMessage(playerid, COLOR_WEED,"Dude, you're not near any drugs.");
                    return 1;
                }
            }
        }
    }


public WeedTimer(playerid)
{
    for(new i = 0; i < sizeof(WeedInfo); i++)
    {
        if(WeedInfo[i][grow] >= 4)
        {
            SendClientMessage(playerid, COLOR_WEED," Your weed is grown completely, /pickplant");
            TextDrawShowForPlayer(playerid, Textdraw100);
            WeedInfo[i][done] = 1;
            SetTimer("wpdrawhide2", 15000, 0);
            return 1;
        }
        else
        {
            TextDrawShowForPlayer(playerid, Textdraw99);
            WeedInfo[i][grow] += 1;
            GrowWeed(playerid);
            SetTimer("wpdrawhide", 10000, 0);
        }
    }
    return 1;
}

public wpdrawhide(playerid)
{
    TextDrawHideForPlayer(playerid, Textdraw99);
    return 1;
}

public wpdrawhide2(playerid)
{
    TextDrawHideForPlayer(playerid, Textdraw100);
    return 1;
}
It's an awesome idea, and I've worked pretty hard on this now, so if anyone knows how I can fix this up, or
guide me to how, I'd be a happy guy.
Reply


Messages In This Thread
[Help] Planting weed function. - by Ace_Menace - 21.07.2010, 13:41
Re: [Help] Planting weed function. - by Kar - 21.07.2010, 13:43

Forum Jump:


Users browsing this thread: 1 Guest(s)