/plant cmd help
#1

https://sampforum.blast.hk/showthread.php?tid=609790

I download that filterscript and I want to make /plant harvest is only allowed for your plant only,how do i do that?

the command

PHP Code:
COMMAND:plant(playeridparams[])
{
    if(
IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid0xE74C3CFF"ERROR: {FFFFFF}You can't use this command in a vehicle.");
    if(
isnull(params)) return SendClientMessage(playerid0xE88732FF"SYNTAX: {FFFFFF}/plant [place/harvest]");
    if(!
strcmp(params"place"true)) {
        
/* -- planting -- */
        
if(Player[playerid][InDrugZone] == false) return SendClientMessage(playerid0xE74C3CFF"ERROR: {FFFFFF}You aren't in drug zone.");
        if(
PlayerDrugData[playerid][Seeds] < 1) return SendClientMessage(playerid0xE74C3CFF"ERROR: {FFFFFF}You don't have a drug seed.");
        if(
Player_PlantCount(playerid) >= PLAYER_LIMIT) return SendClientMessage(playerid0xE74C3CFF"ERROR: {FFFFFF}You can't plant any more drug plants.");
        if(
GetClosestPlant(playerid) != -1) return SendClientMessage(playerid0xE74C3CFF"ERROR: {FFFFFF}You can't place a drug plant here because there is one nearby.");
        new 
id Iter_Free(Plants);
        if(
id == -1) return SendClientMessage(playerid0xE74C3CFF"ERROR: {FFFFFF}Server drug plant limit reached.");
        
GetPlayerName(playeridPlantData[id][plantedBy], MAX_PLAYER_NAME);
        
GetPlayerPos(playeridPlantData[id][plantX], PlantData[id][plantY], PlantData[id][plantZ]);
        
PlantData[id][plantGrowth] = 0;
        
PlantData[id][plantObj] = CreateDynamicObject(3409PlantData[id][plantX], PlantData[id][plantY], PlantData[id][plantZ] - 0.750.00.00.0);
        
SetDynamicObjectMaterial(PlantData[id][plantObj], 219478"signsurf""sign"0xFFFFFFFF);
        new 
label_string[128];
        
format(label_stringsizeof(label_string), "Drug Plant (%d)\n\n{FFFFFF}Placed by %s\nGrowth: {E74C3C}0%%\n\n{FFFFFF}/plant harvest"idPlantData[id][plantedBy]);
        
PlantData[id][plantLabel] = CreateDynamic3DTextLabel(label_string0xF1C40FFFPlantData[id][plantX], PlantData[id][plantY], PlantData[id][plantZ], 5.0);
        
PlantData[id][plantTimer] = SetTimerEx("PlantGrowth"GROWTH_INTERVAL 1000true"i"id);
        
Iter_Add(Plantsid);
        
PlayerDrugData[playerid][Seeds]--;
        
PlayerDrugData[playerid][TotalPlanted]++;
        
/* -- planting -- */
    
}else if(!strcmp(params"harvest")) {
        
/* -- harvesting -- */
        
if(PlayerDrugData[playerid][Drugs] >= CARRY_LIMIT) return SendClientMessage(playerid0xE74C3CFF"ERROR: {FFFFFF}You can't carry any more drugs.");
        new 
id GetClosestPlant(playerid);
        if(
id == -1) return SendClientMessage(playerid0xE74C3CFF"ERROR: {FFFFFF}You're not near a drug plant.");
        if(!
PlantData[id][gotLeaves]) return SendClientMessage(playerid0xE74C3CFF"ERROR: {FFFFFF}You can't harvest this plant because it's not ready.");
        new 
harvested PlantData[id][plantGrowth], string[96];
        if(
PlayerDrugData[playerid][Drugs] + harvested CARRY_LIMITharvested CARRY_LIMIT PlayerDrugData[playerid][Drugs];
        
format(stringsizeof(string), "DRUG PLANT: {FFFFFF}You harvested a drug plant and got %d grams of drugs."harvested);
        
SendClientMessage(playerid0x3498DBFFstring);
        
PlayerDrugData[playerid][Drugs] += harvested;
        
PlayerDrugData[playerid][TotalHarvestedPlants]++;
        
PlayerDrugData[playerid][TotalHarvestedGrams] += harvested;
        new 
owner_id Plant_GetOwnerID(id);
        if(
strcmp(PlantData[id][plantedBy], Player_GetName(playerid), true) && IsPlayerConnected(owner_id)) SendClientMessage(owner_id0x3498DBFF"DRUG PLANT: {FFFFFF}Somebody harvested one of your drug plants!");
        
Plant_Destroy(id);
        
/* -- harvesting -- */
    
}else{
        
SendClientMessage(playerid0xE88732FF"SYNTAX: {FFFFFF}/plant [place/harvest]");
    }
    return 
1;

Reply
#2

Code:
COMMAND:plant(playerid, params[]) 
{ 
    if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You can't use this command in a vehicle."); 
    if(isnull(params)) return SendClientMessage(playerid, 0xE88732FF, "SYNTAX: {FFFFFF}/plant [place/harvest]"); 

	if(!strcmp(params, "place", true)) 
	{ 
		if(Player[playerid][InDrugZone] == false) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You aren't in drug zone."); 
		
		if(PlayerDrugData[playerid][Seeds] < 1) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You don't have a drug seed."); 
		
		if(Player_PlantCount(playerid) >= PLAYER_LIMIT) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You can't plant any more drug plants."); 
		
		if(GetClosestPlant(playerid) != -1) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You can't place a drug plant here because there is one nearby."); 
		
		new id = Iter_Free(Plants); 
		if(id == -1) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Server drug plant limit reached."); 
		
		GetPlayerName(playerid, PlantData[id][plantedBy], MAX_PLAYER_NAME); 
		GetPlayerPos(playerid, PlantData[id][plantX], PlantData[id][plantY], PlantData[id][plantZ]); 

		PlantData[id][plantGrowth] = 0; 
		PlantData[id][plantObj] = CreateDynamicObject(3409, PlantData[id][plantX], PlantData[id][plantY], PlantData[id][plantZ] - 0.75, 0.0, 0.0, 0.0); 
		SetDynamicObjectMaterial(PlantData[id][plantObj], 2, 19478, "signsurf", "sign", 0xFFFFFFFF); 

		new label_string[128]; 
		format(label_string, sizeof(label_string), "Drug Plant (%d)\n\n{FFFFFF}Placed by %s\nGrowth: {E74C3C}0%%\n\n{FFFFFF}/plant harvest", id, PlantData[id][plantedBy]); 
		PlantData[id][plantLabel] = CreateDynamic3DTextLabel(label_string, 0xF1C40FFF, PlantData[id][plantX], PlantData[id][plantY], PlantData[id][plantZ], 5.0); 

		PlantData[id][plantTimer] = SetTimerEx("PlantGrowth", GROWTH_INTERVAL * 1000, true, "i", id); 
		Iter_Add(Plants, id); 

		PlayerDrugData[playerid][Seeds]--; 
		PlayerDrugData[playerid][TotalPlanted]++; 
	}	
	else if(!strcmp(params, "harvest")) 
	{
		if(PlayerDrugData[playerid][Drugs] >= CARRY_LIMIT) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You can't carry any more drugs."); 
		
		new id = GetClosestPlant(playerid); 
		if(id == -1) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You're not near a drug plant."); 
		
		if(!PlantData[id][gotLeaves]) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You can't harvest this plant because it's not ready."); 
		
		new owner_id = Plant_GetOwnerID(id);
		if(owner_id != playerid) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF} You can harvest only your plant.")
		
		new harvested = PlantData[id][plantGrowth], string[96]; 
		if(PlayerDrugData[playerid][Drugs] + harvested > CARRY_LIMIT) harvested = CARRY_LIMIT - PlayerDrugData[playerid][Drugs];
		
		format(string, sizeof(string), "DRUG PLANT: {FFFFFF}You harvested a drug plant and got %d grams of drugs.", harvested); 
		SendClientMessage(playerid, 0x3498DBFF, string); 

		PlayerDrugData[playerid][Drugs] += harvested; 
		PlayerDrugData[playerid][TotalHarvestedPlants]++; 
		PlayerDrugData[playerid][TotalHarvestedGrams] += harvested; 

		Plant_Destroy(id); 
	}
	else SendClientMessage(playerid, 0xE88732FF, "SYNTAX: {FFFFFF}/plant [place/harvest]"); 

    return 1; 
}
It was simple because the 'solution' was already in the code.
As you can see, 'new owner_id = Plant_GetOwnerID(id);' will get the playerid of the planter and, with a simple check as 'owner_id != playerid', you can see if the harvester is the owner. If not, It will show an error message else he will harvest the plant.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)