Command: Harvestweed
#1

I made a weed system, where you can buy seeds, put them in the ground. And after some time the weed object starts rising from the ground, giving you a message the weed smells right ( And sets the variable of the weedplant: weedVariables[x][PlantedWeedReady] to 1) . Everything works fine, except the command to take the weed from the "plants" doesn't work that well.
I use zcmd.
The problem is, when I am standing on one of my weed jobjects, so I'm in a range of 10, of the coordinates, which work (already tested that, they're saved in a mysql database, and get deleted once you harvest the weed).
So whatever I do, it gives me the message InGame:
"You are not near any weed plants, or they don't smell that good to harvest yet."

Код:
CMD:harvestweed(playerid)
{
	new HarvestValue, WeedHarvestString[128], queryString[128];
	HarvestValue = random(100)+200;
    for(new x = 0; x < MAX_WEED; x++)
	{
	  
	    if(IsPlayerInRangeOfPoint(playerid, 10.0, weedVariables[x][PlantedWeedPos][0], weedVariables[x][PlantedWeedPos][1], weedVariables[x][PlantedWeedPos][2]) && weedVariables[x][PlantedWeedReady] == 1)
		{
		    	playerVariables[playerid][pPlantedSeed]--;
		    	playerVariables[playerid][pWeed] += HarvestValue;
		    	format(WeedHarvestString, sizeof(WeedHarvestString),"Harvesting the weed brought you a total of %d grams of weed. (It's in /myitems)", HarvestValue);
				SendClientMessage(playerid, COLOR_GREY, WeedHarvestString);
				DestroyDynamicObject(Weed[x]);
				format(queryString, sizeof(queryString), "DELETE FROM weedplants WHERE weedID = '%d'", weedVariables[x][PlantedWeedID]);
				mysql_query(queryString);
		}
		//else return SendClientMessage(playerid, COLOR_GREY, "You are not near any weed plants");
		//else if(weedVariables[x][PlantedWeedReady] == 0) return SendClientMessage(playerid, COLOR_GREY, "The weed smell isn't that perfect yet, they need more time growing.");
	}
	else return SendClientMessage(playerid, COLOR_GREY, "You are not near any weed plants, or they don't smell that good to harvest yet.");
	return 1;
}
Reply
#2

Try using IsPlayerInRangeOfPoint
Reply
#3

uhh, check the code, because that's pretty what I did, problem is, it doesn't work, so I need suggestions on why it doesn't work.

Код:
if(IsPlayerInRangeOfPoint(playerid, 10.0, weedVariables[x][PlantedWeedPos][0], weedVariables[x][PlantedWeedPos][1], weedVariables[x][PlantedWeedPos][2]) && weedVariables[x][PlantedWeedReady] == 1)
		{
That's the line, so isPlayerInRangeOfPoint is already in it:
Reply
#4

btw are you using CreateDynamicObject/CreateObject to plant weed? Because i cannot find any of those in ur script
Reply
#5

CMD:harvestweed(playerid)
{
new HarvestValue, WeedHarvestString[128], queryString[128];
HarvestValue = random(100)+200;
for(new x = 0; x < MAX_WEED; x++)
{

if(IsPlayerInRangeOfPoint(playerid, 10.0, weedVariables[x][PlantedWeedPos][0], weedVariables[x][PlantedWeedPos][1], weedVariables[x][PlantedWeedPos][2]) && weedVariables[x][PlantedWeedReady] == 1)
{
playerVariables[playerid][pPlantedSeed]--;
playerVariables[playerid][pWeed] += HarvestValue;
format(WeedHarvestString, sizeof(WeedHarvestString),"Harvesting the weed brought you a total of %d grams of weed. (It's in /myitems)", HarvestValue);
SendClientMessage(playerid, COLOR_GREY, WeedHarvestString);
DestroyDynamicObject(Weed[x]);
format(queryString, sizeof(queryString), "DELETE FROM weedplants WHERE weedID = '%d'", weedVariables[x][PlantedWeedID]);
mysql_query(queryString);
}
}
return 1;
}

should work... you had an else but no if statement for it so its showing that message(i think). give that code a go. also fix that commented else coz u dont have a var to see if it has looped through all the pos or itll spam your chat.

It should work thought.


@Tanush
DestroyDynamicObject Clearly answers your question
Reply
#6

Quote:
Originally Posted by Tanush123
Посмотреть сообщение
btw are you using CreateDynamicObject/CreateObject to plant weed? Because i cannot find any of those in ur script
That's because this isn't /plantweed, it's taking the weed (so you destroy/remove the object and not place it)

@THE_KNOWN

Thanks for helping, but I don't really think that solves it. You removed the problem but you also removed the way it works. I want it, that it gives you a message when you are not near any weedplants. You removed the message, and I also think, that the else statement is fine, because you can use "Else" it doesn't have to be "Else if" (Correct me if I'm wrong, but I see plenty people using: If: bla bla bla, Else: wa wa wa)

So in this case If person is near a weed plant (IsPlayerInRangeOfPoint), that is fully grown (variable set to: 1) THEN you get weed from it, if you are not near any, it tells you, you aren't. If it's not grown yet (variable still 0) Then tells you a message, the weed doesn't smell right yet.
Reply
#7

Remove
pawn Код:
else return SendClientMessage(playerid, COLOR_GREY, "You are not near any weed plants, or they don't smell that good to harvest yet.");
Reply
#8

Quote:
Originally Posted by Johndaonee
Посмотреть сообщение
Remove
pawn Код:
else return SendClientMessage(playerid, COLOR_GREY, "You are not near any weed plants, or they don't smell that good to harvest yet.");
Yes that was already suggested above, BUT again, how do I script it then, to give you a message, when you are not near the weed plant or if it's not fully grown yet ( weedVariables[x][PlantedWeedReady] == 1 )
I Need that message in it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)