Problem with deleting a created object.
#1

Ok sup guys i've had some problems with this script and now it works nice but there is still a SMALL problem I can't figure out.

Here is how the script works:
1- You use /wheat plant and it creates a dynamic object and then set a timer
heres the script
PHP код:
CMD:wheat(playeridparams[])
{
    new 
string[128], wheatoldjnewj;
    if(
PlayerInfo[playerid][pJobSkill][JOB_FARMER] < 100wheat 5;
    else if(
PlayerInfo[playerid][pJobSkill][JOB_FARMER] < 300wheat 10;
    else if(
PlayerInfo[playerid][pJobSkill][JOB_FARMER] < 700wheat 15;
    else if(
PlayerInfo[playerid][pJobSkill][JOB_FARMER] < 1200wheat 20;
    else if(
PlayerInfo[playerid][pJobSkill][JOB_FARMER] >= 1200wheat 25;
       if(!
IsPlayerLoggedIn(playerid) || PlayerInfo[playerid][pAsshole] == 1) return SendClientMessage(playeridCOLOR_GREY"You are not allowed to use command.");
       if(
PlayerInfo[playerid][pJob] != JOB_FARMER && PlayerInfo[playerid][pVIPJob] != JOB_FARMER) return SendClientMessage(playeridCOLOR_GREY"You are not a Farmer.");
    new 
usage[10];
    if(
sscanf(params"s[10]"usage)) return SendClientMessage(playerid,COLOR_GREY,"USAGE: /wheat [plant] or [pick]");
    else
    {
        if(
strcmp(usage"plant"true) == 0)
        {
            if(
GetPlayerState(playerid) != PLAYER_STATE_ONFOOT) return SendClientMessage(playeridCOLOR_GREY"You must be standing on the ground to use this command.");
             if(
PlayerInfo[playerid][pSeeds] == 0) return SendClientMessage(playeridCOLOR_GREY"You must have seeds to plant wheat.");
              {
                new 
id plantcount;
                
GetPlayerPos(playerid,winfo[id][poswx],winfo[id][poswy],winfo[id][poswz]);
                
mariaobject[id] = CreateDynamicObject(806,winfo[id][poswx],winfo[id][poswy],winfo[id][poswz]-1,0.0,0.0,0.0,0);
                
ApplyAnimation(playerid,LIBRARY,ANIMATION,4.1,false,false,false,false,3000,false);
                
winfo[id][labelweed] = CreateDynamic3DTextLabel("On Harvest",0xFF0000FF,winfo[id][poswx],winfo[id][poswy],winfo[id][poswz],0);
                
WheatTime[playerid] = 10;
                
WheatCooldown[playerid] = SetTimerEx("harvesttimer"6000true"i"playerid);
                 
PlayerInfo[playerid][pSeeds] = 0;
                
SendClientMessage(playerid,COLOR_GREEN,"You have planted your seeds, it will now grow and be ready to /wheat pick in 10 minutes.");
                
plantcount++;
                
wlimit++;
            }
            return 
1;
        } 
And then you use /wheat pick and if the timer is at 0, it deletes the object ( it works ) but check this out


When I /wheat plant a second plant then /wheat pick I need to go at the first /wheat plant position ( so the first mariaobject[id] = CreateDynamicObject(806,winfo[id][poswx],winfo[id][poswy],winfo[id][poswz]-1,0.0,0.0,0.0,0); ever created or else it doesnt work...

I want to edit /wheat pick so that every time I use it it deletes completely the first mariaobject

Hope you understand, here is the /wheat pick code

PHP код:
if(strcmp(usage"pick"true) == 0)
        {
              {
                  for(new 
0MAX_WEEDi++)
                {
                    if(
IsPlayerInRangeOfPoint(playerid,2.5,winfo[i][poswx],winfo[i][poswy],winfo[i][poswz]-1))
                    {
                             if(
WheatTime[playerid] > 0)
                         {
                             
format(stringsizeof(string), "You need to wait %d more seconds before harvesting your wheat plantations."WheatTime[playerid]);
                              
SendClientMessage(playeridCOLOR_GREYstring);
                             return 
1;
                          }
                         if(
WheatTime[playerid] == 0)
                         {
                              if(
IsPlayerInVehicle(playerid,GetPlayerVehicleID(playerid))) return SendClientMessage(playerid,-1,"You have to be standing on the ground to harvest your wheat.");
                              
ApplyAnimation(playerid,LIBRARY,ANIMATION,4.1,false,false,false,false,3000,false);
                              
DestroyDynamicObject(mariaobject[i]);
                              
DestroyDynamic3DTextLabel(winfo[i][labelweed]);
                              
wlimit--;
                              
WheatTime[playerid] --;
                            
format(stringsizeof(string), "* You have harvested {FF6347}%d wheat{33CCFF} on your plantations."wheat*5);
                            
SendClientMessage(playeridCOLOR_LIGHTBLUEstring);
                        }
                        
PlayerInfo[playerid][pWheat] += wheat*5;
                        
oldj strval(RPJL(playerid,JOB_FARMER));
                        
PlayerInfo[playerid][pJobSkill][JOB_FARMER] ++;
                        
newj strval(RPJL(playerid,JOB_FARMER));
                        if(
oldj newj)
                        {
                            
format(stringsizeof(string), "** Your Farmer level is now %d, you can now harvest %d more pounds of wheat. **"newjnewj*5);
                            
SendClientMessage(playeridCOLOR_YELLOWstring);
                        }
                        return 
1;
                     }
                }
            }
        }
        return 
1;
    }

Thanks for ANY help comming in
Reply
#2

Nevermind I corrected it. Simple mistake ( Removed the [i] )
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)