|
Post by [BMG]Neutro on Dec 1, 2017 11:42:14 GMT 1
Hello i need some help with Lua commands. i cant find a command to change the artillery shell type from explosive to smoke. i want to use it for a smoke barrage with the command supressive fire.
and the second one is: i have a building with 50% health i wanna keep it at 50% at anytime so that the building cant be destroyed completly. is this possible to give a unit HP Points if his HP points get under a 50% for example
Chris
|
|
|
Post by Quintaxel on Dec 1, 2017 12:42:28 GMT 1
Contrary to Calvin's Lua guide it's not possible, at least as far as I know, to change the shell type from explosive to smoke through Lua script. You could create units that have smoke shells as primary ammo. Keeping a building at 50% should be possible but may appear strange in the game as the script would repair the building to 50% health when its health drops below 50% . I could take a look at it this weekend. I'm slow, the are faster scripters in this community
|
|
|
Post by keepitsimple on Dec 1, 2017 17:54:24 GMT 1
Hi Chris, Quintaxel is right. Smoke shell can't be selected with script. For more see Smoke screen for AI With regard to second. Let HPs be 200. With script you first damage it 50% DamageObject(number building, 100); --damage it to 100 -- Runscript("KeepHealth" , 10000); Function KeepHealth () local HP= GetObjectHPs(number building); if HP<100 then DamageObject(number building, -100); -- done know if this works else see below -- end; -- no Suicide() command as you want to keep this check going the hole game -- end; Alternative DamageObject(number building, -1); -- repair DamageObject(number building, 100); -- damage again to required state. I haven't test this so let me know if works?
|
|
|
Post by [BMG]Neutro on Dec 1, 2017 23:58:56 GMT 1
Thank your for your solutions. iam building MP maps only. so there for i cant change any units like mortars i cant only use lua and startcommands. so i will give up the idea with the smoke.
and the second one... its a building with 1000 HP
it look like this now:... the function init works of course but the function keephealth dont work maybe i write something wrong? iam not that pro.... can you please write the exact lua commands iam not sure sometimes ....
function KeepHealth() if((GetObjectHPs(988) < 500 )) then DamageObject(988, -500); end; end;
function Init() DamageObject(988, 500); SwitchWeatherAutomatic (1); RunScript("info",2000); RunScript("infoextra1",40000); RunScript("infoextra2",40000); RunScript("infoextra3",40000); RunScript("startunits",17000); RunScript("support1",600000); RunScript("support2",1200000); RunScript("support3",1800000); RunScript("support4",2400000); RunScript("support5",3000000); RunScript("support6",3600000); RunScript("specialsupport1",900000); RunScript("specialsupport2",1800000); RunScript("factory",180000); RunScript("barrage",2000); Runscript("KeepHealth",1000); end;
|
|
|
Post by keepitsimple on Dec 2, 2017 12:16:19 GMT 1
Hi Chris Fixed it. You can't script without testing . It works out that in DamageObject() a minus is repair of HPs (if not 100% destroyed). So to fixed back to 50% health points you need get HP. And repair the difference between half MaxHP and HP left. Simple if you know it. Delete the DisplayTrace lines in the final script. For testing nice to see that it works. function KeepHealth() SetIGlobalVar("HP988",GetObjectHPs(988)); DisplayTrace("HPs = %g", GetIGlobalVar("HP988",0)); if (GetIGlobalVar("HP988",0)<GetIGlobalVar("MaxHP",0)/2) then DisplayTrace("REPAIR"); DamageObject(988, -((GetIGlobalVar("MaxHP",0)/2)-GetIGlobalVar("HP988",0))); end; end; function Init() SetIGlobalVar("MaxHP",GetObjectHPs(988)); -- building shoud be 100% on the map DisplayTrace("Max HPs %g", GetIGlobalVar("MaxHP",0)); DamageObject(988, GetIGlobalVar("MaxHP",0)/2); -- here the building is destroy to 50% health RunScript( "KeepHealth", 2000); end;
|
|
|
Post by Quintaxel on Dec 2, 2017 15:50:53 GMT 1
Nice script keepitsimple but why use global variables? This is is not necessary and makes the script more complex than it should be. If the variables are not declared as local then there scope is the whole map script. Technically the use of global variables would make the script slower, not that you would notice, but I was just thinking......why not keepitsimple --This should also work function KeepHealth() HP988 = GetObjectHPs(988); DisplayTrace("HPs = %g", HP988); if (HP988)< (MaxHP/2) then DisplayTrace("REPAIR"); DamageObject(988, - (MaxHP/2) - HP988); end; end; function Init() MaxHP = GetObjectHPs(988); -- building shoud be 100% on the map DisplayTrace("Max HPs %g", MaxHP); DamageObject(988, (MaxHP/2)); -- here the building is destroy to 50% health RunScript( "KeepHealth", 2000); end;
|
|
|
Post by [BMG]Neutro on Dec 2, 2017 18:21:14 GMT 1
Hello many thanks to you both. i tested both variants.
first of all the "keepitsimple" script works perfect like i imagined it. the building "always" keep his 50% HP and when it gets completly destroyed it repais to 50% HP again. (I wanted a damaged building that is unconquerably)
The script from Quintaxel works also but there is one problem IF the building gets only damaged (not completely destroyed) it repairs to full 100% HP (but it should stay at 50% all the time)...
i tested with keepitsimple script: what happens with two buildings with the same ID 988.
well if BOTH buildings were completely destroyed they got BOTH repaired -- one with 50% and one with 100%...not working correctly... and only one building at a time will be repaired if it took damage so its not working with more then on buidling with the same ID sadly
now the question is do i need to copy the script for EVERY single building and set differrent IDs or is it possible to incorporate 989 and 900 ID in this script somehow? so i have more then one building that works with it
you speak about slow script cause globalVar do it affect the game really or cause problems in multiplayer?
i noticed you guys have alot of space characters in the script is this only for better clarity or do it have some effects??
it looks like this now in my lua.
function KeepHealth() SetIGlobalVar("HP988",GetObjectHPs(988)); DisplayTrace("HPs = %g", GetIGlobalVar("HP988",0)); if (GetIGlobalVar("HP988",0)<GetIGlobalVar("MaxHP",0)/2) then DisplayTrace("REPAIR"); DamageObject(988, -((GetIGlobalVar("MaxHP",0)/2)-GetIGlobalVar("HP988",0))); end; end;
function Init() SetIGlobalVar("MaxHP",GetObjectHPs(988)); DamageObject(988, GetIGlobalVar("MaxHP",0)/2); RunScript("KeepHealth",1000); SwitchWeatherAutomatic (1); RunScript("info",2000); RunScript("infoextra10",40000); RunScript("infoextra2",40000); RunScript("infoextra3",40000); RunScript("startunits",17000); RunScript("support1",600000); RunScript("support2",1200000); RunScript("support3",1800000); RunScript("support4",2400000); RunScript("support5",3000000); RunScript("support6",3600000); RunScript("specialsupport1",900000); RunScript("specialsupport2",1800000); RunScript("factory",180000); RunScript("barrage",2000); end;
|
|
|
Post by Quintaxel on Dec 2, 2017 18:34:28 GMT 1
The idea for the script idea is by keepitsimple , I just changed the global variables. Apparently I overlooked something I id not test the script. Should have listened to keepitsimple's advice.
|
|
|
Post by keepitsimple on Dec 3, 2017 1:08:11 GMT 1
Quintaxel , In testing I found that my locally declared variable didn't work. Hence, the global variable. [BMG]Neutro , It good programming to keep your global variables as low as possible but one or two or even a hundred won't kill you. What should consider is the time you do a check. Now you do a check (and repair action if necessary) every second. If you test how long it takes to destroy the building. You will find that every 10 seconds or every half minute is good enough. The less check per minute the computer needs to make the more time it has for other things. And no this doesn't work for more than one building at time. What is health of two buildings. A buildings and it health are unique combination. The computer must know which building you what to address. So with more than one building you need to copy the script. Of course need to change SetIGlobalVar("MaxHP",GetObjectHPs(988)); Into SetIGlobalVar("MaxHP988",GetObjectHPs(988));
|
|
|
Post by Quintaxel on Dec 3, 2017 13:56:18 GMT 1
Quintaxel , In testing I found that my locally declared variable didn't work. Hence, the global variable. Strange,....but it works and that's the most important thing about a script. It's a nifty script as it is, but it must also works without declaring variables as Global. [BMG]Neutro The fact that buildings repair to a the full 100 % after they have been destroyed completely has to do with math rules (order of operations). If you want you could replace the script line after DisplayTrace("REPAIR"); with DamageObject(988, - ((MaxHP/2) - HP988)); This time I tested the scrip How many buildings are we talking about ? The initial health of the buildings needs to be checked only once, at the start of the game. Therefore I would not put this check in the RunScript function but use a function for this that only runs once. You can repeat the script for every building but IMO it would be better practice to use arrays for this. (tables in Lua) If it's not urgent then I'll see if I can make something based upon the script of keepitsimple
|
|
|
Post by Quintaxel on Dec 3, 2017 15:34:50 GMT 1
Hi [BMG]Neutro Try this script for more then 1 building -- Start of script --
Building = {500,510,520}; -- Put ScriptId's of Buildings you want to keep at 50 % HP in the table Building {} -- The script will find out how many buildings it needs to keep at 50 % MaxHP = {};
function KeepHealth() local i = 1; while Building ~= nil do HP = GetObjectHPs(Building); DisplayTrace ("HP = %g", HP);
if HP < (MaxHP)/2 then DisplayTrace("Repairing building %g", Building); DamageObject(Building, - ((MaxHP/2) - HP)); end; i = i + 1; end; end;
function InitBuildingsHP() local i = 1; while Building ~= nil do DisplayTrace ("Building = %g", Building); MaxHP = GetObjectHPs(Building); DisplayTrace("Max HPs %g", MaxHP); DamageObject(Building, (MaxHP/2)); -- here the building is destroyed to 50% health i = i + 1; end; RunScript( "KeepHealth", 2000); -- Running the script Keephealth every 2 seconds Suicide(); --Script runs only once end;
function Init() DisplayTrace ("Init Running"); RunScript ("InitBuildingsHP",1000); end;
--End of Script --I have tested the script with 3 buildings but it should work with more buildings. The script will damage each building in the table Building {} to 50 %. This will cause a lot of smoke on the map. You could set each building to 50 % in the map editor and leave out the script line; DamageObject(Building, (MaxHP/2)); -- here the building is destroyed to 50% healthfrom the function; function InitBuildingsHP()
|
|
|
Post by [BMG]Neutro on Dec 3, 2017 20:27:16 GMT 1
Hello iam sorry its not working or maybe i copy the script wrong to the lua... hm ... the buildings not even get damaged from the start SCRIPT ID is correct...
RunScript( "KeepHealth", 2000); -- Running the script Keephealth every 2 seconds Suicide(); --Script runs only once end;
Why is here a suicide command? it will end the script?
Building = {555,666,520}; MaxHP = {};
function KeepHealth() local i = 1; while Building ~= nil do HP = GetObjectHPs(Building); DisplayTrace ("HP = %g", HP);
if HP < (MaxHP)/2 then DisplayTrace("Repairing building %g", Building); DamageObject(Building, - ((MaxHP/2) - HP)); end; i = i + 1; end; end;
function InitBuildingsHP() local i = 1; while Building ~= nil do DisplayTrace ("Building = %g", Building); MaxHP = GetObjectHPs(Building); DisplayTrace("Max HPs %g", MaxHP); DamageObject(Building, (MaxHP/2)); i = i + 1; end; RunScript( "KeepHealth", 2000); Suicide(); end;
function Init() DisplayTrace ("Init Running"); RunScript ("InitBuildingsHP",1000); SwitchWeatherAutomatic (1); RunScript("info",2000); RunScript("infoextra1",40000) RunScript("infoextra1",80000); RunScript("infoextra11",90000); RunScript("infoextra11",180000) RunScript("startunits",17000); RunScript("support1",600000); RunScript("support2",1200000); RunScript("support3",1800000); RunScript("support4",2400000); RunScript("support5",3000000); RunScript("support6",3600000); RunScript("specialsupport1",900000); RunScript("specialsupport2",1800000); RunScript("factory",20000); RunScript("barrage",2000); end;
|
|
kaoz
General
inter faesces et urinam nascimur
Posts: 1,109
|
Post by kaoz on Dec 3, 2017 21:58:09 GMT 1
Suicide(); -- Script runs only onceend; Why is here a suicide command? it will end the script? As it says in red, Suicide will make the script running only once. Without Suicide, the scripts keeps repeating itself. You may think this could be handy in some cases/situations, but do consider that a forever repeating function will have a serious effect on the game and in most cases will make it crash!
|
|
|
Post by [BMG]Neutro on Dec 3, 2017 22:03:55 GMT 1
yes sure but RunScript( "KeepHealth", 2000); must repeat itself the hole game to repair the buildings?
|
|
|
Post by Quintaxel on Dec 3, 2017 22:13:03 GMT 1
I have pasted the script again. I tested it and it works. About the Suicide (); The function InitBuildingsHP() runs only once but before the Suicide (); command it runs RunScript( "KeepHealth", 2000);
This means Keephealth will keep running every 2 seconds. Keephealth () needs to check the status of the buildings in order to heal them. Link to demo map.
|
|