SA-MP Forums Archive
How much wood can a wood chuck, chuck? (Tree cutting script) - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: How much wood can a wood chuck, chuck? (Tree cutting script) (/showthread.php?tid=573185)



How much wood can a wood chuck, chuck? (Tree cutting script) - DukeVega - 05.05.2015

Dear Peopel of the internet,

I thank you in advance for your help

very simple little piece of script here what it should do is detect if you are near X object
and then if you have a knife in hand
will let you cut the tree and gather wood


For the life of me cant get it to work, seems to think you are never near the item in game ; (

Where am i going wrong?


<3 Duke


Код:
CMD:cuttree(playerid, params[])
{
	if(IsPlayerConnected(playerid))
	{
	    if(GetPlayerWeapon(playerid) == 4)
	    {
   		if(IsPlayerNearObject(playerid, 837, 10.0))
			{
			    GameTextForPlayer(playerid, "CUTTING DOWN TREE", 3500, 5);
		 		new string[158];
				new sendername[MAX_PLAYER_NAME];
				GetPlayerName(playerid, sendername, sizeof(sendername));
				format(string, sizeof(string), "%s takes out their Hatchet and starts to cut down the tree for wood", sendername);
				ProxDetector(30.0, playerid, string, COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN,COLOR_GREEN);
				AccountInfo[playerid][pWood] += 4;
			}
			else return SendClientMessage(playerid, RED, "[Database:]{FFFFFF} You are not near any cuttable trees, please look for forests.");
	    }
	    else return SendClientMessage(playerid, RED, "[Database:]{FFFFFF} You cannot cut down any trees, you do not have a Hatchet");
	}
	return 1;
}



AW: How much wood can a wood chuck, chuck? (Tree cutting script) - Mencent - 05.05.2015

Hello!

If you aren't in the near of the object, you have to share your IsPlayerNearObject-function.


Re: How much wood can a wood chuck, chuck? (Tree cutting script) - MP2 - 05.05.2015

Oh my god, how can you code like that?! Learn to indent and use spacing!

Show your IsPlayerNearObject function. I have a feeling it takes an object ID not a model ID. Also, wouldn't a chainsaw make more sense than a knife?

Also, you should use defines like WEAPON_KNIFE instead of '4', so when you come back to that code in 3 years you can understand it. I mean, you probably still would, but it helps.


Re: How much wood can a wood chuck, chuck? (Tree cutting script) - burhanjaved - 05.05.2015

OK, What error it gives when you try to compile it.


Re: How much wood can a wood chuck, chuck? (Tree cutting script) - DukeVega - 05.05.2015

sorry i used the wrong wrap, remade .. and yeh i didnt actually make this script its just something im playing with and learning on.


Quote:
Originally Posted by burhanjaved
Посмотреть сообщение
OK, What error it gives when you try to compile it.
No error on compile, it just doesnt think you are near the object when in game


Re: How much wood can a wood chuck, chuck? (Tree cutting script) - DukeVega - 05.05.2015

Quote:
Originally Posted by MP2
Посмотреть сообщение
Oh my god, how can you code like that?! Learn to indent and use spacing!

Show your IsPlayerNearObject function. I have a feeling it takes an object ID not a model ID. Also, wouldn't a chainsaw make more sense than a knife?

Also, you should use defines like WEAPON_KNIFE instead of '4', so when you come back to that code in 3 years you can understand it. I mean, you probably still would, but it helps.
if(IsPlayerNearObject(playerid, 837, 10.0))



its on the post (See above)


837 is the object id for a piece of dead wood (.like a log)


Re: How much wood can a wood chuck, chuck? (Tree cutting script) - MP2 - 05.05.2015

You didn't read my post properly. Post the code for that function. It probably wants an OBJECT ID not a MODEL ID.


Re: How much wood can a wood chuck, chuck? (Tree cutting script) - DukeVega - 05.05.2015

Quote:
Originally Posted by MP2
Посмотреть сообщение
You didn't read my post properly. Post the code for that function. It probably wants an OBJECT ID not a MODEL ID.

Sorry im not exactly 100% sure what you mean by function


is is this bit

Код:
stock IsPlayerNearObject(playerid, objectid, Float:range)
{
    new Float:X, Float:Y, Float:Z;
    GetObjectPos(objectid, X, Y, Z);
    if(IsPlayerInRangeOfPoint(playerid, range, X, Y, Z))return true;
    return false;



Re: How much wood can a wood chuck, chuck? (Tree cutting script) - MP2 - 05.05.2015

Yes. Like I said, it's expecting an OBJECT ID not a MODEL ID.

You have two options: loop through all objects and use GetObjectModel to check whether it's a tree, OR create cuttable trees with a function and save their IDs in an array.


Re: How much wood can a wood chuck, chuck? (Tree cutting script) - DukeVega - 05.05.2015

Cool thanks, ill have a play around figure it out.

Given Rep

xx