Jump to content
Sign in to follow this  
VonNexus

Problem with a .sqf script

Recommended Posts

Heya,

basically I've got a guy tied up in a depot wich I called hostage1. What I want to do is displaying a hint when a player is at least at 5 meters from him. I could do it via trigger, but I've got the editor full of them so I'm trying to execute this using a basic .sqf script (those things with if, while, do, else). I've read some guides but still didn't figure out how to accomplish a basic .sqf script. This is what I tried to use

_unit=_this select 0;
_hostage1=_this select 1;


if (_unit distance _hostage1 > 5) then {hint "You found the hostage!"}; 

It seems right to me, but doesn't work. I tried to exec it in a trigger and even in the init but it just won't work. So what is wrong?

Share this post


Link to post
Share on other sites

I like to use scopeName and breakOut for stuff like this. I am sure there are other ways to do it, but here's how I would write it:

_unit = _this select 0;
_hostage1 = _this select 1;


scopeName "main";
while {true} do{
if (_unit distance _hostage1 < 5) then {
hint "You found the hostage!";
breakOut "main"
};
};

Also from what you've written you want to use

[b]_unit distance _hostage1 <= 5 [/b] 

instead of

_unit distance _hostage1 > 5

Edited by trini scourge

Share this post


Link to post
Share on other sites
_unit=_this select 0;

_hostage1=_this select 1;

if (_unit distance _hostage1 > 5) then {hint "You found the hostage!"};

Your script does't work because it have not a check

in edit the trigger is check continuous so just insert:

_unit=_this select 0;

_hostage1=_this select 1;

while {true} do{

if (_unit distance _hostage1 < 5) then {

hint "You found the hostage!";

sleep 1;

};

however it's always better to insert a pause in a check with the comand: sleep x

blue = < (lower to)

green = check loop

red = variable (waiting in seconds)

Edited by maxjoiner

Share this post


Link to post
Share on other sites

_unit = _this select 0;
_hostage1 = _this select 1;

WaitUntil {sleep 1; _unit distance _hostage1 < 5};

hint "You found the hostage!";

Better i think :)

Share this post


Link to post
Share on other sites

Where do I put the exec command for the script? And has it to be a nul=[] execVM "filename" or a simple this execVM "filename"?

Your script does't work because it have not a check

in edit the trigger is check continuous so just insert:

_unit=_this select 0;

_hostage1=_this select 1;

while {true} do{

if (_unit distance _hostage1 < 5) then {

hint "You found the hostage!";

sleep 1;

};

however it's always better to insert a pause in a check with the comand: sleep x

blue = < (lower to)

green = check loop

red = variable (waiting in seconds)

Share this post


Link to post
Share on other sites
_unit = _this select 0;

_hostage1 = _this select 1;

WaitUntil {sleep 1; _unit distance _hostage1 < 5};

hint "You found the hostage!";

Better i think

right friend!

that is another method!

@VonNexus can recall the script with a trigger with in its onact: nul=[] execVM "nameofscript.sqf"

or

waypoint (the same)

or

create game logic in its init:

nul=[] execVM "nameofscript.sqf"

Share this post


Link to post
Share on other sites

Yep! But this:

while {true} do{
if (_unit distance _hostage1 < 5) then {
hint "You found the hostage!";
sleep 1;
};

it's a loop with no end :)

Share this post


Link to post
Share on other sites

I actually used Giallustio's code, called the file hostagearea.sqf. Then I created a game logic and put the maxjoiner's code in the init, but when I get close to the hostage no hint is displayed.What is the problem?

Share this post


Link to post
Share on other sites
I actually used Giallustio's code, called the file hostagearea.sqf. Then I created a game logic and put the maxjoiner's code in the init, but when I get close to the hostage no hint is displayed.What is the problem?

Put this as your script:

_unit = _this select 0;
_hostage1 = _this select 1;


scopeName "main";
while {true} do{
if (_unit distance _hostage1 < 5) then {
hint "You found the hostage!";
breakOut "main"
};
};

then in the Act of your trigger put this: null = [rescuingUnit,hostageUnit] execVM "hostageRescue.sqf"

Of course 'rescuingUnit' and 'hostageUnit' will be the names of those units in the editor.

Share this post


Link to post
Share on other sites

You have to define _unit and _hostage1.

So when you launch the script you have to do something like this:

_script = [player,hostage_name] execVM "file.sqf";

Share this post


Link to post
Share on other sites
You have to define _unit and _hostage1.

So when you launch the script you have to do something like this:

_script = [player,hostage_name] execVM "file.sqf";

I actually use this code with player and hostage name (ostaggio1) and I renamed the .sqf files. It's like null = [player,ostaggio1] execVM "h1.sqf". However it still won't work.

Share this post


Link to post
Share on other sites

Ok, where do you write:

null = [player,ostaggio1] execVM "h1.sqf"

Cosi ci capiamo meglio? :)

Share this post


Link to post
Share on other sites

In a trigger activated by Civilian, its area covers the place where the hostage is (of course the hostage is a civilian)

Ok, where do you write:

null = [player,ostaggio1] execVM "h1.sqf"

Cosi ci capiamo meglio? :)

Share this post


Link to post
Share on other sites

Now it works! Last question: after the script of the hostage , can I write something like "Ostaggisalvati=true" so I can use "Ostaggisalvati=true" as a trigger condition?

Well...Put the code in your init.sqf, it's better :)

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  

×