Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Home Land Security Script

  1. #1
    Staff Sergeant Tom_Anger's Avatar
    Join Date
    Mar 2 2007
    Location
    USA, MASSACHUSETTS
    Posts
    342
    Can I have a seasoned coder please review to see how well I did here. ***I haven't tested it yet, but it at least gives an idea on what I am trying to accomplish for a series of Attack & Defend maps that I would like to created for some decent events.

    Let me know if this looks good or has a more efficient way of writing it please let me know. ***Basically a defending team accumulates points on vehicles, players, and other objects. ***Only players respawn and as points go up the Security Alerts drop.

    Vehicle, Object, Person has the script call with it's point value appended
    (i.e. not alive unit [50] execVM homelandsec.sqf )

    Here are my questions on what I have.

    Question 1:
    Is this written in such a way that it will work? ***I have a variable-flag set each time a level is met so that they don't show up when each item is killed. ***Does that look ok?

    Question 2: (HOW TO END)
    How can I make it so that when I get to the very last part where the threat is over, the mission ends with a BLUFOR victry?

    Question 3: (RESTRICT TO BLUFOR ONLY)
    How can I make it so that only the BLUFOR team sees the messages? ***It would be nice to only have them know the level they are at.

    homelandsec.sqf
    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">
    // HOME LAND SECURITY THREAT MESSAGES
    // VARIABLES passed in are&#58;
    // _points - is a variable which the mission maker appends to an object. ***What he/she believe the unit is worth
    //
    // PARAMETERS _codered, blue, etc ***are used for the security threshhold values. ***As points are accumulated
    // the threat is over and the mission will end.

    _points = _this select 0;

    _codered = 0;
    _codeorange = 1000;
    _codeyellow = 2000;
    _codeblue = 3000;
    _codegreen = 4000;
    _threatisover = 5000;

    _total = _total + _points;

    //================================================== ====
    // Now check against our security matrix to see what level of threat we are at. ***Each time we call
    // this script we only want to display as the serverity changes so we set a flag/variable called
    // _code&#40;color&#41;activated then check each time before displaying the message.

    if &#40;&#40;_total &#60; _codeorange&#41; && &#40;_coderedactivated &#33;= 1&#41;&#41; then
    {
    *** *** ***_coderedactivated = 1;
    *** *** ***cutText&#91;&#34;CODE RED. ***We are at a SEVERE Risk of Attack.&#34;, &#34;PLAIN&#34;&#93;;
    *** };

    if &#40;&#40;_total &#62;= _codeorange&#41; && &#40;_total &#60; _codeyellow&#41; && &#40;_codeorangeactivated &#33;= 1&#41;&#41; then
    {
    *** *** ***_codeorangeactivated = 1;
    *** *** ***cutText&#91;&#34;CODE ORANGE. ***We have dropped to a HIGH Risk of Attack.&#34;, &#34;PLAIN&#34;&#93;;
    *** };
    ***
    if &#40;&#40;_total &#62;= _codeyellow&#41; && &#40;_total &#60; _codeblue&#41; && &#40;_codeyellowactivated &#33;= 1&#41;&#41; then
    {
    *** *** ***_codeyellowactivated = 1;
    *** *** ***cutText&#91;&#34;CODE YELLOW. ***We have dropped to an ELEVATED Risk of Attack.&#34;, &#34;PLAIN&#34;&#93;;
    *** };
    ***
    if &#40;&#40;_total &#62;= _codeblue&#41; && &#40;_total &#60; _codegreen&#41; && &#40;_codeblueactivated &#33;= 1&#41;&#41; then
    {
    *** *** ***_codeblueactivated = 1;
    *** *** ***cutText&#91;&#34;CODE BLUE. ***We have dropped to a GUARDED Risk of Attack.&#34;, &#34;PLAIN&#34;&#93;;
    *** };
    ***
    if &#40;&#40;_total &#62;= _codegreen&#41; && &#40;_total &#60; _threatisover&#41; && &#40;_codegreenactivated &#33;= 1&#41;&#41; then
    {
    *** *** ***_codegreenactivated = 1;
    *** *** ***cutText&#91;&#34;CODE GREEN. ***We have dropped to a LOW Risk of Attack.&#34;, &#34;PLAIN&#34;&#93;;
    *** };
    ***
    if &#40;_total &#62;= _threatisover&#41; then
    {
    *** *** ***cutText&#91;&#34;The Security Threats are over. ***We are free of enemy attacks.&#34;, &#34;PLAIN&#34;&#93;;
    *** };[/QUOTE]
    Enjoying Advance & Secure PVP Battles with friends at http://www.fcarma.com

  2. #2
    Hi,

    In your original script you have the variables _coderedactivated to _codegreen are not defined outside the scope of each of thier If statements. So your test for:

    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">&#40;_codegreenactivated &#33;= 1&#41;[/QUOTE] Will always return false.

    You would need to define them at the start of the script, along with your other variables.

    Although it&#39;s not clear how you intend to use them. Is the message something that would be repeatedly displayed using a looping script? All these vaiables are local so you would loose the values once the script has finished. So _codegreenactivated would be reset everytime you called your script. Do you need to store the last message displayed?

    Anyway if you want to reduce your code a bit, you could try it this way:

    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">// HOME LAND SECURITY THREAT MESSAGES
    // VARIABLES passed in are&#58;
    // _points - is a variable which the mission maker appends to an object. ***What he/she believe the unit is worth
    //
    // PARAMETERS _codered, blue, etc ***are used for the security threshhold values. ***As points are accumulated
    // the threat is over and the mission will end.

    _points = _this select 0;

    //Create the code arrays, could be a global array if used in other scripts as well. Or if you want to populate the array when the mission starts.
    _Codes=&#91;&#91;&#34;CODE RED. ***We are at a SEVERE Risk of Attack.&#34;,false&#93;,&#34;&#91;CODE ORANGE. ***We have dropped to a HIGH Risk of Attack.&#34;,false&#93;,&#91;&#34;CODE YELLOW. ***We have dropped to an ELEVATED Risk of Attack.&#34;,false&#93;,&#91;&#34;CODE BLUE. ***We have dropped to a GUARDED Risk of Attack.&#34;,false&#93;,&#91;&#34;CODE GREEN. ***We have dropped to a LOW Risk of Attack.&#34;,false&#93;,&#34;&#91;The Security Threats are over. ***We are free of enemy attacks.&#34;,false&#93;&#93;;

    _total = _total + _points;

    //Convert the total to an integer between 0 and the number of elements in your array.
    _Index=Floor &#40;_Total/1000&#41;;

    //Get the pointer to the required code array
    _pCode=_Codes Select _Index;

    If &#33;&#40;_pCode Select 1&#41; then
    *** *** ***{
    *** *** ***_pCode Set &#91;1,true&#93;;
    *** *** ***cutText&#91;&#40;_Codes Select _Index&#41; Select 0, &#34;PLAIN&#34;&#93;;

    *** *** ***//Reset all the previous codes apart from the current one
    *** *** ***for &#91;{_Count=0},{_Count&#60;=Count _Codes},{_Count=_Count+1}&#93; Do
    *** *** *** *** *** ***{
    *** *** *** *** *** ***If &#40;_Index&#33;=_Count&#41; Then
    *** *** *** *** *** *** *** *** ***{
    *** *** *** *** *** *** *** *** ***&#40;_Codes Select _Count&#41; Set &#91;1,false&#93;;
    *** *** *** *** *** *** *** *** ***};
    *** *** *** *** *** ***};
    *** *** ***};
    [/QUOTE]

    Like I said I cant really comment on how you want to use the script, but the above code gives you an idea of how to reduce the amount of code in some cases and introduces array pointers.

    BTW If you don&#39;t need to remeber the last code displayed you can simplify the script even more to:

    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">// HOME LAND SECURITY THREAT MESSAGES
    // VARIABLES passed in are&#58;
    // _points - is a variable which the mission maker appends to an object. ***What he/she believe the unit is worth
    //
    // PARAMETERS _codered, blue, etc ***are used for the security threshhold values. ***As points are accumulated
    // the threat is over and the mission will end.

    _points = _this select 0;

    //Create the code array, could be a global array if used in other scripts.
    _Codes=&#91;&#34;CODE RED. ***We are at a SEVERE Risk of Attack.&#34;,&#34;CODE ORANGE. ***We have dropped to a HIGH Risk of Attack.&#34;,&#34;CODE YELLOW. ***We have dropped to an ELEVATED Risk of Attack.&#34;,&#34;CODE BLUE. ***We have dropped to a GUARDED Risk of Attack.&#34;,&#34;CODE GREEN. ***We have dropped to a LOW Risk of Attack.&#34;,&#34;The Security Threats are over. ***We are free of enemy attacks.&#34;&#93;;

    _total = _total + _points;

    //Convert the total to an integer between 0 and the number of elements in your array.
    _Index=Floor &#40;_Total/1000&#41;;

    cutText&#91;_Codes Select _Index, &#34;PLAIN&#34;&#93;;
    [/QUOTE]

    None of the above code as been tested in Arma, so you may have to tweak it.

  3. #3
    Staff Sergeant Tom_Anger's Avatar
    Join Date
    Mar 2 2007
    Location
    USA, MASSACHUSETTS
    Posts
    342
    Author of the Thread
    I know there is a simple working answer out there somewhere as this looks to be trivial, but for me as a beginner I am trying my best. Spent alot of time so far so any help is appreciated.

    I need the system to keep a tally of points as the game goes on. So after enough OPFOR, vehicles, objects, etc are defended off the points go up and as the different levels are met the message displays.

    A tank may be worth 100 points, jet, 200, etc so as this builds up I want the mesasge to only display as the levels change. I haven&#39;t put a specific point on an item yet, but just trying it out.

    The logic you provided did not work and the last box had it crashing on line 18. So what method would I have to use to take my original logic and make it work. As you said it won&#39;t work because the system isn&#39;t keeping a temp variable to use.

    Does anyone have an ArmA scripting method for this? It would greatly help. At the very least I have the base code outlined. Just needs to be hammered out now.

    I would also need to know how and where to call it for an object. I am currently using it as a condition

    For example

    Cond: if (getDammage tank01 > 0.95) then {[100] execVM "homelandsec.sqf"};

    ,where the [100] is the point value for the tank

  4. #4
    I am assuming all of this is MP based on your first post and all your sig banners...

    In the case of MP, there is one very important point you need to know: Run as much as possible server-side.

    Rather than try and define a goal based on what we think might work (point variables, arrays, etc..) let&#39;s step back a bit and redefine exactly what you are looking for. You will hear suggestions from people all day about what you CAN do, but lets figure out what works best for you first.

    What are the goals of these missions?

    What is the purpose of the "code level"? You&#39;ve already defined what the points are for, but is it simply to display something to the player? or does it affect gameplay?

    Getting scripts to work in MP is a huge hassle, and it is best to always try and accomplish what you need server-side and worry about running client-side last.

    You can PM me if you need help with this or we can work out of this thread.

    Cheers




  5. #5
    Staff Sergeant Tom_Anger's Avatar
    Join Date
    Mar 2 2007
    Location
    USA, MASSACHUSETTS
    Posts
    342
    Author of the Thread
    Yes MP team vs team
    OPFOR
    The goal is OPFOR starts at the airbase with a convoy lined up, some air fighter jets, and other stuff. ***Not to get into the storyline, but they have been given the command to destroy fuel station supplies in Dolores&#39; dock area.

    The OPFOR base is setup so that they have to fuel up, weapon up and begin the attack. ***Players will respawn and not vehicles.

    BLUFOR
    BLUFOR has inteliigence informing them of this attack so at the get go we are at a Red alert. ***I have a script for a time limit which counts down correctly, but doesn&#39;t end when time expires - that is another issue I am working on
    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">// Time to wait in minutes as single script argument.
    // waiter.sqf
    // Example with 5 mins limit.
    // &#91;30&#93;execVM&#34;waiter.sqf&#34;

    _timetowait = _this select 0;

    while {_timetowait &#62; 0} do
    {
    *** if &#40;_timetowait &#33;= 5&#41; then
    *** {
    *** *** ***cutText&#91;format&#91;&#34;%1 minutes until the threat is over&#34;, _timetowait&#93;, &#34;PLAIN&#34;&#93;;
    *** }
    *** else
    *** {
    *** *** ***cutText&#91;&#34;Five minutes left&#34;, &#34;PLAIN&#34;&#93;;
    *** };
    *** Sleep&#40;300&#41;;
    *** _timetowait = _timetowait - 5;
    }
    cutText&#91;&#34;The threat is over - good job U.S. Team&#34;, &#34;PLAIN&#34;&#93;;[/QUOTE]

    The idea is after 30 minutes the threat is to be over, but I also want to give the BLUFOR the option to decrease the level of threat based on the ability to defend...

    Is that enough information? ***I am working on 4 hours sleep and just got off a 10 hour shift so I am very tired. ***I do appreciate your help. ***I think given the title of the thread and purpose it may help others if they want to form some nice attack & defend maps.




  6. #6
    Gotcha ***

    OK, I reread your post and you actually sum everything up pretty nice except we are missing some details.

    First lets define what needs to be done server-side:

    A) Store global variable for points
    B) Tack on points to AI objects (I assume all objects w/ points are AI and NOT players)
    C) Notify Clients of code level

    Lets run an init SQF to initialize our system:

    Init.sqf
    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">
    CurrentPoints = 0;
    OldPoints = 0;
    CodeLevel=&#34;Red&#34;;
    [/QUOTE]

    Then we will handle points based on killed event handler. We don&#39;t get the flexibility of using a "Damaged" event, but with killed we know it will execute once and will execute only on the server.

    On all the AI units, we want to add the following to their init lines:

    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">this addeventhandler &#91;&#34;Killed&#34;, &#34;CurrentPoints=CurrentPoints+100&#34;&#93;;[/QUOTE]

    changing the value (100) as needed...

    Once a unit is killed, it should execute on the server because the unit is an AI unit not belonging to a player (in players group). This increases the value for CurrentPoints by the specified amount ONLY on the server.

    Now, we could publicvariable "CurrentPoints" at this time but we will NOT and I will explain why. Most would say to PV that value and calculate the result on each client, but I say "why perform the calc more than once?". I say we either run a script which loops and changes CodeLevel or use a trigger. We will then PV CodeLevel to the client which will display the appropriate message. We have triggers which loop and work just fine so lets try that first...

    Place a game logic and call it "server"

    Now make a trigger that repeats and has a condition of:
    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> &#40;local server&#41; && &#40;CurrentPoints&#33;=OldPoints&#41;[/QUOTE]

    in the activation, we will change the codelevel if needed and PV it: (you&#39;ll have to execute in an SQF or write it in one conintuous line in trigger activation field)
    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> if &#40;CurrentPoints &#62; 1000&#41; then
    {
    if &#40;CurrentPoints &#62; 2000&#41; then
    {
    if &#40;CurrentPoints &#62; 3000&#41; then
    {
    if &#40;CurrentPoints &#62; 4000&#41; then
    {
    codelevel = &#34;Green&#34;;
    }else {codelevel = &#34;Blue&#34;;};
    }else {codelevel = &#34;Yellow&#34;;};
    }else {codelevel = &#34;Orange&#34;;};
    }else {codelevel = &#34;Red&#34;;};
    PublicVariable &#34;CodeLevel&#34;;OldPoints=CurrentPoints;[/QUOTE]

    What we do here is change the codelevel to a color and send the color to all the clients. we then update oldpoints so the trigger doesn&#39;t set off until needed again.

    What we need now are trggers for each "color" which executes once (on every client)

    Each trigger will have a condition (use appropriate color):
    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">CodeLevel = &#34;Red&#34;[/QUOTE]

    Then on the Effects tab, we will specify the text to display, any sounds, etc..

    As the points accumulate it should go until you get to the green trigger which ends the mission (make it a "Win" trigger).

    Now, to get the mission to end at a specific time we will another trigger... It will need to have a timeout of 30mins and be a "Loose" trigger.



    No scripts needed other than initializing the values. You can substitute scripts for triggers if you like, but IMO why try and reinvent the wheel if a trigger works fine?




  7. #7
    Staff Sergeant Tom_Anger's Avatar
    Join Date
    Mar 2 2007
    Location
    USA, MASSACHUSETTS
    Posts
    342
    Author of the Thread
    I already had an object setup with gamelogic with the name server (I had that for a vehicle respawn if I choose to use that script - which works, but I am going to restrict respawning in the end).

    1. I created the init file and saved it (used one from another map and copied and editted.
    2. I added the killed condition to a tank and gave it a value of 2000 for testing
    this addeventhandler ["Killed", "CurrentPoints=CurrentPoints+2000"];
    3. I added my 1st trigger as you mentioned and clicked the repeatedly words
    (local server) && (CurrentPoints&#33;=OldPoints)

    I did not change anything on the trigger other than that. ***
    4. in the On Acc section of that trigger I entered in the entire string of commands and verified that they were there.
    5. I then added each trigger with the CodeLevels that matched that of the string.

    I do not get any of the messages. ***Maybe we can get on a teamspeak. ***I have my own personal one if you are around to chat. ***I believe with your help I am extremly close.

    Here are some screenies of my settings for what it&#39;s worth
    Example Pic 1
    Example Pic 2
    Example Pic 3
    Example Pic 4
    Example Pic 5




  8. #8
    Sorry, I am at work right now (shhhh&#33

    Welcome to debugging&#33;

    Lets figure out what is not working.
    ...

    [EDIT] I just realized I made a coding mistake. Change the addeventhandler to this:
    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">this addeventhandler &#91;&#34;Killed&#34;, {CurrentPoints=CurrentPoints+2000;}&#93;;[/QUOTE]




    [Text before Edit]
    We can do this by using the easiest method - "hints".

    First, change the addeventhandler to:
    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">this addeventhandler &#91;&#34;Killed&#34;, {CurrentPoints=CurrentPoints+2000;hint &#34;Unit Killed&#34; }&#93;;[/QUOTE]

    and try killing the unit. does the Hint display? It should if it is working.

    If it is working, add a hint to the trigger and remove all the code from the activation line and just put:
    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">hint &#34;Trigger works&#33;&#34;[/QUOTE]

    make sure it goes off every time a unit is killed.

    if it works, replace the text with the code as before and try placing a hint in each color trigger...

    you should get the point of this by now... try and find what doesn&#39;t work.

    Also, try changing the color triggers to something other than "None" in the activation drop-down. It doesn&#39;t matter what... just make sure you change it.




  9. #9
    Staff Sergeant Tom_Anger's Avatar
    Join Date
    Mar 2 2007
    Location
    USA, MASSACHUSETTS
    Posts
    342
    Author of the Thread
    Unfortunately when I put your event handler line I get the error immediately before going forward that

    Error Missing ]

    I realize it has to be part of the "[" and "]" to work. I am a software programmer myself and am kicking myself for not understanding this. 11+ years, but with our own software. I worked the 3rd shift last night and am barely able to keep awake, lol. I am soo close so I will go wash up for a bit, check back, then probably go to sleep for the night. Boston area, lol.

    by the way - I did try other values than None. Even hosted in dedi mode to try it. The timeout isn&#39;t working either - Murphys law at the moment. Anyway - I appreciate your helping, we can do this another time, maybe on a teamspeak or something. I will check back in a few to see if you see something that I don&#39;t.

  10. #10
    Go to bed... You&#39;ll think better when you&#39;ve refreshed ***

    I am surprised the addeventhandler doesn&#39;t work - but now that I think about it... I do remember something about addeventhandler not working in INIT fields. Like you must write them in the init.sqf or something.. i.e.:
    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">TankUnit addeventhandeler... blah blah[/QUOTE]

    I really wish I could test this myself before writing... but as I mentioned I&#39;m at work and it would be in OFP (not ArmA)




Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •