Jump to content
Sign in to follow this  
scottdog62

beginer scripting help

Recommended Posts

Trying to learn scripting

Made a very simple script, one thing that is happening is its not being activated, only if I put a sleep command before it and activate in that time, I want it to be activate-able at any time in the mission.
 

_target = BOB;
_runner = jim;
_begger = greg;




if (!alive _target) then 
{
	 hint "bob is dead"; 
	_runner globalchat "bob is dead good job"; 
	_runner doMove (position player);
	sleep 3;
	hint "jim is a traitor";
};



if (!alive _runner) then 
{
	hint "jim is dead";
	sleep 3;
	_begger globalchat "please have mercy";
};

if (!alive _begger) then
{
	
	_begger globalchat "Nooooooooo";
	hint "good job";
};



 

Share this post


Link to post
Share on other sites

We have to guess the answers to these questions?

  1. Where do you put this code?
  2. How do you run this code?
  3. Which errors occur during execution?

Share this post


Link to post
Share on other sites

Hey yeah sorry for the lack of information.

1) It is the init.sqf in my mission.
2) so it triggers on start up

 

3) so what i want is that when the conditions are met I want them to activate. So say when I kill "target" I want it to "hint "bob is dead"."
At the moment it runs through all the code, so when i kill target it doesn't activate the hint's and other commands. I want the way so that it activates once i kill target, ect.

Share this post


Link to post
Share on other sites

This should do the trick, if I understood right:


_wait = [] spawn {
	

	_target = BOB;
	_runner = jim;
	_begger = greg;



	waitUntil {!alive _target OR !alive _runner OR !alive _begger};

	if (!alive _target) exitWith 
	{
		 hint "bob is dead"; 
		_runner globalchat "bob is dead good job"; 
		_runner doMove (position player);
		sleep 3;
		hint "jim is a traitor";
	};



	if (!alive _runner) exitWith 
	{
		hint "jim is dead";
		sleep 3;
		_begger globalchat "please have mercy";
	};

	if (!alive _begger) exitWith
	{
		
		_begger globalchat "Nooooooooo";
		hint "good job";
	};

};

 

Cheers

  • Like 1

Share this post


Link to post
Share on other sites
39 minutes ago, scottdog62 said:

Hey yeah sorry for the lack of information.

1) It is the init.sqf in my mission.
2) so it triggers on start up

 

3) so what i want is that when the conditions are met I want them to activate. So say when I kill "target" I want it to "hint "bob is dead"."
At the moment it runs through all the code, so when i kill target it doesn't activate the hint's and other commands. I want the way so that it activates once i kill target, ect.

 

I see two problems:

  1. Code of your script can executing before BOB, jim and greg variables gets initialized. In most cases you need for delay at begin of init.sqf
  2. Your code executes once, while  you need to check for conditions continously all the time (as GrumpyOldMan already found above)

 

//delay in init.sqf
waitUntil {time > 0};

// other code here

 

Share this post


Link to post
Share on other sites

Based on Grumpy Old Man variant:

waitUntil {time > 0};

private _target = BOB;
private _runner = jim;
private _begger = greg;

while {true} do {
	if (!alive _target) exitWith 
	{
		 hint "bob is dead"; 
		_runner globalchat "bob is dead good job"; 
		_runner doMove (position player);
		sleep 3;
		hint "jim is a traitor";
	};
	if (!alive _runner) exitWith 
	{
		hint "jim is dead";
		sleep 3;
		_begger globalchat "please have mercy";
	};
	if (!alive _begger) exitWith
	{
		_begger globalchat "Nooooooooo";
		hint "good job";
	};
	sleep 1; // important pause
};

Share this post


Link to post
Share on other sites

hey thanks for the help, getting more of a grasp of how things work.

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  

×