Jump to content
Sign in to follow this  
eagledude4

Creating an object through script

Recommended Posts

if (isNull cashpile1) then {
	cashpile1 = "il_money_stack_500s" createvehicle (getpos posCashpile1);
};

What I want to do is create an object called cashpile1 at the position poscashpile1. is this how I would accomplish this? I used this syntax "Object = type createVehicle position" but am unsure if the object = will actually give the new vehicle that name, or if I have to use setVehicleVarName in setVehicleInit or something.

Share this post


Link to post
Share on other sites
if (isNull cashpile1) then {
	cashpile1 = "il_money_stack_500s" createvehicle (getpos posCashpile1);
};

What I want to do is create an object called cashpile1 at the position poscashpile1. is this how I would accomplish this? I used this syntax "Object = type createVehicle position" but am unsure if the object = will actually give the new vehicle that name, or if I have to use setVehicleVarName in setVehicleInit or something.

try that if SP MP mission.. notice that on dedi servers not working that way.

_spawn = [getMarkerPos "poscashpile1", "il_money_stack_500s", "cashpile1",0];

edit: i think you can use the GetPos also. getmarkerpos needs a named marker in your mission

Edited by dragonsyr

Share this post


Link to post
Share on other sites
cashpile1 would be the object name.

Not correct, cashpile1 will simply be a variable holding the object instance, use setVehicleVarName in order to give the object a name.

Share this post


Link to post
Share on other sites

So would this be what I'm looking for?: (Also, I used getmarkerpos by mistake earlier)

if (isNull cashpile1) then {
	_spawn = [getPos "poscashpile1", "il_money_stack_500s", "cashpile1",0];
};

Do I need to use createVehicle with _spawn or something?

Share this post


Link to post
Share on other sites

If cashpile1 is a handler, as in, if it is used like so...

[color="#FF0000"]cashpile1[/color] = "il_money_stack_500s" createVehicle (getPos poscashpile1);

Then, you need to be aware that "cashpile1", if not defined before (which is why you're checking isNull), is NOT defined as an object, therefore it will never meet your isNull check because isNull only checks against objects, so if the handler is not assigned to an object then "cashpile1" cannot be checked using isNull.

isNull is really only effective for checking to see if an object that you defined before exists. Here is an example.

private["_car"];
_car = (nearestObjects [getPos player, ["LandVehicle"], 20] select 0);
waitUntil {isNull _car};
hint "_car is null";

Edited by Horner
Added Example of isNull

Share this post


Link to post
Share on other sites

Alright that makes sense.

If I were to define the location of cashpile1 at the beginning of my mission like this:

_posCashpile1 = createMarker ["posCashpile1", position cashpile1]

Could I use:

_posCashpile1 = getMarkerPos "posCashpile1";
_cashpile1 = nearestObject [_posCashPile1, "il_money_stack_500s"];

if (isNull _cashpile1) then {
	_cashpile1 = "il_money_stack_500s" createvehicle _posCashpile1;
};

Edited by eagledude4

Share this post


Link to post
Share on other sites

That should work as long as "il_money_stack_500s" is a recognisable object to the nearestObject command.

Share this post


Link to post
Share on other sites

If no "il_money_stack_500s" is found _cashpile1 will be nil. Assign _cashpile1 as objNull first to get a definite isNull check.

_posCashpile1 = getMarkerPos "posCashpile1";
_cashpile1 = objNull;
_cashpile1 = nearestObject [_posCashPile1, "il_money_stack_500s"];

if (isNull _cashpile1) then 
{
	_cashpile1 = "il_money_stack_500s" createvehicle _posCashpile1;
};

EDIT: Since I didn't test this I'll add in something else, not sure if the nearestObject check, if something is not found will it return the value to objNull, therefore it may be best to use a check if the above doesn't work.

_posCashpile1 = getMarkerPos "posCashpile1";
_cashpile1 = objNull;
if ((count (nearestObjects [_posCashpile1, ["il_money_stack_500s"], 5])) > 0) then
{
_cashpile1 = nearestObject [_posCashPile1, "il_money_stack_500s"];
};

if (isNull _cashpile1) then 
{
	_cashpile1 = "il_money_stack_500s" createvehicle _posCashpile1;
};

Edited by Horner

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
Sign in to follow this  

×