Jump to content
timmiej93

Random parking spot selection

Recommended Posts

Hey guys,

 

I'm trying to come up with a scripting method to have a script park cars randomly on a set number of parking spaces.

Now this isn't the hard part. The hard part, is making sure the script understands when a parking space is filled. This is quite easy when there is a set parking order, since you can go down the list. When going random, it gets had.

I've been able to think of one way to do it, but it requires ridiculous amount of code:

 

Script out all possible options: Something like: if parking spot 3, 5 and 7 are occupied, park in one of these (with a list of spots 1, 2, 4, 8, 9 and 10 or something).

This should be done for every single option then, and that does not appeal to me one bit.

 

Does anyone know a different way to do this?

Could it be possible to use an array with two columns, with column 1 being the data you need, and column 2 containing a 0 or a 1, depending if a car is parked on that spot.

 

Tim

Link to comment
Share on other sites

Hey guys,

 

I'm trying to come up with a scripting method to have a script park cars randomly on a set number of parking spaces.

Now this isn't the hard part. The hard part, is making sure the script understands when a parking space is filled. This is quite easy when there is a set parking order, since you can go down the list. When going random, it gets had.

I've been able to think of one way to do it, but it requires ridiculous amount of code:

 

Script out all possible options: Something like: if parking spot 3, 5 and 7 are occupied, park in one of these (with a list of spots 1, 2, 4, 8, 9 and 10 or something).

This should be done for every single option then, and that does not appeal to me one bit.

 

Does anyone know a different way to do this?

Could it be possible to use an array with two columns, with column 1 being the data you need, and column 2 containing a 0 or a 1, depending if a car is parked on that spot.

 

Tim

 

Give the parked cars a dummy called DUMMY_Parked01 ... _Parked10. 

And then make the script generate a random number between 1 and 10. Then check if any cars on the map has the dummy. If there is one, make it try again, else give it the dummy :)

Link to comment
Share on other sites

Yeah I've been thinking about something like that, but look at it like this:

You've got 10 parking spaces. 9 are occupied.

The chance that last parking spot number gets hit in the random number generation, is about 10%. That would mean the script would run approx 10 times before it can park. I don't know about you, but that sounds like a lot of memory usage to me, especially in EM4. I'm just about to set up a small test with a multidimensional array. Let's see how that works out.

Link to comment
Share on other sites

That is true :)

But then again, how much memory does it take to generate a number and check for a dummy command?

There is a lot of scripts that run constantly in the background. Bma, water tank ect :)

Link to comment
Share on other sites

Checking the dummy is the easiest way to have it know if the spot is occupied, the key is that if a spot is occupied it goes to the else of x y z for the parking spaces... Eventually all of them will be filled but bma is correct there are plenty of full-time running scripts, the key is to have them checking a limited pool of objects...  If you have it checking for 50 objects that will certainly bog a system.  Having 10 or so isnt outside the realm of loading down a system.

Link to comment
Share on other sites

Well I guess I have no choice..

 

I've created below script to test if the MD array works, but when adding this to a control panel or a vehicle, it causes the game to freeze after a few seconds, without any error.

In my eyes this script should work, but maybe one of you sees a flaw in it.

 

const char *TestPool [2][2];object Test : CommandScript{	Test()	{	}	bool CheckPossible(GameObject *Caller)	{		return true;	}	bool CheckTarget(GameObject *Caller, Actor *Target, int childID)	{		return true;	}	void PushActions(GameObject *Caller, Actor *Target, int childID)	{		TestPool[0][0] = 0;		TestPool[0][1] = 1;		TestPool[1][0] = 2;		TestPool[1][1] = 3;		if(TestPool[0][0] = 0)			Mission::PlayHint "0,0 = 0";			System::Log "0,0 = 0";		if(TestPool[0][1] = 1)			Mission::PlayHint "0,1 = 1";			System::Log "0,1 = 1";		if(TestPool[1][0] = 2)			Mission::PlayHint "1,0 = 2";			System::Log "1,0 = 2";		if(TestPool[1][1] = 3)			Mission::PlayHint "1,1 = 3";			System::Log "1,1 = 3";	}}; 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...