Jump to content
AngelCaptain

Problem to met a setvariable on P3D already on the map.

Recommended Posts

Hey good evening guys, i got a problem when i'm trying to find the solution.

 

Sorry for my english i'm french :)

 

i'll explain exactly what i'm trying to do.

 

Firstable i make a scan of all p3d in a range 15m around the player, when its done i asking for find the p3d i want to use.

 

Exemple: 

_terrainObjects = nearestTerrainObjects [player, ["TREE", "SMALL TREE", "BUSH"], 15];
_object = [];
_DestructionP3D = "t_oleae1s_f.p3d";
{
	_counterDestructionP3D = count _DestructionP3D;
	for "_i" from 0 to (_counterDestructionP3D-1) do
	{
		_find = str _x find (_DestructionP3D select _i);
		if (_find > 0) then
		{
			if(damage _x < 1) then 
				{
					_object pushBack _x;
				};
		};
	};
} forEach _terrainObjects;
_objects = count _object;
if (_objects < 1) exitWith
{
	Hint "Impossible to get the tree";
};

after that i select the closer of the player:

_tree = _object select 0;
_RealAvailable = 16;

after that when the tree is select and all is good i want to put on it a specific variable to give it to him a virtual inventory of apple at this moment all is good but when its time to give to him the variable its look like not working.

if (isNil {_tree getVariable "appletogetit"}) then
{
	diag_log "The variable is not create we will create it.";
   _tree setVariable ["appletogetit",_RealAvailable,true];
    diag_log format["Number of apple's into the tree: %1.",(_tree getVariable "appletogetit")];
} else {
    _tree getVariable "appletogetit";
    diag_log "Retreive the apple into the tree";
};

into the dialog for fetch the number of the appl was a add i got Null into the RPT:

23:16:14 "Number of apple's into the tree: <null>."

so its someone can find the solution of that problem thats will be magic.

 

 

Thanks for help. 

 

Best regards

Share this post


Link to post
Share on other sites

Hi Samuel. It seems your local variables _RealAvailable or _tree are not fully defined when you try to setVariable on _tree.

Same script?

Are you sure there is a "t_oleae1s_f.p3d" near the player?

 

Share this post


Link to post
Share on other sites

Could you:

diag_log format ["arbre: %1 pommes: %2",_tree, _RealAvailable ];

 

Share this post


Link to post
Share on other sites
5 minutes ago, pierremgi said:

Could you:

diag_log format ["arbre: %1 pommes: %2",_tree, _RealAvailable ];

 

thanks for your answer : 

23:58:20 "arbre: 1143130: t_oleae1s_f.p3d pommes: 14"

 

Share this post


Link to post
Share on other sites

2 apples missing? Could be some thief... or some missing lines on what you wrote above. Difficult to help more.

Share this post


Link to post
Share on other sites
Just now, das attorney said:

You can't setVariables onto things like trees and rocks.  

We cant make a setvariable on tree ? why ?

Share this post


Link to post
Share on other sites
Just now, pierremgi said:

2 apples missing? Could be some thief... or some missing lines on what you wrote above. Difficult to help more.

no its because the apple is calculating with a random

Share this post


Link to post
Share on other sites
1 minute ago, das attorney said:

You can't setVariables onto things like trees and rocks.  

and the variables is made on a p3d

Share this post


Link to post
Share on other sites
1 minute ago, das attorney said:

You can't save variables onto things like trees and rocks.  

Why? not really objects even detected by nearestTerrainObjects?

Share this post


Link to post
Share on other sites
Just now, pierremgi said:

Why? not really objects even detected by nearestTerrainObjects?

i put the variables on the p3d not on the classname because yes tree dont have any classname

Share this post


Link to post
Share on other sites

It's not a proper object.

 

Try it:

 

_tree = (nearestTerrainObjects [player, ["TREE", "SMALL TREE", "BUSH"], 200]) select 0;
_tree setVariable ["apple",true];
diag_log format ["apple: %1",_tree getVariable ["apple",false]];

 

Will return "apple: false" 

 

 

Share this post


Link to post
Share on other sites
Just now, Samuel Desmarais said:

i put the variables on the p3d not on the classname because yes tree dont have any classname

Not so bad, class names are strings. You couldn't do that.

Share this post


Link to post
Share on other sites
Just now, das attorney said:

It's not a proper object.

 

Try it:

 


_tree = (nearestTerrainObjects [player, ["TREE", "SMALL TREE", "BUSH"], 200]) select 0;
_tree setVariable ["apple",true];
diag_log format ["apple: %1",_tree getVariable ["apple",false]];

 

Will return "apple: false" 

 

 

True but i dont have any other solution for making a virtual inventory directly into the tree ?

Share this post


Link to post
Share on other sites

If you can't use setVariable on map objects, could he do this

 

_trees = nearestObjects [player,["Trees"],15];

{

    _class = typeof _x;

    _pos = getpos _x;

    _dir = getdir _x;

    hideObject _x;

    _newTree = _class createVehicle _pos;

    _newTree setdir _dir;

    _newTree setVariable ["appletogetit",_RealAvailable,true];

}forEach _trees

  • Like 2

Share this post


Link to post
Share on other sites

If you really have to then put a game logic where the tree is then set the variable to that.  Or check out using "supply" containers as a fake inventory.  SO it looks like the tree has an inventory but really you're interacting with an invisible object.  edit: Or what Beldum just said :)

Share this post


Link to post
Share on other sites

i need to make it for each tree has a proper inventory all in random and for all client on the server

Share this post


Link to post
Share on other sites

Or he could try this

 

_trees = nearestObjects [player,["Trees"],15];

{

    _class = typeof _x;

    _pos = getpos _x;

    _dir = getdir _x;

    hideObject _x;

    _fakeTree = "Land_HelipadEmpty_F" createVehicle _pos;

    _fakeTree setVariable ["appletogetit",_RealAvailable,true];

}forEach _trees;

Share this post


Link to post
Share on other sites
Just now, pierremgi said:

Arf! trying to place apples in olive tree, That's hard!

so funny xD.

1 minute ago, Beldum said:

Or he could try this

 

_trees = nearestObjects [player,["Trees"],15];

{

    _class = typeof _x;

    _pos = getpos _x;

    _dir = getdir _x;

    hideObject _x;

    _fakeTree = "Land_HelipadEmpty_F" createVehicle _pos;

    _fakeTree setVariable ["appletogetit",_RealAvailable,true];

}forEach _trees;

i'll try this and see maybe thats will be working

Share this post


Link to post
Share on other sites

abandon _realAvailable for something like :  (4  + round random 12) // 4 mini up to 16 in this case.

Share this post


Link to post
Share on other sites
1 minute ago, pierremgi said:

abandon _realAvailable for something like :  (4  + round random 12) // 4 mini up to 16 in this case.

already made into an array

Share this post


Link to post
Share on other sites

Thanks alot people now all its working with spawning a empty helipad but now another problem was found 

if ((_tree getVariable ["PommesDispo",0]) == 0) then
{
	diag_log "La variable es introuvable et va maintenant etre créer.";
   _tree setVariable ["PommesDispo",_RealAvailable,true];
    diag_log format["Nombre de pommes: %1.",(_tree getVariable "PommesDispo")];
} else {
    _tree getVariable "PommesDispo";
   diag_log format ["Pommes: %1",_tree getVariable ["PommesDispo",0]];
};

always i resend the script the variable was not found because the script always go to the _tree setVariable ["PommesDispo",_RealAvailable,true]; @pierremgi

Share this post


Link to post
Share on other sites

Probably because you're creating another empty helipad each time. You're trying to patch some workarounds like helipads when player is near trees. Why don't you create just once your apples regardless of player(s) distance?

Do it simple.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×