Getting Scripts/Conditions to activate other events

Post new mods and scenarios here.

Moderator: MOD_Command

Post Reply
lerugray
Posts: 160
Joined: Mon Dec 22, 2014 12:42 pm

Getting Scripts/Conditions to activate other events

Post 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
 
User avatar
kevinkins
Posts: 2465
Joined: Wed Mar 08, 2006 11:54 am

RE: Getting Scripts/Conditions to activate other events

Post 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
“The study of history lies at the foundation of all sound military conclusions and practice.”
Alfred Thayer Mahan
lerugray
Posts: 160
Joined: Mon Dec 22, 2014 12:42 pm

RE: Getting Scripts/Conditions to activate other events

Post 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
 
lerugray
Posts: 160
Joined: Mon Dec 22, 2014 12:42 pm

RE: Getting Scripts/Conditions to activate other events

Post 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?
lerugray
Posts: 160
Joined: Mon Dec 22, 2014 12:42 pm

RE: Getting Scripts/Conditions to activate other events

Post 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)
Rory Noonan
Posts: 2418
Joined: Thu Dec 18, 2014 1:53 am
Location: Brooklyn, NY

RE: Getting Scripts/Conditions to activate other events

Post 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.
Image
lerugray
Posts: 160
Joined: Mon Dec 22, 2014 12:42 pm

RE: Getting Scripts/Conditions to activate other events

Post 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
Rory Noonan
Posts: 2418
Joined: Thu Dec 18, 2014 1:53 am
Location: Brooklyn, NY

RE: Getting Scripts/Conditions to activate other events

Post 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
Image
Rory Noonan
Posts: 2418
Joined: Thu Dec 18, 2014 1:53 am
Location: Brooklyn, NY

RE: Getting Scripts/Conditions to activate other events

Post 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
Image
bearhunter007
Posts: 23
Joined: Sat Mar 11, 2017 2:51 am

RE: Getting Scripts/Conditions to activate other events

Post by bearhunter007 »

To clarify, what triggers this final version of the lua script? Does this run continuously in the background?

Thanks in advance Apache85.
Rory Noonan
Posts: 2418
Joined: Thu Dec 18, 2014 1:53 am
Location: Brooklyn, NY

RE: Getting Scripts/Conditions to activate other events

Post 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.
Image
Post Reply

Return to “Mods and Scenarios”