How much wood can a wood chuck, chuck? (Tree cutting script)
#1

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;
}
Reply
#2

Hello!

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

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.
Reply
#4

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

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
Reply
#6

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)
Reply
#7

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

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;
Reply
#9

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.
Reply
#10

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

Given Rep

xx
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)