Jump to content
Sign in to follow this  
daimyo21

Cant get random script I wrote to work.

Recommended Posts

So I though random X would be super simple but holy hell this is frustrating.

Anyways, I first tried random 3; then if (1)... if (2)... if (3)... etc but no luck. Heres what I got so far by looking around;

_unit = _this select 0;
_caller = _this select 1;
_id = _this select 2;
_params = _this select 3;

_counter = (random 3);
_counter != 0;
if (_counter = 1) then {
_ok = [_caller,'data\sackfood1.paa',"Sack of food","SOF","Eat sack of grains","example_scripts\eat_food.sqf","SOF",""] call TBR_inventory_add;
deletevehicle cursortarget;


} else {
exitwith;
};

if(_counter = 2) then {
_ok = [_caller,'data\FruitfoodB.paa',"Fruit","BAN","Eat Bananas","example_scripts\eat_food.sqf","BAN",""] call TBR_inventory_add;
deletevehicle cursortarget;

} else {
exitwith;
};

if (_counter = 3) then {
_ok = [_caller,'data\cannedfood2.paa',"Canned food","CF2","Eat canned food","example_scripts\eat_food.sqf","BAN",""] call TBR_inventory_add;
deletevehicle cursortarget;
} else {
exitwith;
};

if(_ok) then { 
_unit removeaction _id 
} else {
_caller sidechat "Uhhh... my pockets are full";
};

Share this post


Link to post
Share on other sites

Use switch. Something like this...

_counter = [url="http://community.bistudio.com/wiki/ceil"]ceil[/url] (random 3);

switch (_counter) do {
  case 1: {[i]....code here[/i]};
  case 2: {[i]... code here[/i]};
  case 3: {[i]....code here[/i]};
};

Share this post


Link to post
Share on other sites

Also, Random will almost always return a decimal. because random 3 will more than likely return 1.3345 or 2.8943 , etc...

thats probably why yours is not working

1.3547 != 1

to stop this use the floor or ceiling commands

ie. like this:

_counter = (floor(random 3)); 

Share this post


Link to post
Share on other sites

Appreciate the feedback.. I got something similar to twirly after searching a bit and failing at scripting.

Btw what is the alternative to goto "blahblah"; for SQF???

I want to be able to jump to the end of a script or to different parts of it.

Share this post


Link to post
Share on other sites

there is no goto in sqf, nearest alternative is exitWith {_null = [something] execVM "another_script.sqf"};

sqf is conditions based, wich skips or executes codes dependig on condition.

you can also define "scripts_snippets" within the script and use spawn or call to run them if condition is fullfilled, or if no condition at all.

Best advice to learn sqf is to open up sqf scripts posted by community and look at how and why they have done what ever is in that script, start small, advance as you learn more and more.

Most if not all commands will work in sqf, its just the difference of using loops with conditions instead of goto.

Someone else can probably give a much better explanation on it than me.

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  

×