Destroying a certain object
#1

Hello,im trying to create a drug system. The point of it is it creates a global object after player /plant it.And the command /harvest should destroy it and give drugs.But it doesn't destroy it,nor give drugs. Here's the command:
pawn Code:
CMD:harvest(playerid,params[])
{
    new Float:x,Float:y,Float:z;
    GetObjectPos(3409,x,y,z);
    if(IsPlayerInRangeOfPoint(playerid,5,x,y,z))
    {
        new rand = random(5);
        DestroyObject(3409);
        PlayerInfo[playerid][Marijuana]=PlayerInfo[playerid][Marijuana] + rand;
        SaveStats(playerid);
    }
    return 1;
}
Reply
#2

Then the object ID is a fail,try to define the Object ID instead of putting the actual ID
E.G:
pawn Code:
new DrugObject;
pawn Code:
CMD:plant(playerid,params[])
{
//bla bla the code
DrugObject = CreateObjet(//the object
return 1;
}
Then the harvest becomes
pawn Code:
CMD:harvest(playerid,params[])
{
    new Float:x,Float:y,Float:z;
    GetObjectPos(3409,x,y,z);
    if(IsPlayerInRangeOfPoint(playerid,5,x,y,z))
    {
        new rand = random(5);
        DestroyObject(DrugObject);
        PlayerInfo[playerid][Marijuana]=PlayerInfo[playerid][Marijuana] + rand;
        SaveStats(playerid);
    }
    return 1;
}
Reply
#3

i thought that might be the problem. But in this case, wont everyones objects get destroyed after one player types it?
Reply
#4

Then use a player variable
pawn Code:
new DrugObject[MAX_PLAYERS];
pawn Code:
CMD:plant(playerid,params[])
{
//bla bla the code
DrugObject[playerid] = CreateObjet(//the object
return 1;
}
pawn Code:
CMD:harvest(playerid,params[])
{
    new Float:x,Float:y,Float:z;
    GetObjectPos(DrugObject[playerid],x,y,z);
    if(IsPlayerInRangeOfPoint(playerid,5,x,y,z))
    {
        new rand = random(5);
        DestroyObject(DrugObject[playerid]);
        PlayerInfo[playerid][Marijuana]=PlayerInfo[playerid][Marijuana] + rand;
        SaveStats(playerid);
    }
    return 1;
}
Reply
#5

Thanks for that BUT, what if i plant multiple trees? then i can only harvest the last one planted.
Reply
#6

Then make an array
pawn Code:
new DrugObject[MAX_PLAYERS][10];
Then it will be
pawn Code:
CMD:plant(playerid,params[])
{
//bla bla the code
DrugObject[playerid][0] = CreateObjet(//the object
DrugObject[playerid][1] = CreateObjet(//the object2
return 1;
}
Reply
#7

I'm still able only to destroy the last planted
Reply
#8

You want to destroy all planted weed at the same time?
Reply
#9

I want to destroy the that im near.

edit: the question would be,how do i get the position of a certain drug plant. Because GetObjectPos and then IsPlayerInRangeOfPoint is pretty annoying.Or is there no other way?
Reply
#10

instead assigning multiple plantids to each playerid[][], why not assign ONE playerid to any planted seed?
instead of:
Code:
PlantID[playerid][0]=CreateObject(blabla..
...with the issue of multiple plants (those [0], [1] etc in the player-plant array), you can do this:
Code:
new PlantID=CreateObject(blabla..
PlantedByPlayerID[PlantID]=playerid;
pay attention to the new PlantID, the "new" is there for a reason. the (returned) PlantID is only required once: as pointer into the PlantedByPlayerID cell.
doing it this way, you dont need to worry about checking if a player plant [0], [1], [2], (or more plant-slots) are free for planting.
the only little downside is the requirement for a sort-of-big array for holding like 10000 playerid's, pointed by each single plant.
to avoid the need for checking 10000 plants to find the closest plant to a player, you can spawn a pickup below each plant, and store the PlantID (same as the returned value above) into the pickup array the same way.

if you're done, your plant script can:
-handle (almost) unlimited amount of plants (per player too, since they all share the same plants array),
-avoid loops and timers. no closest plant-check, no counting for free plantslots etc.

trading a few KBytes RAM (10000 plant-integer-object-ids plus the same for invisible pickups linking to the plants) for using no loops&timers at all, seems to be a good deal. the more plants you intent to use, the more speedup advantages over other plant scripts you'll notice. for free.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)