growing pot command help
#1

i am using the united roleplay script for my gomemode and i want to set it so i can grow more then 1 plant at a time can someone help me out with this or tell me how to fix it

PHP код:
if(strcmp(cmd,"/plantweed",true)==0)
    {
        if(
IsPlayerConnected(playerid))
        {
         if (
PlayerInfo[playerid][pJob] != 4)
            {
                
SendClientMessage(playerid,COLOR_GREY"You are not a Drug Dealer !");
                return 
1;
            }
            new 
name[MAX_PLAYER_NAME];
            
GetPlayerName(playeridnamesizeof(name));
            if(
GetPlayerState(playerid) != 1) return SendClientMessage(playeridCOLOR_GREY"   You must be on foot !");
            if(
GetPlayerInterior(playerid) > 0) return SendClientMessage(playeridCOLOR_GREY"   You must be outside to plant your seeds.");
            if(
PlayerInfo[playerid][pSeeds] == 0) return SendClientMessage(playeridCOLOR_GREY"   You don't have any Seeds!");
            if(
PlayerInfo[playerid][pSeeds] < 10) return SendClientMessage(playeridCOLOR_GREY"   You don't have enough Seeds!");
            if(
HasPlantWeed[playerid] == 1) return SendClientMessage(playeridCOLOR_GRAD2"* You have already planted a weed !");
            new 
Float:XFloat:YFloat:Z;
            
ApplyAnimation(playerid"BOMBER""BOM_Plant"4.000000);
            
GetPlayerPos(playeridXYZ);
            
Weed_x[playerid] = X;
            
Weed_y[playerid] = Y;
            
Weed_z[playerid] = Z;
            
Weed[playerid] = CreateDynamicObject(3409XYZ-1.8000);
            
HasPlantWeed[playerid] = 1;
            
PlayerInfo[playerid][pSeeds] -= 10;
            
format(stringsizeof(string), "* %s plants some seeds."name);
            
ProxDetector(30.0playeridstringCOLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
            
SendClientMessage(playeridCOLOR_GREEN"You have planted your seeds! Every minute, your plant will make one gram of weed.");
            
SendClientMessage(playeridCOLOR_GREEN"If your plant won't picked within 70 minutes, it will rot and you will lose it.");
            
SendClientMessage(playeridCOLOR_GREEN"Also remember that anyone can /pickweed if they find your plant, so be careful.");
        }
        return 
1;
    } 
Reply
#2

Change a variable or add a variable that will hold the number of plants.Increment it when player plants and decrements when he harvests.

SO before planting, check if(PlayerInfo[playerid][PlantedSeed]) //Depends on ur enum and then display a message
Reply
#3

pawn Код:
if(strcmp(cmd,"/plantweed",true)==0)
    {
        if(IsPlayerConnected(playerid))
Obviously the player is connected if typing the command useless check here.

Anyways the main problem is in these lines

Код:
         if(HasPlantWeed[playerid] == 1) return SendClientMessage(playerid, COLOR_GRAD2, "* You have already planted a weed !"); 
            new Float:X, Float:Y, Float:Z; 
            ApplyAnimation(playerid, "BOMBER", "BOM_Plant", 4.0, 0, 0, 0, 0, 0); 
            GetPlayerPos(playerid, X, Y, Z); 
            Weed_x[playerid] = X; 
            Weed_y[playerid] = Y; 
            Weed_z[playerid] = Z; 
            Weed[playerid] = CreateDynamicObject(3409, X, Y, Z-1.8, 0, 0, 0); 
            HasPlantWeed[playerid] = 1;
Basically it's only set up to grow one weed plant so your going to need to make some modifications to get this to work, firstly you'll need to setup a proper enum to make life easier .

pawn Код:
#define MAX_WEED_PLANTS 5
#define WEED_Z_OFFSET -1.8

enum WEEDENUM {
     WeedObj[MAX_WEED_PLANTS],
     Float:Weed_x[MAX_WEED_PLANTS],
     Float:Weed_y[MAX_WEED_PLANTS],
     Float:Weed_z[MAX_WEED_PLANTS]
}

new WeedData[MAX_PLAYERS][WEEDENUM]
Ok so now we have our data set up we need to initialize the objectid's to default values in OnGameModeInit() which wouldn't be 0

pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++)
{
    for(new j = 0; j < MAX_WEED_PLANTS; j++)  { WeedData[i][WeedObj][j] = INVALID_OBJECT_ID; }
}
So now for adding a plants your going to want to make a new function for this

pawn Код:
AddWeedPlant(playerid)
{
    // Find a open plant slot
    for(new i = 0; i < MAX_WEED_PLANTS; i++)
    {
         if(WeedData[playerid][WeedObj][i] == INVALID_OBJECT_ID)
         {
            ApplyAnimation(playerid, "BOMBER", "BOM_Plant", 4.0, 0, 0, 0, 0, 0);
            GetPlayerPos(playerid, WeedData[playerid][Weed_x], WeedData[playerid][Weed_y], WeedData[playerid][Weed_z]);
            WeedData[playerid][Weed_z] += WEED_Z_OFFSET;
            Weed[playerid] = CreateDynamicObject(3409, WeedData[playerid][Weed_x], WeedData[playerid][Weed_y], WeedData[playerid][Weed_z], 0, 0, 0);
            return 1;
         }
    }
    return 0;
}
pawn Код:
DestroyWeedPlant(playerid, index)
{
    if(WeedData[playerid][WeedObj][i] != INVALID_OBJECT_ID)
    {
        DestroyDynamicObject(WeedData[playerid][WeedObj][i]);
        WeedData[playerid][WeedObj][i] = INVALID_OBJECT_ID;
        return 1;
    }
    return 0;
}
So now modify your command

pawn Код:
if(strcmp(cmd,"/plantweed",true)==0)
{
    if (PlayerInfo[playerid][pJob] != 4) return SendClientMessage(playerid,COLOR_GREY, "You are not a Drug Dealer !");
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    if(GetPlayerState(playerid) != 1) return SendClientMessage(playerid, COLOR_GREY, "   You must be on foot !");
    if(GetPlayerInterior(playerid) > 0) return SendClientMessage(playerid, COLOR_GREY, "   You must be outside to plant your seeds.");
    if(PlayerInfo[playerid][pSeeds] == 0) return SendClientMessage(playerid, COLOR_GREY, "   You don't have any Seeds!");
    if(PlayerInfo[playerid][pSeeds] < 10) return SendClientMessage(playerid, COLOR_GREY, "   You don't have enough Seeds!");
    if(!AddWeedPlant(playerid)) return SendClientMessage(playerid, COLOR_GRAD2, "* You have the maximum plants planted !");
    PlayerIfo[playerid][pSeeds] -= 10;
    format(string, sizeof(string), "* %s plants some seeds.", name);
    ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
    SendClientMessage(playerid, COLOR_GREEN, "You have planted your seeds! Every minute, your plant will make one gram of weed.");
    SendClientMessage(playerid, COLOR_GREEN, "If your plant won't picked within 70 minutes, it will rot and you will lose it.");
    SendClientMessage(playerid, COLOR_GREEN, "Also remember that anyone can /pickweed if they find your plant, so be careful.");
    return 1;
}
Remember other commands like /pickweed will need to be updated, you need to take into account when a player disconnects saving the data. There is still probably a bunch more to update but hopefully this sets you on the right direction.
Reply
#4

pawn Код:
if(HasPlantWeed[playerid] == 1) return SendClientMessage(playerid, COLOR_GRAD2, "* You have already planted a weed !");
Change the '1' to the number you want.

Then change
pawn Код:
HasPlantWeed[playerid] = 1;
To

pawn Код:
HasPlantedWeed[playerid]++;
Reply
#5

No isolated, read my post there is a lot more to it than just that and I still didn't cover everything only the fundamental dynamics.
Reply
#6

Quote:

Remember other commands like /pickweed will need to be updated, you need to take into account when a player disconnects saving the data. There is still probably a bunch more to update but hopefully this sets you on the right direction.

if i attempt to add this command in it will make it so i can plant more then 1 plant so i can grow like 20 plants?
Reply
#7

If you do it right you would be able to set it to 1000 plants if you want
Reply
#8

the script i am using is way diffrent there is no max weed plants define
Reply
#9

OK i got it but it grows like 10 plants but i cant pick any of them only 1
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)