Results 1 to 12 of 12

Variables in .ship files

  1. #1
    Riebart
    Guest

    Variables in .ship files

    I'm starting to make a mod that addresses some (Perceived) severe limitations and imbalances in the game. In doing so, I've got some defensive platforms: The standard gun/ion platforms with the ability to activate a defense field.

    The ships are done, and in and working great, but now I would like to add upgrades to the defense field frigate (Stock one), that boost the range and duration of the field. I know what values modify in it's .ship file, but I can't seem to be able to create a varaible that I can reference. Here's an example of what I mean:

    [hgn_defensefieldfrigate.ship]
    ...
    1: addAbility(NewShipType, "DefenseFieldAbility", 1, 0, 1200, 200, 200, 1, 0.6, 0, "defensefield_sphere_spray")
    2: addAbility(NewShipType, "DefenseFieldShieldAbility", 0, 1200, 0, 0)
    3: AddShipAbility(NewShipType, "DefenseField", 1, "ThisShipOnly", 0)
    ...
    [end]

    Line 1 adds the ability to the ship, line 2 adds the sphere that we see when active, and line 3 adds the sphere outline when mouse-overing the ship. The numbers highlighted in red are the radius in metres, the blue number is the duration, and the green number is the recharge time. The duration and recharge time appear to have a unit of 0.1s. (So, the stock is 20s duration, 20s recharge). THe units don't really matter though.

    My idea was to modify the file as follows:

    [hgn_defensefieldfrigate.ship]
    ...
    1: NewShipType.MaxRadius = 1200
    2: NewShipType.Duration = 200
    3: NewShipType.Recharge = 200
    4: addAbility(NewShipType, "DefenseFieldAbility", 1, 0, MaxRadius, Duration, Recharge, 1, 0.6, 0, "defensefield_sphere_spray")
    5: addAbility(NewShipType, "DefenseFieldShieldAbility", 0, MaxRadius, 0, 0)
    6: AddShipAbility(NewShipType, "DefenseField", 1, "ThisShipOnly", 0)
    ...
    [end]

    However, this doesn't work. What I (effectively) end up with is a radius of 0 (I presume an initialized integer is passed to the parameters, and so I get no radius. Without a radius, the defense field won't even activate.)

    I've also tried replacing MaxRadius in teh function call by NewShipType.MaxRadius (Same effect), And Me.NewShipType and This.NewShipType (Both of which crashed Homeworld).

    I am completely unfamiliar with LUA scripting, but I am not at all new to programming in general.

    Any help would be amazingly appreciated.

  2. #2
    Lost in the code... Mikali's Avatar
    Join Date
    Jun 2003
    Location
    %HW2_ROOT%
    Have you tried doing this:

    Code:
    1: local MaxRadius = 1200
    2: local Duration = 200
    3: local Recharge = 200
    4: addAbility(NewShipType, "DefenseFieldAbility", 1, 0, MaxRadius, Duration, Recharge, 1, 0.6, 0, "defensefield_sphere_spray")
    5: addAbility(NewShipType, "DefenseFieldShieldAbility", 0, MaxRadius, 0, 0)
    6: AddShipAbility(NewShipType, "DefenseField", 1, "ThisShipOnly", 0)
    Download my HW2 mods, maps & tools. link
    Username|SF on Gamespy/Xfire/Hamachi/Gameranger

  3. #3
    Riebart
    Guest
    I gave that it a shot and HW just crashed when loading the universe. Hmm....
    Last edited by Riebart; 14th Mar 07 at 7:54 AM.

  4. #4
    LUA functionality if very limited in ship scripts... that's why functions like Rand() (or Rnd(), whatever it is) don't work over there. But there is no reason why variables don't work...

  5. #5
    Member
    Join Date
    Oct 2005
    Location
    City of Lights
    I don't think you can change the values in .ship files in the middle of the game, except by researching upgrades or adding subsystems. Check out the list of modifiable values on the wiki.

    EDIT: perhaps it does not understand "local" or you should declare the variables before the NewShipType functions. But even if it could use a variable in ship script, I don't think you can change it by your own script during the game as they are loaded once and for all at game start.

  6. #6
    Riebart
    Guest
    Well, the idea would be to add in a new parameter to the NewShipType being created that would get modified later. Adding the variable is fine, it is referencing it. I can add in a NewShipType.MaxRadius = 2500 (Almost an identical clone to the NewShipType.maxhealth = _____), but I cannot reference that variable anywhere else in the .ship file.

    It occurs to me now that I might have t go looking for the constructor used to create the object - the StartShipConfig() method. It might return the object with all variables at their default initialization, and so adding a new parameter to that should work, but then I still can't be guaranteed that I can reference it.

    Still on this vein, it might be that the reason I can use the NewShipType.MaxRaduis=2500 line is that is silently fails, and when I try to reference it, the interpreter throws me a null, which is read into the int paramter as a 0. That would explain the symptoms I am getting, and that means I now need to go hunting around for that method.

    As for modifying it, it would be through a research. I've got the research command in, and it researches fine, but since I've got this whole variable problem, it doesn't do anything. So it isn't just arbitrary changes, it is through an already implemented game-mechanic (Research in this case, although if i can get this to work, I'll also be looking into modifying weapons and such on the fly).

    I should probably take a look at the scout and torpedo frigate .ship files, since those have non-HP/speed values modified by research and I might be able to glean something from those. I'll post back if I get anything.

  7. #7
    Riebart
    Guest
    P.S: I apologize in advance. My posts tend to be very wordy, but I try to keep them from rambling...I don't always succeed.

  8. #8
    HELLO!!! variables like "NewShipType.abc" aren't going to work! LUA is used to configure types of ships. Once this information is loaded it is kept constant, and cannot be changed until HW2 is closed, and then restarted. Why such vars won't work is because there is no C Interface to handle them! (like HW, except that here we have LUA, instead of those scripts)
    Ex. NewShipType.maxHealth would assign its value to a struct in C(++), like <the Ship>.maxHealth, but the table index you give for the LUA parameter (yes. NewShipType.abc is equal to NewShipType["abc"]) isn't referenced, or read by HW2 code.
    Further, I don't think you'll be able to, in any way, access these ship's data from other LUA 'Scope' (ex. in gamerules)
    Similarly, you won't be able to call StartShipConfig() from any other scope (like gamerules)

    So research is the only way, I guess.

  9. #9
    Riebart
    Guest
    4E534B, if I'm understanding you correctly, then it just treats these LUA scripts as data files, which it loads on startup into data structures that the HW2 core code then works with. if this is the case, then there won't be a pre-defined variable for me to work on (barring re-rusing one of the less useful ones....like Mass. I could add a multiplier to the Mass or something).

    Sinc my method of modifying it ingame would be through research (not a custom script), it is just getting the data structures I want in there to begin with that is the problem. I might give that trick of modifying another variable (I.e: Mass), then have the research modify Mass, and therefore my defense field radius. I'll give that a fast test, then post back.

    *Edit: Nope, Making a modifier to Mass just crashes the game. Referencing the Mass variable doesn't do anything, just gives me a radius of 0 or something. It appears that I can't reference anything in these LUA scripts because, as was mentioned, they appear to be treated just as data files and not as actual code. They are just loaded into an object. This means my job just became a hell of a lot harder, if it is even still possible.

  10. #10
    Making a modifier to Mass just crashes the game

    Because it was never defined in HW2... HW2 doesn't know what to do; that multiplier is unknown to HW2. The connections for multipliers and abilities are not directly related to ship configurations.
    As I said, once the stats are loaded, they are kept constant. There's no way to change them because, (correct me if i'm wrong) they (stats like mass) are kept in a 'protected' area (a feature of C++ not in C).
    Look into the RDN doc for multipliers and abilities. That'll explain all multipliers available. Further, you can use the vars, if and only if you just want the code to reference them while configuring ships.
    Again it's not that LUA is used for sole purpose as data scripts; the way HW2 communicates with LUA interpreter is limiting things (scripts for configuring ships are called from a different 'world' than the gamerule scripts; there is just no way that they can be inter-related in any manner, with this respect)
    (barring re-rusing one of the less useful ones....like Mass. I could add a multiplier to the Mass or something).
    you mean something like assigning defence field radius to mass; then what will happen is that the current value of mass will get assigned to the radius, and will not remain in sync. This, too won't work, EVEN if there was a multiplier for mass, because they both have different places for storage of their data. (you cannot work with pointers in LUA* , each var has it's own mem. allocation)
    Research is the only way (other than 'invisible' sub-systems)
    ----
    * well, there is a data type--'userdata' to handle C pointers, but I don't think the LUA for HW2 has any facility to deal with them

  11. #11
    Riebart
    Guest
    I think I'm not really conveying myself well, so here's what I tried:

    Code:
    [hgn_defionturret.ship]
    ...
    NewShipType.mass = 20
    ...
    addAbility(NewShipType, "DefenseFieldAbility", 1, 0, NewShipType.mass, 2400, 1200, 1, 0.6, 0, "defensefield_sphere_spray")
    addAbility(NewShipType, "DefenseFieldShieldAbility", 0, NewShipType.mass, 0, 0)
    ...
    [/hgn_defionturret.ship]
    Code:
    [research.lua]
    ...
    UpgradeType = Modifier, 
    TargetType = Ship, 
    TargetName = "Hgn_DefIonTurret", 
    UpgradeName = "mass", 
    UpgradeValue = 1.3, 
    ...
    [/research.lua]
    is what I'm trying to do. It won't even do this. Even though mass is equal to 20, the radius of defense field is nonexistent (Probably 0) before I even upgrade. I think what you're trying to tell me is that there is no way to make references in the LUA scripts in such a way that'll make the HW2 interpreter work with them.

    The only reason I can't see creating a new variable NewShipType.MaxRadius in the .ship file wouldn't work is because it isn't being read in by the interpreter, as there isn't a maxradius variable in the template...Hopefully if that is the case, I can find the template in the Big file somewhere and modify that.

  12. #12
    as there isn't a maxradius variable in the template
    It isn't defined in HW2. In no way is this goind to work ('maxradius'). Look into the manual of RDN which tells about Multipliers and abilities. That'll tell how you need to modify research.lua for radius upgrade.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Posting Permissions

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