Jump to content
Null 45

Lua C++ Extension DLL Example

9 posts in this topic Last Reply

Highlighted Posts

Posted:
Last Online:  
 

This DLL extends the Lua system by adding two new C++ functions for the Lua code to call. The first function computes the binary logarithm of the specified number, and the second function returns the NAM version string if that mod is installed.

The DLL is intended as a demo/example for DLL and Lua developers. Its only in-game functionality is showing a message box upon entering an established city, which probably isn't very interesting for most users.

Download: https://github.com/0xC0000054/sc4-lua-extension-example/releases

Source Code: https://github.com/0xC0000054/sc4-lua-extension-example

System Requirements

  • Windows 10 or later

The DLL may work on Windows 7, but I am not able to test that.

Installation

  1. Close SimCity 4.
  2. Copy SC4LuaExtensionExample.dll and LuaExtensionExample.dat into the top-level of the Plugins folder in the SimCity 4 installation directory or Documents/SimCity 4 directory.
  3. Start SimCity 4.

Usage

The game's Urgent Advice dialogs must be enabled for the plugin to work. It will show a Lua C++ Function Test message box upon entering an established city.

MessageBox.jpg.f5c2a1f59f5c4400490e98d32eb49e4d.jpg

The code used to show the Urgent Advice dialog is adapted from code created by @CorinaMarie.

Troubleshooting

The plugin should write a SC4LuaExtensionExample.log file in the same folder as the plugin.
The log contains status information for the most recent run of the plugin.

  • Like 3

Share this post


Link to post
Share on other sites
Posted:
Last Online:  
 

Tested:

imgW10-3343.jpg

*:)

  • Like 1

Chance favors the prepared mind. ― Louis Pasteur  
Remember, a few hours of trial and error can save you several minutes of looking at the README. -- I Am Devloper (on Twitter)

Clickable ---> The Best of Cori's Posts  (scroll down a wee bit there)    Something fun: MySimtropolis - Invitation to become a SimCity 4 MySim

Are you new here? Check out the Introduction and Guide to Simtropolis.

Share this post


Link to post
Share on other sites
Posted:
Last Online:  
Currently: Viewing Topic: Show us What you're Working On
 

I'm just seeing this now and I'm wondering about the possibilities that this test example might allow.  What sort of game functions (currently coded in C++?) could also be adopted to LUA? 

I'm interested in possibly adopting buildings to create a custom query similar to how Cori/Cyclone Boom did here: 

 

Share this post


Link to post
Share on other sites
  • Original Poster
  • Posted:
    Last Online:  
     
    3 hours ago, Kel9509 said:

    What sort of game functions (currently coded in C++?) could also be adopted to LUA? 

    In theory the C++ side could call any of the game systems that are available in the city view. Maxis did that with the the ordinance Lua functions (ordinance_set_onordinance_name, etc.), those methods interact with the ordinance simulator.

    The game.g_nnn variables in that Cori/Cyclone Boom UI are just numbers or strings that the game tosses over to the Lua side.

    Share this post


    Link to post
    Share on other sites
    Posted:
    Last Online:  
    Currently: Viewing Topic: Show us What you're Working On
     
    2 hours ago, Null 45 said:

    In theory the C++ side could call any of the game systems that are available in the city view. Maxis did that with the the ordinance Lua functions (ordinance_set_onordinance_name, etc.), those methods interact with the ordinance simulator.

    The game.g_nnn variables in that Cori/Cyclone Boom UI are just numbers or strings that the game tosses over to the Lua side.

    Ok.  I guess I don't know enough about the game systems to understand what we're still missing in Lua, which otherwise would need C++ functionality to view.  I don't know what I'm missing, I guess.

    Share this post


    Link to post
    Share on other sites
    Posted:
    Last Online:  
     

    I've no idea if it's possible, but we might be able to create interesting new mods if everything the Auto Run Cheats DLL can do could be called from LUA. This would allow popup messages with those as linkys and one could agree by clicking them.


    Chance favors the prepared mind. ― Louis Pasteur  
    Remember, a few hours of trial and error can save you several minutes of looking at the README. -- I Am Devloper (on Twitter)

    Clickable ---> The Best of Cori's Posts  (scroll down a wee bit there)    Something fun: MySimtropolis - Invitation to become a SimCity 4 MySim

    Are you new here? Check out the Introduction and Guide to Simtropolis.

    Share this post


    Link to post
    Share on other sites
  • Original Poster
  • Posted:
    Last Online:  
     
    1 hour ago, CorinaMarie said:

    I've no idea if it's possible, but we might be able to create interesting new mods if everything the Auto Run Cheats DLL can do could be called from LUA.

    Executing cheats should be possible, e.g. having a lua_extensions_execute_cheat command that could run everything that the cheat box can. But the Auto Run Cheats DLL has access to game notifications that are not present in Lua, and I don't think many of those notifications could be exposed to Lua.

    • Thanks 1

    Share this post


    Link to post
    Share on other sites
    Posted:
    Last Online:  
    Currently: Viewing Topic: Show us What you're Working On
     

    Would it be possible to create a cheat that permits you to run any variable Simcity4 has?  For instance, you could enter a cheat code to bring up a dialog box that permits you to enter in any variable, like "#game.g_num_parks#", which is the variable that displays the number of parks, and that result would display somewhere?  Or is that too much?

    Share this post


    Link to post
    Share on other sites
  • Original Poster
  • Posted:
    Last Online:  
     
    4 hours ago, Kel9509 said:

    Would it be possible to create a cheat that permits you to run any variable Simcity4 has?

    A cheat code that takes the token name as a parameter would be easier to implement than a dialog, the cheat code could then show a message box with the result.

    Text token is the official name of the #variable# blocks that the game can replace with a new value, I guessed as much based on the fact that the string handling class is called detokenizer. But after searching for token in the SimCity_1.dat I discovered that one of the leftover Lua files is the Maxis Lua programming reference (TGI 0xCA63E2A3, 0x4A5E8EF6, 0xFFAEC42B), which confirmed the name.

    @CorinaMarie or others may have already known about that Maxis Lua programming reference. Interestingly there are a few more format strings listed in that file which the game's Lua files don't appear to use.

    The date and time format strings appear to be broken, but the following format strings work. None of these values support floating point because Maxis decided to convert the Lua double to an integer before passing it to the formatting methods. This is understandable for the money formatting, but is strange behavior for the other number types.

    #m@500000# prints the 500000 value as §500,000 in English, it would possibly change the format for the user's chosen UI language.

    #n@2000# prints the 2000 value as 2,000 in English, it would possibly change the format for the user's chosen UI language.

    #s@2000# prints the 2000 value as 2000 in English, it would possibly change the format for the user's chosen UI language.

    #p@200# prints the 200 value as 200% in English, it would possibly change the format for the user's chosen UI language.

    • Thanks 1

    Share this post


    Link to post
    Share on other sites

    Sign In or register to comment...

    To comment in reply, you must be a community member

    Sign In  

    Already have an account? Sign in here.

    Sign In Now

    Create an Account  

    Sign up to join our friendly community. It's easy!  

    Register a New Account


    ×

    Thank You for the Continued Support!

    Simtropolis depends on donations to fund site maintenance costs.
    Without your support, we just would not be in our 24th year online!  You really help make this a great community. *:thumb:

    But we still need your support to stay online. If you're able to, please consider a donation to help us stay up and running. This helps sustain a platform where we can share our community creations for years to come.

    Make a Donation, Get a Gift!

    Expand your city with the best from the Simtropolis Exchange.
    Make a Donation and get one or all three discs today!

    STEX Collections

    By way of a "Thank You" gift, we'd like to send you our STEX Collector's DVD. It's some of the best buildings, lots, maps and mods collected for you over the years. Check out the STEX Collections for more info.

    Each donation helps keep Simtropolis online, open and free!

    Thank you for reading and enjoy the site!

    More About STEX Collections