[MOD EXT] Empyrion Scripting - Discussions

Discussion in 'The Hangar Bay' started by Sephrajin, Jun 29, 2020.

  1. shadowiviper

    shadowiviper Commander

    Joined:
    Apr 13, 2020
    Messages:
    89
    Likes Received:
    144
    That would be extremely useful, although I understand completely if it's something you're adding for C# scripts only and I'll just have to learn that instead.

    Also, hope you have an awesome vacation and we'll see you when you get back :)
     
    #21
  2. ASTIC

    ASTIC Captain

    Joined:
    Dec 11, 2016
    Messages:
    991
    Likes Received:
    707
    I will add this to the HBS syntax too.
     
    #22
    Kassonnade, shadowiviper and tachyon like this.
  3. tachyon

    tachyon Commander

    Joined:
    Aug 12, 2015
    Messages:
    92
    Likes Received:
    134
    Another idea:
    Would it be possible to add a function that returns a 2-tuple of 3dVectors that represent the bounding box of a structure?
    Are there events in the ModAPI that fire when a new block is added to a structure? This would be helpful to keep the values up to date without having to iterate the whole structure everytime this want-to-have function is called.
    I can do this ingame es well, of course, but I think it makes more sense to have this generally available in the ScriptAPI...
     
    #23
  4. Sephrajin

    Sephrajin Rear Admiral

    Joined:
    Dec 22, 2017
    Messages:
    916
    Likes Received:
    2,917
    #24
    shadowiviper and tachyon like this.
  5. tachyon

    tachyon Commander

    Joined:
    Aug 12, 2015
    Messages:
    92
    Likes Received:
    134
    I am aware of this but then you have to parse the information from strings which cumbersome and error-prone. Having something to store objects directly would be really nice.
     
    #25
    shadowiviper likes this.
  6. tachyon

    tachyon Commander

    Joined:
    Aug 12, 2015
    Messages:
    92
    Likes Received:
    134
    @ASTIC
    I tried to use Array.Length but got the message "This script is only allowed in SaveGameScripts" for doing so. I then set "WithinLearnMode" to "true" within "DefaultCsCompilerConfiguration.json" but this did not help. Shouldn't this automatically add permissions in the correct place? (I added System.Array.* manually).
     
    #26
  7. ASTIC

    ASTIC Captain

    Joined:
    Dec 11, 2016
    Messages:
    991
    Likes Received:
    707
    Withinlearnmode can be set in the CsCompilerConfiguration.json in the SaveGame mods path. Then the mod adds the found types in the SaveGame permission section and you have to move this to the section you want player or admin
     
    #27
    Kassonnade likes this.
  8. ASTIC

    ASTIC Captain

    Joined:
    Dec 11, 2016
    Messages:
    991
    Likes Received:
    707
    #28
  9. tachyon

    tachyon Commander

    Joined:
    Aug 12, 2015
    Messages:
    92
    Likes Received:
    134
    Hi and thanks for adding this. There seems, however, something wrong with the y values. The screenshots shows what MinPos/MaxPos and by brute force algorithm returns:
    titanminmax.jpg

    The screenshots also includes the debuginfo for the LCD screen. As one can see, the y value is within the range of what the brute force algortihm returns. MinPos/MaxPos return wrong values. For some reason I do not understand, the values are not in the range [-maxsize / 2 : maxsize/2] but from [0 : maxsize]. This is different from the x and z corrdinates. MinPos/MaxPos seem to returm values centered around zero, however. The GetBlock method also wants the [0:maxsize] variant.
    Maybe this is a bug...
     
    #29
  10. ASTIC

    ASTIC Captain

    Joined:
    Dec 11, 2016
    Messages:
    991
    Likes Received:
    707
    It's ok ... the origin is (the starter core) with 0,128,0 - sorry i forgot to tell this.
     
    #30
  11. tachyon

    tachyon Commander

    Joined:
    Aug 12, 2015
    Messages:
    92
    Likes Received:
    134
    Again a question: I try to use Max(IEnumerable<float>) and get the message that this is only allowed in savegame scripts. What is the problem here? System.Linq.* is included in the player permissions.

    Update: "System.Single.*" was missing
     
    #31
    Last edited: Aug 2, 2020
  12. shadowiviper

    shadowiviper Commander

    Joined:
    Apr 13, 2020
    Messages:
    89
    Likes Received:
    144
    @tachyon

    Did you ever settle on a workaround for coordinates of multi-block devices in your damage map? I've recreated the basic concept in HBS script with a few differences, I've removed the damage monitoring aspect of it and just producing a simple floorplan in miniature scale to use as an 'icon' for the ship (stored as cached data, as doing it 'live' lags my code, so generate once and store as an icon for later use).

    As part of this, i'm using that one-off generation to log coordinates of key devices (weapons, thrusters, generators) for later use, for example being able to show the number of gattling guns on the ship with an ammo counter, without having to manually enter the coordinates of each weapon on setup (devicesoftype doesn't include weapons currently) - but because each weapon is spread over multiple blocks I end up with multiple coordinates for each one e.g. when looking at a gattling gun with `di` it shows "-1,129,-4", but the logging system picks up "-1,129,-4 / -1,129,-3 / -1,129,-2" etc. The .Position in the block always returns the coords used to load it so when iterating over multiple spaces each result is always different, so when I try to calculate "number of weapons" I get a lot more results than I should. The damage-map/icon itself works fine, as every coordinate returns that theres a block at that location so every square is filled in properly.

    The current workaround I've got is to just log every coordinate that returns a cpgWeapon group, then loop through every value and log the count-per-id of those devices, and then divide that value by the known size for that ID (currently all manually, so I'm defining '429 = gattling gun = size:3' to give the accurate number for that weapon type - but I'm sure there must be a better way and I know you were looking into it before.

    overview for my current method
    • Once only - loop all x/y/z coords and log output to cache data
    • foreach coord, if Group=cpgWeapon, append x/y/z to 'Weapons' cacheData
    • CacheData.Weapons = "[-1,129,-4][-1,129,-3][-1,129,-2][3,129,-4][3,129,-3][3,129,-2]"
    • Loop all CacheData.Weapons coords
    • foreach coord, increment counter-per-block-ID
    • "CacheData.Weapons<430> = 3", "CacheData.Weapons<428> = 6"
    • hardcoded, per ID, the size of each weapon. ID:428 = 1x1x6
    • Divide counter total by size - id 428 has a size of 6, 6 x/y/z coords return ID 428, therefore there is 1 weapon with id 428
    So far this works, but it's clunky and means I need to hardcode the ID/size of each weapon or it wont work. I also haven't tested with things like turrets or weapons being retracted yet so I don't know if that will make a difference to returned ids.

    Have you found anything in your experiments that could improve on this? Most useful would be a way to get the origin x/y/z for a block - the one you see in the di menu so I can log unique instances of that. Failing that, a way to get the dimensions for a device so I don't need to hardcode sizes (couldn't see anything in Attr but maybe i'm being blind!) or any other method you're using for multi-dimension blocks

    Thanks
     
    #32
    Kassonnade likes this.
  13. tachyon

    tachyon Commander

    Joined:
    Aug 12, 2015
    Messages:
    92
    Likes Received:
    134
    No, not yet. What do you do, if you have multiple adjacent weapons to differentiate them from each other?
    Maybe each part of a multi-block device has the same hash in c# so you can utilize that. I have to check this.
     
    #33
    Kassonnade likes this.
  14. shadowiviper

    shadowiviper Commander

    Joined:
    Apr 13, 2020
    Messages:
    89
    Likes Received:
    144
    Ok so I thought I'd worked this out now with a better method - but I'm getting some really weird results.

    For a multi-block device, using {{block}} with any of the coordinates inside that block will return the correct id, But, only one space returns 'Active=true', the same coords as you get in the console. So for my purpose of logging 1 instances per device without duplicates, I just check is Active=1 as well as the ID/Group and where active isn't set can discard that item as another part of a multi-block device

    But.... out of 5 guns on my test ship this works for 4 of them, and 1 plasma cannon somehow returns Active=1 on ALL 5 of it's blocks, while every other weapon only on the origin coordinates, which completely throws off my method.

    It doesn't look to be a difference in the plasma cannon device itself - having added a 2nd one it only shows Active for a single set of coordinates (but NOT the ones shown in the console, unlike the others). I think it may be to do with block rotation as one instance shows a value for rotation while the others don't. I'm doing some more testing to work out the exact cause and hopefully it's a case of if Rotation > 0 also discarding that result, though I'd need some more test cases to be sure
     
    #34
  15. tachyon

    tachyon Commander

    Joined:
    Aug 12, 2015
    Messages:
    92
    Likes Received:
    134
    On my opinion every “sub-block” of a multi-bock device should just return the same values. For example the damage should be returned on every block and not only on the origin block. This would easily fix the problems, at least for me.
    I also have a new problem ( bug) with the LCDs where overlapping characters cause strange effects depending on from where you look on the LCD:
    https://empyriononline.com/threads/lcd-content-display-depends-on-player-position.95252/
    As I use overlapping characters to add the floor plan to the density based view, this is really annoying...
     
    #35
    Last edited: Aug 4, 2020
  16. shadowiviper

    shadowiviper Commander

    Joined:
    Apr 13, 2020
    Messages:
    89
    Likes Received:
    144
    Code:
    
    Plasma Cannon #1 - `di` shows [0,131,1]
        [0,131,1]: Plasma Cannon  - Active:True Rotation:8
        [0,131,2]: Plasma Cannon  - Active:True Rotation:0
        [0,131,3]: Plasma Cannon  - Active:True Rotation:0
        [0,131,4]: Plasma Cannon  - Active:True Rotation:0
        [0,131,5]: Plasma Cannon  - Active:True Rotation:0
    
    RailGun #1 - `di` shows [-2,129,4]
        [-2,129,4]: Rail Gun  - Active:True Rotation:8
        [-2,129,5]: Rail Gun  - Active:False Rotation:0
        [-2,129,6]: Rail Gun  - Active:False Rotation:0
        [-2,129,7]: Rail Gun  - Active:False Rotation:0
        [-2,129,8]: Rail Gun  - Active:False Rotation:0
        [-2,129,9]: Rail Gun  - Active:False Rotation:0
    
    Gattling Gun #1 - `di` shows [2,129,4]
        [2,129,4]: Gatling Gun  - Active:True Rotation:8
        [2,129,5]: Gatling Gun  - Active:False Rotation:0
        [2,129,6]: Gatling Gun  - Active:False Rotation:0
        [2,129,7]: Gatling Gun  - Active:False Rotation:0
    
    Plasma Cannon #2 - `di` shows [2,130,4]
        [2,130,4]: Plasma Cannon  - Active:True Rotation:8
        [2,130,5]: Plasma Cannon  - Active:True Rotation:0
        [2,130,6]: Plasma Cannon  - Active:True Rotation:0
        [2,130,7]: Plasma Cannon  - Active:True Rotation:0
        [2,130,8]: Plasma Cannon  - Active:True Rotation:0
    
    Pulse Laser #1 - `di` shows [0,129,5]
        [0,129,5]: Pulse Laser  - Active:True Rotation:8
        [0,129,6]: Pulse Laser  - Active:True Rotation:0
        [0,129,7]: Pulse Laser  - Active:True Rotation:0
        [0,129,8]: Pulse Laser  - Active:True Rotation:0
    
    Rocket #1 - `di` shows [0,127,0]
        [0,127,0]: Rocket Launcher  - Active:True Rotation:8
        [0,127,1]: Rocket Launcher  - Active:True Rotation:0
        [0,127,2]: Rocket Launcher  - Active:True Rotation:0
    
    
    I take it back, it looks like for some weapons, only the origin point is marked active, while others its all spaces. I also seem to be able to get false positives as well - for example the Rocket Launcher shows all 3 spaces as 'Active' while it's powered. If I turn the power off, the origin/first space shows Active:false, while the others continue to show True.

    Possibly this isn't related to the weapon type at all, and is to do with the order I've placed them - the 2 with odd results were the first ones I placed and i've logged out / respawned the ship since they were added, so that could be contributing to the different results.

    I agree with you it would be better if it was consistent across all spaces (although that would break my current script) and would be nice if there was a way to get the "true" coordinates even when accessing a multi-block from it's other spaces, e.g. load {{block 0 127 3}}{{TruePosition.Z}} //1{{/block}}

    The overlapping characters I've had a lot of, mostly when decreasing the text size down to a very small size and overlapping separate lines can at times give a 'flickering' effect, almost like scan lines on an old CRT. The 'Fuel area chart' was the worst offender, a lot of solid blocks in very small font size and would constantly flicker or have sections disappear, so very similar to the amount of 'filled in space' you'd have in the floor plan.
     

    Attached Files:

    #36
  17. tachyon

    tachyon Commander

    Joined:
    Aug 12, 2015
    Messages:
    92
    Likes Received:
    134
    Using the hashcode of IBlock (directly from the mod API) doesn't work either. Each position has a different hashcode. This was to be expected but I had some hope here. You should really make a report/suggestion for change in the suggestions- and/or bug thread for the mod API with your findings.
    For me, it is just to complicated to scan the whole structure, then cluster the devices, and then to scan those clusters again, just to determinate what belongs together. It's just not worth all the effort.
    Regarding your approach with using "Active" for this: I think this won't work for multi-block stuff like fuel tanks or large containers...

    PS: I have to admit that I am quite impressed that you do all the stuff with handlebars.
     
    #37
    Last edited: Aug 6, 2020
  18. shadowiviper

    shadowiviper Commander

    Joined:
    Apr 13, 2020
    Messages:
    89
    Likes Received:
    144
    Thanks! I'm always impressed with the stuff you come up with in C#, if I could find the time to actually sit down and learn it I would but it always looks so complicated so currently I stick to what I know (although I'd never heard of Handlebars when I started either, and spent many evenings watching ASTIC's videos and a lot of google translate :) )

    For the multi-blocks, you're right it wouldn't work with fuel tanks etc, although for what I'm actually aiming for that shouldn't be a problem. My end goal is for part of the heads up display I'm working on, which would effectively recreate the toggles from the P menu (Shield, Thrusters, Oxygen, RCS etc) as a series of warning lamps shown in 1 corner.

    Originally I had a user-entered config set up - put in the x,y,z of your shield generator, a single thruster, an RCS block for example, and then using {{block}} test if that device is on/off and change the colour of the icon.

    In a later version, as I was 'scanning' the ship anyway to produce an "icon" that looks like a top down view of the SV - inspired by your damage map - I figured I could do away with asking the user to set up the coordinates per device, and just store them as I found them in that initial scan. So I then have the coordinates to every thruster on the ship, and if they are all ON can show that "In the P menu, Thruster is on"

    Next version, wanted to expand on what I was doing with weapons - so not just a single light for 'Weapons - On/Off', but actually be able to list in the HUD "Gattling Gun x 4 - [1000/5000]" (for ammo counter). That mean't knowing how many individual 'gattling gun' devices there are - but the coordinates I was storing were for every space occupied by 'gattling gun', so for each individual weapon I've got 4 sets of coordinates.

    That then became more of a problem when I found that of the 4 coordinates I've got stored for a single gattling gun, 3 of those return Active=false and 1 returns Active=true - the data in {{block}} differed depending on if it was the first block or one of the other spaces. That then led to using 'Active' as a secondary test, and only storing the coordinate if true, in effect only storing 1 coordinate per device

    That didn't work as some weapons (plasma, pulse laser) return Active across all their spaces, while others only on 1 block - I've not yet determined if its to do with weapon type, orientation, placing a weapon then relogging or respawning the ship etc, but there is a difference between them which makes that method unworkable. Next on my list to try is 'Rotation' seems to always be a non-zero value for the first block, and then 0 for all others, so that may be an option for only logging 1 coordinate per device and *might* also be applicable to Fuel tanks as well. If it works I'll let you know
     
    #38
  19. shadowiviper

    shadowiviper Commander

    Joined:
    Apr 13, 2020
    Messages:
    89
    Likes Received:
    144
    I'd planned to report this, both for the devs and for ASTIC, once i've gathered some hard data on what the differences are on multi blocks and also if I can determine why some weapons are different to others - if its the type of weapon or something else. At the minute all my findings are quite flimsy and based only on a single ship which is already running a lot of other code, so I'd want to isolate the exact problem with some clear examples before I report anything
     
    #39
  20. tachyon

    tachyon Commander

    Joined:
    Aug 12, 2015
    Messages:
    92
    Likes Received:
    134
    Best would be, if they expand the API for multi-block stuff:
    • Is multi-block? true/false
    • Min-/max coordinates
    • Correct hitpoints/ damage for the whole multi-block thing
    • Is switchable (can be turned on/off)
    • An instance id that is the same for every sub-block of the multi-block thing
    This would really help with many things. IDevice would be a good place to put this in, as this only applies to devices.
     
    #40
    shadowiviper likes this.

Share This Page