|
Post by Jagged Steel on May 4, 2014 16:46:00 GMT 1
I have been washing around an idea for a Multiplayer map where air power or extra air power will be granted to the side holding a certain area or building. The idea being that there would be something like an airfield in the middle, and holding it would give you not only flag points but air power as well. My .lua-foo is pretty weak, I know how to call reinforcements and such, change the weather, etc. , but I have never tried doing any of the area scripts, and I know that you guys who make all of these fancy single player missions do a lot of this sort of thing for various triggers. How should I go about this? Do I define an area and then check what is in it? What about defining a certain building that would have to be occupied (and thus intact)? Thanks in advance for helping me out on this.
|
|
|
Post by Major Pain on May 4, 2014 19:43:54 GMT 1
Most likely the best way is to create map location around the airfield. Then you can check which player's units occupy it. That would enableaviation for that player; you could even limit which type of aircraft are available.
I'm sure someone already has a script for this...
|
|
kaoz
General
inter faesces et urinam nascimur
Posts: 1,112
|
Post by kaoz on May 5, 2014 11:58:32 GMT 1
Try out if this works:
function Airfield_Check() if (GetNUnitsInArea(0, "Airfield") > 0) then EnableAviation(0, -1); DisableAviation(1, -1); Suicide(); elseif (GetNUnitsInArea(1, "Airfield") > 0) then EnableAviation(1, -1); DisableAviation(0, -1); Suicide(); elseif ((GetNUnitsInArea(0, "Airfield") == 0) and (GetNUnitsInArea(1, "Airfield") == 0)) then DisableAviation(0, -1); DisableAviation(1, -1); Suicide(); end; end;
There's only party 0 and 1 in this example. I'm not entirely sure that elseif can be used more than once. I've never used it on 3 choices before...
|
|
|
Post by Jagged Steel on May 5, 2014 16:05:32 GMT 1
Thank you for the help Kaoz. I checked and you can use elseif multiple times in one function string. For future reference, here is a fairly good (I think) walkthrough of basic .lua statements, although I noticed logic flaws in at least one of his examples. For my purposes there will be only 2 players, so your example works in that respect. Question: If I use the function you posted, will that disable air as the default? I know it looks like it will, but I have not done this before and I want to make sure. As an example, lets say the game starts and no one is occupying the airfield. Neither player should have air. When one side or the other gains control of the airfield it then enables air for that player. Question 2: Do I need to call this block in a "RunScript" , or will it run every cycle of the script on it's own? Question 3: What about situations where both players have units within the "Airfield" area? In this case I think neither player should have air. Do I need to construct another check within that function block for this? I think this is the case, so is this the proper way to do that? elseif ((GetNUnitsInArea(0, "Airfield") > 0) and (GetNUnitsInArea(1, "Airfield") > 0)) then DisableAviation(0, -1); DisableAviation(1, -1); Suicide(); Question 4: I might want to require that a building be occupied ( think control tower) to enable air. This should do away with having to check if both sides have units in the area, since only one side can occupy a building at any given time. I have checked some scripts that require occupation of a certain building (area) and also check that the building is intact to enable certain reinforcements. Here is a snippet from a script that does just that : if (GetNUnitsInArea(m, "office_3") > 0) and (GetObjectHPs(3000) > 100 ) then execute whatever event you want to enable.
This code is from one of the most complex scripts I have ever seen, and he is using a variety of variables, but what I am looking at is the basic check of the area defined as area "office_3" which is the footprint of a building with script ID 3000 and also the check of that buildings hitpoints. Also, is the hitpoint value of a building that is less than 100 considered destroyed? Is this how I should write a string to do this?: if (GetNUnitsInArea(0, "Airfield") > 0) and (GetObjectHPs(3000) > 100 ) then EnableAviation(0, -1); DisableAviation(1, -1); Suicide(); And the other check strings in that block would include the same "and" check of the buildings hitpoints. I am certain I will have more questions about this, so please bear with my ignorance of scripting. I think making a repository of some script blocks to perform certain functions relating to multiplayer maps might be in order to help folks create better scripted multiplayer maps, as most of them have only the very crudest reinforcement functions. P.S: I noticed in this example I made that I had put a space after "100". I am assuming that this would screw things up, correct? if (GetNUnitsInArea(0, "Airfield") > 0) and (GetObjectHPs(3000) > 100 ) then EnableAviation(0, -1); DisableAviation(1, -1); Suicide(); Also: It has been a long time since I have done any of this, and I can not remember what is the preferred program to edit .lua files. I am using notepad at the moment. I know there is a way to run the script to check for errors, but I do not recall the particulars of how to do this either.
|
|
|
Post by altheogre on May 5, 2014 17:50:32 GMT 1
|
|
|
Post by Jagged Steel on May 5, 2014 18:11:45 GMT 1
Got it, thank you Al. I remember Scite now, and I see some old versions of it in my BK stuff folders.
I do not see an option to run the file anywhere on the Scite menu. Am I missing it or will it not run the script?
Edit to add: I see "Go" And "Compile" in the tools. Both of these seem to run the script, which one should I use to check for basic script errors?
Edit again: I think it is not running the script. Here is the message I get in the Scite info box on the right when using Go or Compile with .lua scripts that I know function perfectly:
>luac5.1 -o "this_is_afrika_v03.luc" "this_is_afrika_v03.lua" 'luac5.1' is not recognized as an internal or external command, operable program or batch file. >Exit code: 1
I selected .lua as the language. Am I missing something here?
|
|
|
Post by keepitsimple on May 5, 2014 20:08:45 GMT 1
Hi JS,
The tool only makes editing more simple because it shows if you go a valid command. There is no complying necessary, this is done (I assume) by the BK engine.
With regard to your problem I would do the following:
Start with an initial
DisableAviation(0, -1); DisableAviation(1, -1);
function Airfield_Check()
local num1=GetNUnitsInArea(0, "Airfield"); local num2=GetNUnitsInArea(1, "Airfield");
if (num1> 0) and (num2==0)) then EnableAviation(0, -1); RunScript("Disable1",3000); Suicide(); elseif ((num1==0) and (num2>0)) then RunScript("Disable2",3000,1); EnableAviation(0, -1); Suicide(); end; end;
Ones a party has taken the airfield you want to stop his air-support ones the other party also is at the airfield. Then you want again give are support to player that holds the airfield solo (and of course lose it again etc).
function Disble1() local num2=GetNUnitsInArea(1, "Airfield"); if (num2> 0) then DisableAviation(0, -1); RunScript("Airfield_Check", 3000); Suicide(); end; end; It might be that this does not work. It seems that if the player has an airplane in the air while the command DisableAviation(0, -1); is give than it is ignored (in single maps). Test it. If it doesn't work as planned then try this:
function Disable1() local num2=GetNUnitsInArea(1, "Airfield"); if (num2> 0) then SwitchWeather(1); RunScript("NoAirForce1", 80000); <-- This most be time it takes for the air support to return home (with large maps this can take more time) Suicide(); end; end;
function NoAirForce1() local num2=GetNUnitsInArea(1, "Airfield"); DisableAviation(0, -1); SwitchWeather(0); RunScript("Airfield_Check", 3000); Suicide(); end; end;
|
|
|
Post by Jagged Steel on May 5, 2014 21:27:40 GMT 1
Good point about the aircraft already in flight issue, KIS. I like the fix using a storm to call home aircraft, I think that might work for what I envision for this map. I am also thinking that I will change the scenario slightly and give each side an airfield, and to not include the function of disabling air if the opponent has a unit anywhere on your airfield, that might be too easy. I think the simplest option is to require at least 1 infantryman in the "tower" and that the tower be intact to enable air. Destroying the tower would cause it to rain for 1 rain cycle , and would give the offended side a small amount of time to repair his tower and re-man it before his opponent was able to utilize his advantage. If he did not have a repair truck or it was far away he would then be eeled and not be able to call air support. I don't recall how long 1 rain cycle is, but I do remember that when you change weather it comes back to sunshine after x amount of time. I searched through the buildings in vanilla and the best option to represent a control tower is the wooden watchtower. I guess this is good enough to represent a crude tower on a forward airstrip. If a player has his air disabled, and then it is enabled again, what does this do to his aircraft roster? Does it refresh the whole count of aircraft? Or, does the amount of each aircraft he had remaining when he lost airpower remain? Not sure why the new Scite is not running .lua scripts. I thought I had an old version, but when I looked it was only an empty folder. I looked and found another .lua editor called "ZeroBrane", which works as well and runs the .lua scripts just fine to test for bugs. Click here to download ZeroBrane Edit to add: I think it will require using a variable to make it rain for only 1 cycle. I know the following is not correct .lua code, but in principle I think this is what needs to happen to have a continuous check for enable/disable airpower conditions while the airpower has been disabled and not have it keep raining continuously. Both players would have air enabled and their tower intact and manned at start. At start set variables A and B to 1. I think I could leave them null, but I like the idea of using 1 as the number for Enabled air rather than the opposite. VarA=1 VarB=1 Define Player 0 and 1 control towers as script id 1000 and 2000 in the map editor. Define area "Airfield1000" and "Airfield2000" for the two areas where the watchtowers are in the editor. The check to see if air is to be disabled for player 0 would be something like this: if VarA=1 and (GetNUnitsInArea(0, "Airfield1000") = 0) or (GetObjectHPs(1000) <= 100) then DisableAviation(0, -1); SwitchWeather(1); VarA=0; Suicide(); If triggered it would disable air for Player0 and rain once and then not trigger this string again until air has been reinstated and then the conditions to remove it have been met again. The check to see if airpower for Player 0 will be reinstated would be like this: if VarA=0 and (GetNUnitsInArea(0, "Airfield1000") > 0) and (GetObjectHPs(1000) > 100) then EnableAviation(0, -1); VarA=1; Suicide(); This is assuming that 100 is the threshold amount of HPs for the watchtower to be intact, which I am not sure about. Is zero HPs the actual threshold for a building to be intact?? What say ye scripters? Does this sound like a solid way to do what I want? Edit again: Now that I have looked at this I can see a potential hole in this system that could be exploited by a player. If a player was being overwhelmed by his opponents airpower he could simply remove all men from his control tower and it would then rain and all aircraft would go home, at which point he could re-man his tower and get his air back. To make this a truly solid non-exploitable function might take a little bit fancier scripting than this. Or of course maybe the answer would be to have air being disabled permanently if the "tower" were destroyed or not manned. In that case I might want a stronger building than a watchtower which can be knocked out very easily. I do like the option of repairing and re-manning the tower to regain airpower a lot better though.
|
|
kaoz
General
inter faesces et urinam nascimur
Posts: 1,112
|
Post by kaoz on May 5, 2014 23:29:50 GMT 1
My post was a bit in a haste and not complete. It was supposed to put you in the direction. I see KIS has shown in better detail. Altho' i've used variables, i do not master them.
|
|
|
Post by Jagged Steel on May 5, 2014 23:44:07 GMT 1
You got me going in the right direction Kaoz, and Kis' point about air not being disabled if that player currently has aircraft in the air got me to thinking about some of the details about how to implement something like this. Now that I am looking at the problems of each player having his own airstrip the idea of having a single central one that belongs to one player or the other might be the easier option. I am just trying to breathe some new life into the regular stale old BK Multiplayer scripts which generally consist of a series of timed reinforcements and nothing else. Others have a factory type of reinforcement system built in where you get reinforcements based on having a certain building occupied or such. By far the most elaborate method for doing this that not only has factory type reinforcements , it also is scripted to let the partner of a 2v2 team who has had his partner drop from the game to continue to receive his now gone partners reinforcements. Check out the .lua for "This is Africa" by Landser. Download it here. His variable system is extremely elaborate.
|
|