Drug harvesting help
#1

Hi guys,
so i made a drug system wich a player can plant several plants at a time and it works good at planting. Problem is when i try to harvest them i can only harvest the last one i planted. It just doesnt find others its like if it wasnt even setting their X Y Z pos variables. Could you guys help me? Ill leave the code here:

PHP код:
enum drogasinfo
{
    
semente,
    
Float:sementeposX,
    
Float:sementeposY,
    
Float:sementeposZ,
    
drogacolher,
    
sementecrescimento
};
new 
DrugInfo[200][drogasinfo]; 
PHP код:
if(strcmp(cmd,"/sementes"true) == 0)
        {
            new 
x_nr[256];
            
x_nr strtok(cmdtextidx);
            if(!
strlen(x_nr)) {
                
SendClientMessage(playeridCOLOR_LIGHTRED,"{ADFF2F}[Comando]: {FFFFFF} /sementes [Comandos]");
                
SendClientMessage(playeridCOLOR_LIGHTRED,"{ADFF2F}[Comando]: {FFFFFF} plantar, colher");
                return 
1;
            }
            if(
strcmp(x_nr,"plantar",true) == 0)
            {
                if(
IsPlayerConnected(playerid))
                {
                    if(
PlayerInfo[playerid][pFaction] == || PlayerInfo[playerid][pFaction] == 8)
                    {
                        if(
PlayerInfo[playerid][pSementes] > 0)
                        {
                            for(new 
0;c<sizeof(DrugInfo);c++)
                            {
                                if(
DrugInfo[c][sementecrescimento] == 0)
                                {
                                new 
Float:x;
                                new 
Float:y;
                                new 
Float:z;
                                
ApplyAnimation(playerid"BOMBER","BOM_Plant_In",4.0,0,0,0,0,0);
                                
ApplyAnimation(playerid"BOMBER","BOM_Plant_In",4.0,0,0,0,0,0);
                                
GetPlayerPos(playeridxyz);
                                
DrugInfo[c][semente] = CreateDynamicObject(809xyz-1.00000);
                                
DrugInfo[c][sementeposX] = x;
                                
DrugInfo[c][sementeposY] = y;
                                
DrugInfo[c][sementeposZ] = z-1.0;
                                
DrugInfo[c][drogacolher] = 0;
                                
PlayerInfo[playerid][pSementes] -= 1;
                                
SetTimerEx("crescer"10000false"ii"playerid,c);
                                
SendClientMessage(playeridCOLOR_WHITE"[Info] Plantas-te uma semente de cocaina. Terбs que esperar algum tempo antes de a colher.");
                                return 
1;
                                }
                            }
                            return 
1;
                        }
                        else
                        {
                        
SendClientMessage(playeridCOLOR_RED"[Erro]: Nao tens sementes suficientes!");
                        return 
1;
                        }
                    }
                    else
                    {
                    
SendClientMessage(playeridCOLOR_RED"[Erro]: Nao pertences а faction que trafica drogas");
                    return 
1;
                    }
                }
            }
            else if(
strcmp(x_nr,"colher",true) == 0)
            {
                if(
PlayerInfo[playerid][pFaction] == || PlayerInfo[playerid][pFaction] == 8)
                {
                        for(new 
0sizeof(DrugInfo); c++)
                           {
                               if(
IsPlayerInRangeOfPoint(playerid3.0DrugInfo[c][sementeposX], DrugInfo[c][sementeposY], DrugInfo[c][sementeposZ]))
                            {
                                if(
DrugInfo[c][drogacolher] == 1)
                                {
                                    
ApplyAnimation(playerid"BOMBER","BOM_Plant_In",4.0,0,0,0,0,0);
                                    
DrugInfo[c][drogacolher] = 0;
                                    
DestroyDynamicObject(DrugInfo[c][semente]);
                                    
DrugInfo[c][sementecrescimento] = 0;
                                    
DrugsHolding[playerid] += 5;
                                    
SendClientMessage(playeridCOLOR_WHITE"[Info]: Colheste a tua planta. Agora para a transformares tens que a entregar ao teu trabalhador.");
                                    return 
1;
                                }
                                else
                                {
                                
SendClientMessage(playeridCOLOR_RED"[Erro]: A planta ainda nao cresceu! Espera mais tempo.");
                                return 
1;
                                }
                            
                            }
                            else
                            {
                            
SendClientMessage(playeridCOLOR_RED"[Erro]: Nao estas perto de nenhuma planta de cocaina!");
                            return 
1;
                            }
                        }
                    
                }
                else
                {
                
SendClientMessage(playeridCOLOR_RED"[Erro]: Nao pertences a faction que vende drogas!");
                return 
1;
                }
            }
            else
            {
                
SendClientMessage(playeridCOLOR_RED,"{FF0000}[Erro]: {FFFFFF}Comando Invalido.");
                return 
1;
            }
            return 
1;
        } 
PHP код:
forward crescer(playerid,c);
public 
crescer(playerid,c)
{
    
DrugInfo[c][drogacolher] = 1;

Reply
#2

can anyone help me?
Reply
#3

You forgot to set "DrugInfo[c][sementecrescimento]" to something different than 0 in the first for loop
Therefore it always overwrites the first index with c = 0
Reply
#4

but the "sementecrescimento" thing is to check if the seed id is on use. So i should only make it different from 0 if it is on use.
Reply
#5

any ideas to fix this?
Reply
#6

Quote:
Originally Posted by GunZsmd
Посмотреть сообщение
but the "sementecrescimento" thing is to check if the seed id is on use. So i should only make it different from 0 if it is on use.
In use means that the seed exists right?, than you need to set it to something different
Just add right after the if statment something like that
PHP код:
                                if(DrugInfo[c][sementecrescimento] == 0)
                                {
                                    
DrugInfo[c][sementecrescimento] = 1// for example = 1 
Reply
#7

ok now i can only pick up the first one that i planted. Others that are created after that cant be picked.
Reply
#8

Quote:
Originally Posted by GunZsmd
Посмотреть сообщение
ok now i can only pick up the first one that i planted. Others that are created after that cant be picked.
Thats because you put ridiculous many returns in your command
And one return stops the whole for loops, therefore only the first one worked
Moved the wrong return and message outside the loop
PHP код:
else if(strcmp(x_nr,"colher",true) == 0)
{
    if(
PlayerInfo[playerid][pFaction] == || PlayerInfo[playerid][pFaction] == 8)
    {
        for(new 
0sizeof(DrugInfo); c++)
        {
            if(
IsPlayerInRangeOfPoint(playerid3.0DrugInfo[c][sementeposX], DrugInfo[c][sementeposY], DrugInfo[c][sementeposZ]))
            {
                if(
DrugInfo[c][drogacolher] == 1)
                {
                    
ApplyAnimation(playerid"BOMBER","BOM_Plant_In",4.0,0,0,0,0,0);
                    
DrugInfo[c][drogacolher] = 0;
                    
DestroyDynamicObject(DrugInfo[c][semente]);
                    
DrugInfo[c][sementecrescimento] = 0;
                    
DrugsHolding[playerid] += 5;
                    return 
SendClientMessage(playeridCOLOR_WHITE"[Info]: Colheste a tua planta. Agora para a transformares tens que a entregar ao teu trabalhador.");
                }
                return 
SendClientMessage(playeridCOLOR_RED"[Erro]: A planta ainda nao cresceu! Espera mais tempo.");
            }
        } 
// this \/ message was inside the loop, should be here
        
return SendClientMessage(playeridCOLOR_RED"[Erro]: Nao estas perto de nenhuma planta de cocaina!");
    }
    return 
SendClientMessage(playeridCOLOR_RED"[Erro]: Nao pertences a faction que vende drogas!");

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)