Jump to content
Sign in to follow this  
tryteyker

Couple of problems with randomization and variables

Recommended Posts

Hey,

so I'm kind of stuck at doing a couple of really really simple things.

First of all, I want to randomize the appearance of soldiers. By that I mean that I have 3 soldiers, and one of these 3 soldiers should spawn each time the mission starts.

I could probably do this by simply placing a marker on the ground and create them on mission start, but since I'm not familiar with that I don't even want to try it out right now.

Currently, I'm doing it by placing 3 units in the editor, each unit has basically the same probability of presence (around 50%), and in the condition checks of one of the other units is alive.

(!alive unit1) AND (!alive unit2)

This is what I'm using in this case. And I guess that's far from right, because none of them spawns at mission start now. It's not giving me any specific errors though.

Another problem I currently have is with a really simple script. I have an array, removeAction and then I try to use setDamage with an array. I know that doesn't work, since it's giving me errors.

I'll post the script down below:

_unit = ["machinegunner", "gunner1", "gunner2"];

player removeaction ID;

_unit setDamage 1;

player setcaptive false;

Its giving me an error at "_unit setDamage 1;". Question here is, what do I use instead of setDamage? This gets triggered once I use the action, obviously.

Thanks for the help in advance.

Share this post


Link to post
Share on other sites

If all the guys are the same unit just use markers. Place the guy in one place, put markers in the two other spots and group the guy with the markers. He'll show up either were you put him or at one of the other markers.

The setDamage isn't working because setDamage works on and object and you've assigned _unit as an array of strings. Are you trying to allow a player to kill all three units at once, then lose his captive status? If so:

Player init:

player addAction ["Drop stealth but kill three dudes", "kill3dudes.sqf", [machinegunner1, gunner1, gunner2]];

kill3dudes.sqf:

_player = _this select 1;
_action = _this select 2;
_units = _this select 3;

_player removeAction _action;

{_x setDamage 1} foreach _units;

_player setCaptive false;

This assumes you've named your units machinegunner, gunner1 and gunner2 in their Name fields.

Share this post


Link to post
Share on other sites

No, what I am trying to do here is the following:

The player spawns as a hostage, and to his right is one of the units in the array _unit. Which one of these units spawn has to be decided somehow (this is where I need help). When executing the action I want the script to check which unit is spawned and then kill the unit that's spawned.

Share this post


Link to post
Share on other sites

I'm still confused why this guy is random? So you want a random guard always in the same place? Or random weapons on the one guard with the hostage?

Share this post


Link to post
Share on other sites

I have 3 units. One Machinegunner, one guy with an AA gun, and one with an AT gun.

I basically choose them randomly so it's basically more of a challenge to get out there. (As in, if you have the AA guy, you're lucky since you can shoot the helicopter patrolling the town, if you have the Machinegunner, you can fight against the infantry, and if you have the rifleman it gets a bit tougher)

The script should choose one of the units from an array and spawn the unit on the same place. (Basically random guard in the same place as you mentioned before)

Share this post


Link to post
Share on other sites

_unit2spawn = _units select floor(random(count _units));

_unit2spawn will be a random selected unit from the _units array.

Share this post


Link to post
Share on other sites

Thanks for that. It still doesn't work though, not giving me any errors though.

Code looks like this:

_grpAlpha = group rifleman;

_units = ["RU_Soldier_AA","MVD_Soldier_MG","MVD_Soldier_Sniper"];

_unit2spawn = _units select floor(random(count _units));

// _unit2spawn will be a random selected unit from the _units array. 

_unit2spawn createunit [getMarkerPos "Spawn",_grpAlpha,"machinegunner = this"];

Seems like he doesn't recognize _grpAlpha, because the marker exists. Any ideas? ;o

Share this post


Link to post
Share on other sites

Try the createUnit line like this... using createUnit array.

machinegunner = _grpAlpha createUnit [_unit2spawn, getMarkerPos "Spawn", [], 0, "FORM"];

Edited by twirly
Clarity

Share this post


Link to post
Share on other sites

Seems like he doesn't recognize _grpAlpha, because the marker exists. Any ideas? ;o

Create a group first:

_unit2spawn = _units select floor(random(count _units));

_grpAlpha = createGroup east;

_unit2spawn _unitArray select floor(random(count _unitArray)) createUnit [getMarkerPos "Spawn", _grpAlpha, "machinegunner = this", 1, "PRIVATE"];

I can't remember if you still need to have a unit placed somewhere on the map before being able to spawn, if it dont work then try that.

Share this post


Link to post
Share on other sites

I kinda hate myself right now for forgetting the most obvious detail in the whole thing.. I didn't put the script in the init.sqf....

Anyway, I tried twirly's method and it works just fine, thanks for your help.

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  

×