Home   Help Search Login Register  

Author Topic: Random base location  (Read 2985 times)

0 Members and 1 Guest are viewing this topic.

Offline SaS TrooP

  • Members
  • *
  • n00b always & everywhere
Random base location
« on: 18 Sep 2009, 18:33:51 »
I am making coop mission where you need to destroy Russian Grad SP RArt. I found 3 good places to put them there with small encampment. But I decided to create a random situation: Grads can be in 1 of those 3 places, but ALL TOGETHER. I dont mean to have one in one place etc. They are all together (under camo nettings, you know). And I dont have an idea how to make this random option in .sqf file. Can you help me?

Offline Rellikki

  • Members
  • *
  • Die-hard OFP player
Re: Random base location
« Reply #1 on: 18 Sep 2009, 18:40:16 »
The simplest way, in my opinion, would be just to place three "Empty" type of markers on the map and group either of the Grads into all of those markers. Then make a script which setPos's the rest of the Grads close to the one which you grouped into the markers, like this:

Code: [Select]
grad2 setPos [(getPos grad1 select 0) +10, getPos grad1 select 1, getPos grad1 select 2];
grad3 setPos [(getPos grad1 select 0) -10, getPos grad1 select 1, getPos grad1 select 2];
camonet1 setPos [getPos grad1 select 0, getPos grad1 select 1, getPos grad1 select 2];

That's just a simple example, which would set the other two Grads 10 meters away from the first Grad, on the both sides of it and would also place a camo netting on top of the first one. :) I hope it helps.
« Last Edit: 18 Sep 2009, 20:54:11 by Rellikki »

Offline SaS TrooP

  • Members
  • *
  • n00b always & everywhere
Re: Random base location
« Reply #2 on: 18 Sep 2009, 20:01:13 »
Hmmm, I don't thing you understand me:
Here is basic screenshot of the idea:



And here is the vety old good one script for OFP :P

Code: [Select]
_x = random 10

?(playercounter<10) : goto "notenough"

?(_x>5) : goto "won"

?(_x<5) : goto "lose"

#won
playercounter=playercounter+20
hint format ["Well done you have won Ł20! you now have a total of Ł%1", playercounter]
exit

#lose
playercounter=playercounter-10
hint format ["You have just lost Ł10, better luck next time.(Ł%1 left)", playercounter]
exit

#notenough
hint "sorry you do not have enough to gamble Ł10"
exit

I cant understand how this exactly works. I thought about moving this script to .sqf and modify it. But I dont now how to do that

Offline Rellikki

  • Members
  • *
  • Die-hard OFP player
Re: Random base location
« Reply #3 on: 18 Sep 2009, 20:50:41 »
I do believe I did understand you perfectly. Of course it could be done with such a script as you posted, it would probably even be more practical that way, but unfortunally I'm not really into SQF so I can't help you. But the way I described should work as good too - By grouping a vehicle into different markers, it will every time start at a different location at the position of those markers. And by re-positioning the other vehicles close to the one which would have a random location, it should work as good. Try it out. ;)
« Last Edit: 18 Sep 2009, 20:54:00 by Rellikki »

Offline SaS TrooP

  • Members
  • *
  • n00b always & everywhere
Re: Random base location
« Reply #4 on: 20 Sep 2009, 20:17:37 »
Now I probably got you, but in this case I need to random the markers, so its still a deep shit ;/

Offline sardaukar17

  • Members
  • *
Re: Random base location
« Reply #5 on: 27 Sep 2009, 02:21:35 »
I set something up using start point instead of base locations but it could be modified easily. I'll post the part that makes it possible. It is very similar to what you are doing with the Random command.
Code: [Select]
#StartPointMaster
_rand = random 3
_num = _rand - (_rand mod 1)

?(_num==0):goto "Start1"
?(_num==1):goto "Start2"
?(_num==2):goto "Start3"

The Random command randomly chooses a number between 0 and the number you choose . Here I chose 3. This means random will chose any number between 0-3. Now these numbers do not equal simple whole numbers. It could choose 1.323 or 0.934. That is the reason for the next line.
Code: [Select]
_num = _rand - (_rand mod 1)
This line if I remember correctly subtracts any decimal points from the number chosen. So if Random chose 1.334. The mod line will subtract .334 to make the number 1. Anyway thats all not very important. The point is those 2 random lines choose a random number between 0 and the number you enter -1. Thus since I choose 3 it will pick a number between 0-2 making the next 3 lines possible.

Code: [Select]
?(_num==0):goto "Start1"
?(_num==1):goto "Start2"
?(_num==2):goto "Start3"
Once the number is picked randomly it chooses a start position to go to. All you need to do is fill in the information for each start position. The whole thing would look something like this:
Code: [Select]
#StartPointMaster
_rand = random 3
_num = _rand - (_rand mod 1)

?(_num==0):goto "Start1"
?(_num==1):goto "Start2"
?(_num==2):goto "Start3"

#start1
Vehicles setpos (getpos Start1Loc);


#start2
Units setpos (getpose Start2Loc)

#start3
Buildings setpos (getpos Start3loc)
I am just filling in example lines. they could be object creation lines or whatever you want. For the reference to each location I would use GameLogics or Markers for each. Hence the Start1loc. If they were markers the line would be
Code: [Select]
Vehciles setpos (getmarkerpos "Start1loc")

Offline Trexian

  • Members
  • *
Re: Random base location
« Reply #6 on: 28 Sep 2009, 20:26:50 »
Here's how I would do it.  This example is untested, but I regularly use the ideas.

First, in the markers that you place, name them Spot1, Spot2, and Spot3.

Then, in your mission init, something like:
Code: [Select]
private ["_list", "_spot", "_pos", "_loc", "_dir", "_spawn1", "_spawn2", "_spawn3"];

waituntil {!isnil "bis_fnc_init"}; // this is necessary to make sure the functions you use later are initialized

_list = [Spot1, Spot2, Spot3];

_spot = _list call BIS_fnc_selectRandom; // this randomly selects 1 of the 3 elements

_pos = getMarkerPos _spot; // this gets the location of the chosen marker

// spawn 1st grad
_loc = _pos findEmptyPosition [20, 100, "GRAD_RU"]; // this will find an empty spot the size of the Grad within 100m of the marker
_dir = random 360; // random direction

// spawnVehicle spawns the vehicle and a crew
_spawn1 = [_loc, _dir, "GRAD_RU", East] call BIS_fnc_spawnVehicle;

// spawn 2d grad
_loc = _pos findEmptyPosition [20, 100, "GRAD_RU"];
_dir = random 360;
_spawn2 = [_loc, _dir, "GRAD_RU", East] call BIS_fnc_spawnVehicle;

// spawn 3rd Grad
_loc = _pos findEmptyPosition [20, 100, "GRAD_RU"];
_dir = random 360;
_spawn3 = [_loc, _dir, "GRAD_RU", East] call BIS_fnc_spawnVehicle;


If you wanted to get tricky, you could also spawn a protective group of guards. ;)
Sic semper tyrannosauro.