Harvest Hemp Script Help

bubba752

New Member
Hello I'm new to this, so I hope I do this right.

I run a server with a hemp field so you can harvest the weed and then sell it at a trader. The only problem is that the weed plants (fiberplants) don't get destroyed once someone harvests them. Therefor a player can infinetly harvest from one plant. This is a problem, because it allows them to make WAYYYY too much gold from it.

Here is what my script looks like:
Code:
_countHemp = count nearestObjects [player, ["fiberplant"], 5];

if (_countHemp > 0) then {
cutText [format["Start harvesting....."], "PLAIN DOWN"];
player removeWeapon "ItemMachete";
player playActionNow "Medic";
sleep 5;
player addMagazine "ItemKiloHemp";
player addWeapon "ItemMachete";
cutText [format["Finished harvesting! , 2 kilo hemp has been added in your inventory!"], "PLAIN DOWN"];
} else {
cutText [format["You are not close enough to a hemp plant!"], "PLAIN DOWN"];
};

And here is what I've been attempting to do to set a damage value on the hemp to be destroyed once they harvest it:
Code:
_countHemp = count nearestObjects [player,["fiberplant"],5];_Hemp= nearestObjects [player,["fiberplant"],5];if(_countHemp >0)then{
cutText [format["Start harvesting....."],"PLAIN DOWN"];
player removeWeapon "ItemMachete";
player playActionNow "Medic";
sleep 5;
player addMagazine "ItemKiloHemp";
player addWeapon "ItemMachete";
cutText [format["Finished harvesting! A kilo of hemp has been added to your inventory!"],"PLAIN DOWN"];
sleep 1;_Hemp setDamage 1;};}else{
cutText [format["You are not close enough to a hemp plant!"],"PLAIN DOWN"];};

I am not sure what I am doing wrong. Any help would be much appreciated.
 
"_Hemp= nearestObjects" always returns an array of Objects.
Try
Code:
_Hemp = nearestObjects [player,["fiberplant"],5];
_countHemp = count _Hemp;
...

(_Hemp select 0) setDamage 1;
ps.: one call of nearestObjects should be enough, two calls with the same conditions makes no sense. once is enough and is better for server performance

ps2: why you are remove the item machete from player, and later give it back? If someone has no machete before, he has one after he finished harvesting.
 
Last edited:
THANK YOU SOOOO MUCH!!! xD That fixed the issue and the plants are no longer indestructible so people can't get infinite amounts.. But... there is a new issue :D

When a player right clicks on the Harvest Hemp option on the machete, the right click menu remains there and clickable to gather as much as they can click before the plant dies even though I have it set-up so that the machete is removed. Basically, in more simple terms, the right click menu is remaining on an item that has been removed from the inventory as long as they do not click anywhere else or leave their gear. Any ideas on how to fix that? I'm no master scripter, but is there a way for the script to also check if the player still has an object then remove there right click option? The only two possible solutions I thought of was to either 1. Update-check if the player still has the item (Machete) or 2. Close out of their gear menu once they click harvest hemp. I would prefer to go for the second option if you know how to do it.

Any help is appreciated you've help sooo much already :D
 
"ps2: why you are remove the item machete from player, and later give it back? If someone has no machete before, he has one after he finished harvesting.
The reason for that is that to actually harvest the hemp you have to right click harvest on the machete. I have a another script that can add actions to right click on for whatever items I choose. Basically it adds the text "Harvest Hemp" to the machete and it then activates a script which is the script above.
 
You can set a global variable to true, at the start of the harvesting and false at the end.
And check these Variable if the player is already harvesting hemp, so it only can run once a time

Code:
if(_countHemp >0 AND !harvesting)then{
harvesting = true;

...


harvesting = false;
};
you have to initialize this variable elsewhere
Code:
harvesting = false;

Code:
if(_countHemp >0)then{
    if !(harvesting) then {
        harvesting = true;

        ...


        harvesting = false;
    } else {
        cutText [format["You are already harvesting hemp!"], "PLAIN DOWN"];
    };
} else {
    cutText [format["You are not close enough to a hemp plant!"], "PLAIN DOWN"];
};

ps.: you should name the variable unique like "bubba_havesting" or something, so it can't influence other scripts
 
Last edited:
Also it would help more if you joined my Teamspeak so I can talk more directly to you. Our TS is ts3.xenagosgaming.com. Sorry if I'm not supposed to post ip's.
 
Can I put that variable in my Missions init.sqf? with the rest of my true/false dayz statements?
to initialize it, it think yes

Also it would help more if you joined my Teamspeak so I can talk more directly to you. Our TS is ts3.xenagosgaming.com. Sorry if I'm not supposed to post ip's.
Uhh, sry, but my english skills are very poor, i'm from germany
 
It didn't work. I may have put it in wrong but here's what I have currently.

hemp.sqf:

Code:
_countHemp = count nearestObjects [player, ["fiberplant"], 5];
_Hemp = nearestObjects [player, ["fiberplant"], 5];

if (_countHemp > 0) then {
    if !(harvesting) then {
        harvesting = true;
cutText [format["Start harvesting....."], "PLAIN DOWN"];
player removeWeapon "ItemMachete";
player playActionNow "Medic";
sleep 5;
player addMagazine "ItemKiloHemp";
player addWeapon "ItemMachete";
cutText [format["Finished harvesting! A kilo of hemp has been added to your inventory!"], "PLAIN DOWN"];
            sleep 1;
            (_Hemp select 0) setDamage 1;
            };
            harvesting = false;
    } else {
        cutText [format["You are already harvesting hemp!"], "PLAIN DOWN"];
    };
} else {
cutText [format["You are not close enough to a hemp plant!"], "PLAIN DOWN"];
};

And then added

Code:
harvesting = false;

Into my init.sqf
 
try this:
Code:
_Hemp = nearestObjects [player, ["fiberplant"], 5];
_countHemp = count _Hemp;

if (_countHemp > 0) then {
    if !(bubba_harvesting) then {
        bubba_harvesting = true;
        cutText [format["Start harvesting....."], "PLAIN DOWN"];
        player removeWeapon "ItemMachete";
        player playActionNow "Medic";
        sleep 5;
        player addMagazine "ItemKiloHemp";
        player addWeapon "ItemMachete";
        cutText [format["Finished harvesting! A kilo of hemp has been added to your inventory!"], "PLAIN DOWN"];
        sleep 1;
        (_Hemp select 0) setDamage 1;
        bubba_harvesting = false;
    } else {
        cutText [format["You are already harvesting hemp!"], "PLAIN DOWN"];
    };
} else {
    cutText [format["You are not close enough to a hemp plant!"], "PLAIN DOWN"];
};

you had a } too much

and this in your init.sqf:
Code:
bubba_harvesting = false;
 
Haha!! I didn't notice that parsing error thanks. It all works now. But....:D...ONE more issue. When the plant destroys itself after being harvested it makes the sound of a building being destroyed and falls in the ground as you would expect, the problem is if a player is too close to it when that happens they die. Is there a way to make the plant simply fall over like when you are chopping down tree's that way it doesn't actually destroy and kill the player?
 
Hmm, i think thats a setting in the config.bin/config.cpp, for the model/class of this item, but i'm not sure
 
Also if I change it will the players have to do the same or is it in the server.pbo?

Edit: Actually if its in the dayz_code I can just add it to my custom compiles right?
 
No sorry, i don't know much about the configs.
Every Item/Building etc. is set in these configs, but all pbo files can contain their config file, and in epoch it exist more then one file of these.
I'm not realy familar with locality of these config files and settings, you can test it, if you create your own config file and put it in a folder in the dayz_server.pbo.
 
Alright thanks soooooo much! xD Have been trying to get this script working for awhile now and now its working great! Thanks a bunch man! I'm sure others whom have this issue will see this thread and figure it out.
 
Update:
Alright my hemp scripts have been working great except for the previous issue. Now as said before, I needed to edit a config.bin. Well instead I tryed a new piece of code. Instead of setting its damage to 1 I simply chaged it to a deleteVehicle entry. It's not working, thus is why I am here.

Here is my code:

Code:
_Hemp = nearestObjects [player, ["fiberplant"], 5];
_countHemp = count _Hemp;

if (_countHemp > 0) then {
    if !(bubba_harvesting) then {
        bubba_harvesting = true;
        cutText [format["Start harvesting....."], "PLAIN DOWN"];
        player removeWeapon "ItemMachete";
        player playActionNow "Medic";
        sleep 5;
        player addMagazine "ItemKiloHemp";
        player addWeapon "ItemMachete";
        cutText [format["Finished harvesting! A kilo of hemp has been added to your inventory!"], "PLAIN DOWN"];
        sleep 1;
        deleteVehicle _Hemp;
        bubba_harvesting = false;
    } else {
        cutText [format["You are already harvesting hemp!"], "PLAIN DOWN"];
    };
} else {
    cutText [format["You are not close enough to a hemp plant!"], "PLAIN DOWN"];
};

I also tryed replacing the _Hemp in the delete vehicle entry with _fiberplant and still to no avail. What's wrong with it? Could it be because the createVehicle entries for the Hemp are on my server.pbo and cannot be deleted with another script until the next scheduled restart of my server? Any help is appreciated!

Edit: The problem in-game is that now instead of falling down and killing the player if they are too close it simply just stays so the player can achieve infinite amounts.
 
It's the same as before, _hemp is an array of objects not only one.
Use
deleteVehicle (_Hemp select 0);
 
Back
Top