Jump to content
revv

[SOLVED] Giving name to object

Recommended Posts

Hello I am trying to spawn an ammo crate at mission start and giving it a name so when it's destroyed the task sets to succeeded. Having trouble with giving it a name upon being created, anyone know how to do this?

SOLVED (not sure how to edit title to say solved)
This is the working script
mission_1.sqf
 

"scripts\cache_A.sqf" remoteExec ["execVM",2];
switch (side player) do 
{

case WEST: // BLUFOR briefing goes here
	{
		player createDiaryRecord ["Diary", ["*CHANGE ME*", "*debug 1*"]];

//Task1 - COMMENT
		task_1 = player createSimpleTask ["Mission 1"]; 
		task_1 setSimpleTaskDescription ["This is mission 1 description","Find Cache","Search"]; 
		task_1 setSimpleTaskDestination (getMarkerPos "cache_1");
		task_1 setTaskState "Assigned"; 
		player setCurrentTask task_1;
		
//Task2 - COMMENT
		task_2 = player createSimpleTask ["Exfil"]; 
		task_2 setSimpleTaskDescription ["Leave area.","Exfiltrate","Exfil"]; 
		task_2 setSimpleTaskDestination (getMarkerPos "cache_3");
		task_2 setTaskState "created"; 
		
	};


case EAST: // OPFOR briefing goes here
{ 
};


case RESISTANCE: // RESISTANCE/INDEPENDENT briefing goes here
{ 
};


case CIVILIAN: // CIVILIAN briefing goes here
{ 
};
};

cache_A.sqf
 

//  Create weapon cache at random marker
ammocrate1 = createVehicle ["B_supplyCrate_F",getMarkerPos "cache_1",["cache_2","cache_3"], 10, "NONE"];

//  Create trigger for crate
_trg = createTrigger ["EmptyDetector", getPos ammocrate1, true];
_trg setTriggerArea [5, 5, 0, false];
_trg setTriggerStatements 
	[
		"this",
		"!alive ammocrate1;",
		"task_1 setTaskState 'SUCCEEDED';  player setCurrentTask task_2;  task_1 = true;  publicVariable "task_1";  hint "Operation Success!";"
	];

The trigger part is not yet working though :(
If someone could tell me how to mark the title as solved I would appreciate it!

Share this post


Link to post
Share on other sites

ammocrate1 = "classname_blablubb" createVehicle [0,0,0];

in this example ammocrate1 is the name of the variable which contains the object u created.

 

you can do everything u wanna with it then for example damage it:

ammocrate1 setDamage 0.5;

or give a hint if its destroyed:

 

if(isNull ammocrate1) then {hint "Ammo crate destroyed, mission succeded. Hurra :-)";};

Share this post


Link to post
Share on other sites
ammocrate1 = "classname_blablubb" createVehicle [0,0,0];

in this example ammocrate1 is the name of the variable which contains the object u created.

 

you can do everything u wanna with it then for example damage it:

ammocrate1 setDamage 0.5;

or give a hint if its destroyed:

 

if(isNull ammocrate1) then {hint "Ammo crate destroyed, mission succeded. Hurra :-)";};

Awesome thanks!

So the "classname_blablubb" would be the ammobox classname which I can get form the editor I'm guessing? Also the square brackets is that where I can define pos (like a marker location?)

Share this post


Link to post
Share on other sites

Awesome thanks!

So the "classname_blablubb" would be the ammobox classname which I can get form the editor I'm guessing? Also the square brackets is that where I can define pos (like a marker location?)

 

thats what I meant :-)

  • Like 1

Share this post


Link to post
Share on other sites

So I am having a mission spawn the ammo crate using this in a "mission_1.sqf":

 

waitUntil { !isNil {player} };
waitUntil { player == player };

ammocrate1 = createVehicle ["B_supplyCrate_F",getMarkerPos "cache_1",["cache_2","cache_3"], 0, "NONE"]

switch (side player) do 
{

case WEST: // BLUFOR briefing goes here
{
player createDiaryRecord ["BTA", ["ION Contractors", "Make sure you have all required equipment before heading out such as bandages, ammo, radio and earplugs!"]];

//Task1 - COMMENT
task_1 = player createSimpleTask ["Find The Weapon Cache"]; 
task_1 setSimpleTaskDescription ["Search for the weapon cache at the three locations, then destroy the cache.","Find Cache","Search"]; 
//task_1 setSimpleTaskDestination (getMarkerPos "cache_1");
task_1 setTaskState "Assigned"; 
player setCurrentTask task_1;

//Task2 - COMMENT



};


case EAST: // OPFOR briefing goes here
{ 
};


case RESISTANCE: // RESISTANCE/INDEPENDENT briefing goes here
{ 
};


case CIVILIAN: // CIVILIAN briefing goes here
{ 
};
};

and I can't seem to figure out how to us the above code so I can name the crate, any help?

Share this post


Link to post
Share on other sites

u already have that variable named ammocrate1. i dont understand what else u mean with to name the crate. what exectly do u want to do with that desired name?

edit: u missed a ; at the end of line 4

Share this post


Link to post
Share on other sites

u already have that variable named ammocrate1. i dont understand what else u mean with to name the crate. what exectly do u want to do with that desired name?

edit: u missed a ; at the end of line 4

Oops thanks! Ah it is spawning the crate Im just trying to figure out the best way to make it destroyed/deleted and then trigger the next task. trying to not use modules since the mission is supposed to be a persistant repeating mission on our server.

Share this post


Link to post
Share on other sites

I m not sure if u r aware about locality. If this script is used in Multiplayer then it will spawn 1 crate for each Player who gets the Mission. if there r more Players which should get this Mission at the same time then u have to spawn the crate server side or on 1 client only.

Best solution is to spawn and delete it server side or at headless Client if u use one.

deleting the crate is simple just do

 
deleteVehicle ammocrate1;

Share this post


Link to post
Share on other sites

 

I m not sure if u r aware about locality. If this script is used in Multiplayer then it will spawn 1 crate for each Player who gets the Mission. if there r more Players which should get this Mission at the same time then u have to spawn the crate server side or on 1 client only.

Best solution is to spawn and delete it server side or at headless Client if u use one.

deleting the crate is simple just do

 
deleteVehicle ammocrate1;

Okay, so should I change the start to something like:

 

if (!isServer) exitWith {};

Share this post


Link to post
Share on other sites

No its not that easy. the task should be set on Clients machine.

 

you have to think about every line of the scipt. Ask where should this line be executed and does the machine which executes it know about all objects that r needed for the execution.

 

for example the line

ammocrate1 = "blalaa" createVehicle [pos];

creates the desired object and the object is local on the machine which spawns it.

this machine must know about pos for example.

and after that spawning the variable ammocrate1 is known by this machine only.

if u want to use that variable on other machines then u have to publish it to them with publicVariable or a familiar command.

Also u should learn as much as u can about the command remoteExec because with that u could send "orders" from the Server to the Clients to get some code executed.

 

I think the best way would to start this way. plan your scipt to be executed on Server only and force the Clients to set up the Tasks with remoteExec.

  • Like 2

Share this post


Link to post
Share on other sites

initPlayerLocal.sqf

switch (side player) do 
{
 
case WEST: // BLUFOR briefing goes here
{
player createDiaryRecord ["BTA", ["ION Contractors", "Make sure you have all required equipment before heading out such as bandages, ammo, radio and earplugs!"]];
 
//Task1 - COMMENT
task_1 = player createSimpleTask ["Find The Weapon Cache"]; 
task_1 setSimpleTaskDescription ["Search for the weapon cache at the three locations, then destroy the cache.","Find Cache","Search"]; 
//task_1 setSimpleTaskDestination (getMarkerPos "cache_1");
task_1 setTaskState "Assigned"; 
player setCurrentTask task_1;
 
//Task2 - COMMENT
 
 
 
};
 
 
case EAST: // OPFOR briefing goes here
{ 
};
 
 
case RESISTANCE: // RESISTANCE/INDEPENDENT briefing goes here
{ 
};
 
 
case CIVILIAN: // CIVILIAN briefing goes here
{ 
};
};

initServer.sqf

ammocrate1 = createVehicle ["B_supplyCrate_F",getMarkerPos "cache_1",["cache_2","cache_3"], 0, "NONE"];

That way one box will be spawned at mission start and every player gets his briefing.

  • Like 2

Share this post


Link to post
Share on other sites

Awesome and thank you both!
Say if I didn't want this to all happen at server start but executed by a script that picks a random mission from a list so it could be run on repeat how could I do that?

Share this post


Link to post
Share on other sites

Okay so now I have these 2 scripts:

mission_1.sqf
 

switch (side player) do 
{

case WEST: // BLUFOR briefing goes here
	{
		player createDiaryRecord ["Diary", ["*ION Contractors*", "*Make sure you have all required equipment before heading out such as bandages, ammo, radio and earplugs!*"]];

//Task1 - COMMENT
		task_1 = player createSimpleTask ["Find The Weapon Cache"]; 
		task_1 setSimpleTaskDescription ["Search for the weapon cache at the three locations, then destroy the cache.","Find Cache","Search"]; 
		task_1 setSimpleTaskDestination (getMarkerPos "cache_1");
		task_1 setTaskState "Assigned"; 
		player setCurrentTask task_1;

//Task2 - COMMENT
		task_2 = player createSimpleTask ["Exfil"]; 
		task_2 setSimpleTaskDescription ["Leave area.","Exfiltrate","Exfil"]; 
		task_2 setSimpleTaskDestination (getMarkerPos "cache_3");
		task_2 setTaskState "created"; 

	};


case EAST: // OPFOR briefing goes here
{ 
};


case RESISTANCE: // RESISTANCE/INDEPENDENT briefing goes here
{ 
};


case CIVILIAN: // CIVILIAN briefing goes here
{ 
};
};

and then cache_A.sqf
 

//  Create weapon cache at random marker
ammocrate1 = createVehicle ["B_supplyCrate_F",getMarkerPos "cache_1",["cache_2","cache_3"], 5, "NONE";

//  Create trigger for crate
_trg = createTrigger ["EmptyDetector", getPos ammocrate1, true];
_trg setTriggerArea [5, 5, 0, false];
_trg setTriggerStatements 
	[
		"this",
		"!alive ammocrate1;",
		"task_1 setTaskState "SUCCEEDED";  player setCurrentTask task_2;  task_1 = true;  publicVariable "task_1";  hint "Operation Success!";"
	];

What would the best way to execute these in a repeatable way, it's a persistent mission and the tasks are supposed to pop up randomly.
I did have a read on publicVariable and remoteExec but it's a bit more advanced than my brain can handle this late at night so will have to study that tomorrow.
If you can't or don't feel like explaining how to do this could someone point me to an example that's similar, I learn best from seeing the code structure in action so-to-speak.
I forgot to mention this is in my init.sqf:
 

//Tasks
execVM "scripts\mission_1.sqf";

Temporary of course till I can figure out how to make more missions and then randomly pick one.

Share this post


Link to post
Share on other sites
"cache_A.sqf" remoteExec ["execVM",2];
"mission_1.sqf" remoteExec ["execVM",-2];

That could work.

  • Like 1

Share this post


Link to post
Share on other sites

I think a usual way to achieve random missions is to compile the Mission.sqf files into an Array of variables and then randomly call or spawn that.

 

this I would do in an init script to get an Array of tasks:

fnc_miss_array = []; 
fnc_miss_array pushBack (compileFinal preprocessFileLineNumbers "scripts\mission_1.sqf");
fnc_miss_array pushBack (compileFinal preprocessFileLineNumbers "scripts\mission_2.sqf");
fnc_miss_array pushBack (compileFinal preprocessFileLineNumbers "scripts\mission_3.sqf");
fnc_miss_array pushBack (compileFinal preprocessFileLineNumbers "scripts\mission_4.sqf");

and whereever u want to execute a random Mission script u could do:

[] call (selectRandom fnc_miss_array);
  • Like 1

Share this post


Link to post
Share on other sites
"cache_A.sqf" remoteExec ["execVM",2];
"mission_1.sqf" remoteExec ["execVM",-2];

That could work.

 

Thank you, what is 2 and -2 at end of each line for?

 

 

I think a usual way to achieve random missions is to compile the Mission.sqf files into an Array of variables and then randomly call or spawn that.

 

this I would do in an init script to get an Array of tasks:

fnc_miss_array = []; 
fnc_miss_array pushBack (compileFinal preprocessFileLineNumbers "scripts\mission_1.sqf");
fnc_miss_array pushBack (compileFinal preprocessFileLineNumbers "scripts\mission_2.sqf");
fnc_miss_array pushBack (compileFinal preprocessFileLineNumbers "scripts\mission_3.sqf");
fnc_miss_array pushBack (compileFinal preprocessFileLineNumbers "scripts\mission_4.sqf");

and whereever u want to execute a random Mission script u could do:

[] call (selectRandom fnc_miss_array);

That seems great, is there a way I could make it execute the first selection at server start? for example make it pick one at server start and essentially begin the mission looping at launch and also would this be server/JIP friendly?

Share this post


Link to post
Share on other sites

Thank you, what is 2 and -2 at end of each line for?

 

 

2 means server only

-2 everyone except server

  • Like 2

Share this post


Link to post
Share on other sites

Thank you, what is 2 and -2 at end of each line for?

2 - means it is executed on Server only

-2 - means it is executed evereywhere except the Server.

edit:

R3vo was faster

  • Like 2

Share this post


Link to post
Share on other sites

2 means server only

-2 everyone except server

Oh right, thanks mate!

Edit: but you still answered ;)

Thanks to both of you!

Share this post


Link to post
Share on other sites

you could do that JIP thing with the third element of the array passed the right side of remotexec. you can set that element to e.g. 6789 and every JIP client will execute it.

if the task is completed and a new is started then u can use the same id (6789) to override the old JIP command with the new one. just read the wiki its all described there and examples r included.

  • Like 1

Share this post


Link to post
Share on other sites

you could do that JIP thing with the third element of the array passed the right side of remotexec. you can set that element to e.g. 6789 and every JIP client will execute it.

if the task is completed and a new is started then u can use the same id (6789) to override the old JIP command with the new one. just read the wiki its all described there and examples r included.

Ok mate thanks again!

gonna get some shuteye then hit it again tomorrow.

Thanks to both of you for all of your help :)

Share this post


Link to post
Share on other sites

How do I mark this as solved?

Share this post


Link to post
Share on other sites

Edit the thread title yourself and put: "[RESOLVED] Thread Title"

 

You have to be in the "full editor", edit the OP.

  • Like 1

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

×