timmiej93 Posted August 24, 2014 Report Share Posted August 24, 2014 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 Quote Link to comment Share on other sites More sharing options...
bma Posted August 24, 2014 Report Share Posted August 24, 2014 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 Quote Link to comment Share on other sites More sharing options...
timmiej93 Posted August 24, 2014 Author Report Share Posted August 24, 2014 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. Quote Link to comment Share on other sites More sharing options...
bma Posted August 24, 2014 Report Share Posted August 24, 2014 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 Quote Link to comment Share on other sites More sharing options...
timmiej93 Posted August 24, 2014 Author Report Share Posted August 24, 2014 Good point. It's a bit of curiosity as well, discovering new scripting methods etc.I'll let you know how the multidimensional array worked out. Quote Link to comment Share on other sites More sharing options...
MikeyPI Posted August 24, 2014 Report Share Posted August 24, 2014 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. Quote Link to comment Share on other sites More sharing options...
timmiej93 Posted August 24, 2014 Author Report Share Posted August 24, 2014 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"; }}; Quote Link to comment Share on other sites More sharing options...