Page 1 of 1
Getting Scripts/Conditions to activate other events
Posted: Thu Mar 16, 2017 3:59 pm
by lerugray
Hi all
First, thanks so much to the community for helping me with all these questions, hope to have a great scenario up for you guys soon.
So I am trying to create an event where if a player destorys a certian target, like a textile factory- between 9-5, it triggers another event called civilians killed which instead penalizes the player
I thought I could set this up via conditions but either I dont understand conditions correctly or I am using them wrong. any help is very appreciated. here is my code so far
Code: Select all
local now = ScenCurrentTime()
if now > now += 3600*9 and now < now += 3600*18 then
if SecnEdit_GetUnit({side='BSA', side='BSA', name='Ammo Factory' or side='BSA', name='Textile Factory' or side='BSA', name='Power Station'
or side='BSA', name='Military Factory' or side='BSA', name='Diesel Tank' or side='BSA', name='Processing Plant' or side='BSA', name='Serb Police Station Alpha'
or name='Serb Police Station Bravo' or name='Serb Police Station Charlie' or name='Serb Police Station Charlie'
or side='BSA', name='Serb Police Station Delta' or side='BSA', name='Serb Police Station Echo'}) == nil then
ScenEdit_ExecuteEventAction('Civilians Killed')
else
ScenEdit_ExecuteEventAction('BSA Land Structure Destroyed')
end
end
RE: Getting Scripts/Conditions to activate other events
Posted: Thu Mar 16, 2017 8:56 pm
by kevinkins
If I understand your intent correctly, it would be OK to destroy those facilities outside "working hours" i.e. outside the 9AM - 5PM. window?. It's not clear if you are having trouble with the code above or not. How is it not working for you? Maybe the syntax is off?
Kevin
RE: Getting Scripts/Conditions to activate other events
Posted: Thu Mar 16, 2017 8:59 pm
by lerugray
ORIGINAL: kevinkin
If I understand your intent correctly, it would be OK to destroy those facilities outside "working hours" i.e. outside the 9AM - 5PM. window?. It's not clear if you are having trouble with the code above or not. How is it not working for you? Maybe the syntax is off?
Kevin
Thank you for the reply Kevin, I'm not the best at asking questions and I apologize.
You have the right idea, historically units were not allowed to destroy certain targets during working hours.
Right now I can't get anything to trigger correctly. If I hit one of the buildings that is not on the above list, the civilians killed gets fired. I, trying another version of the code and will report how it behaves.
Code: Select all
local now = ScenCurrentTime()
if now > now += 3600*9 and now < now += 3600*18 and SecnEdit_GetUnit({side='BSA', side='BSA', name='Ammo Factory'
or side='BSA', name='Textile Factory'
or side='BSA', name='Power Station'
or side='BSA', name='Military Factory'
or side='BSA', name='Diesel Tank'
or side='BSA', name='Processing Plant'
or side='BSA', name='Serb Police Station Alpha'
or name='Serb Police Station Bravo'
or name='Serb Police Station Charlie'
or side='BSA', name='Serb Police Station Delta'
or side='BSA', name='Serb Police Station Echo'}) == nil then
ScenEdit_ExecuteEventAction('Civilians Killed')
else
ScenEdit_ExecuteEventAction('BSA Land Structure Destroyed')
end
end
RE: Getting Scripts/Conditions to activate other events
Posted: Thu Mar 16, 2017 9:03 pm
by lerugray
After trying the above code, I destroyed a Serbian Police Station after 9AM, the BSA Land Structure event did not trigger because of conditions, but the Civilians Killed event did not fire, any idea what I'm doing wrong?
RE: Getting Scripts/Conditions to activate other events
Posted: Thu Mar 16, 2017 9:19 pm
by lerugray
Scenario Download
It may show up weird, but if you hit download the resulting file should work in command
rar file (should work like a zip file but with winrar)
RE: Getting Scripts/Conditions to activate other events
Posted: Thu Mar 16, 2017 9:36 pm
by Rory Noonan
Hey lerugray, if you post a zip file containing your scenario I'd be happy to have a look through it and make some specific suggestions for you.
Edit: Apparently I'm blind. I'll have a look for you.
RE: Getting Scripts/Conditions to activate other events
Posted: Thu Mar 16, 2017 9:37 pm
by lerugray
ORIGINAL: apache85
Hey lerugray, if you post a zip file containing your scenario I'd be happy to have a look through it and make some specific suggestions for you.
I believe I just posted a download to it above! Thank you so much
RE: Getting Scripts/Conditions to activate other events
Posted: Thu Mar 16, 2017 9:44 pm
by Rory Noonan
I'm just looking at it now, if you like you can join me on the CMANO discord server and we can communicate there:
https://discord.gg/zbJyQAX
RE: Getting Scripts/Conditions to activate other events
Posted: Thu Mar 16, 2017 11:36 pm
by Rory Noonan
For other's benefit, the solution we came up with was getting rid of the condition and making an action with the following code:
local now = ScenEdit_CurrentTime() --checks current time
local start = 810604800 --this is the scenario start time, determined by using the ScenEdit_CurrentTime() function and the print function in the console
local begin = start + (3600*9) --time working hours begin
local finish = start + (3600*18) --time working hours end
local current_score = ScenEdit_GetScore ("NATO") --stores NATO's current score as a variable
ScenEdit_SetScore ("NATO", current_score + 40, "Ground target destroyed") --Adds 40pts from NATO
ScenEdit_SpecialMessage('playerside','Points added for killing target')
if now > begin and now < finish then --if the target is destroyed in business hours
local target = ScenEdit_UnitX() --gets the data of the destroyed unit
if target.dbid == 455 --if it's an ammo factory plant, military factory or textile factory or processing plant
or target.dbid == 597 --power station
or target.dbid == 8 --diesel tank
or target.dbid == 115 --sorting facility
or target.dbid == 616 --police station
then --if one of the above conditions is true, then...
local current_score = ScenEdit_GetScore ("NATO") --stores NATO's current score as a variable
ScenEdit_SetScore ("NATO", current_score - 50, "Killed civilians. You monster.") --Removes 50pts from NATO
ScenEdit_SpecialMessage('playerside','Points removed for killing civilians')
end
end
RE: Getting Scripts/Conditions to activate other events
Posted: Fri Mar 17, 2017 3:39 pm
by bearhunter007
To clarify, what triggers this final version of the lua script? Does this run continuously in the background?
Thanks in advance Apache85.
RE: Getting Scripts/Conditions to activate other events
Posted: Fri Mar 17, 2017 5:22 pm
by Rory Noonan
Hey bearhunter007,
The trigger for that script was the destruction of any enemy building, set to 100% and repeatable.
In essence it runs every time an enemy building is destroyed, checks the time, if outside of business hours then points awarded without penalty, if inside business hours *and* a specified type of target, points deducted (after initial award) for killing civilians.