• Welcome to SC4 Devotion Forum Archives.

SOLVED: Reward Buildings

Started by RobertaME, January 13, 2019, 01:02:38 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

RobertaME

First Post.  ;D

I'm getting back into SC4 after a 10 year gap in play and am really getting into modding. I am able to do most things with little difficulty after reading the forums passively for years so I felt very confident when I wanted to mod a custom lot I downloaded to become a reward building. I examined several reward lots and learned the basic logic of LUA files and attempted to adapt my lot to have conditionals that would only make it available if certain other properties were already built in the city.

To be specific I am modding the SM2 Modular Solar Panels so that you HAVE to build inverters before you can build the panels... and also limit the number of them you can build based on how many inverters you've built. (a 16 to 1 ratio) So I wrote the following LUA Script:

--#-package:490ff4a1# -- package signature

------------ Created by RobertaME, Jan 2019 ------------------
------------ Requires --- Solar Inverters

--------- unlocker functions and variables -----------
Modular_Solar_Panels_hex_ID = "490ff4a1"
------------------------------------------------------
------------- unlocker news message ------------------

a = create_reward_cityplanning('490ff4a1')
function a.condition()
if (sc4game.automata.get_source_building_count(hex2dec('b90b4dc3'))) = 0 then
return [[text@490ff4a4]]
else
if ((sc4game.automata.get_source_building_count(hex2dec('490ff4a1'))/16)/sc4game.automata.get_source_building_count(hex2dec('b90b4dc3'))) >= 1 then
return [[text@490ff4a4]]
else
return reward_state.AVAILABLE
end
end
a.once = 0
a.timeout = tuning_constants.ADVICE_TIMEOUT_SHORT
a.title = [[text@490ff4a2]] -- title instance ID
a.message = [[text@490ff4a3]] -- body text instance ID
a.priority  = tuning_constants.ADVICE_PRIORITY_URGENT -- triggers popup
a.mood = advice_moods.GREAT_JOB -- green title
a.persist = 0


490ff4a1 is the IID of the Modular Solar Panels themselves
490ff4a2 is the IID of the LTEXT for the popup message
490ff4a3 is the IID of the LTEXT for the message body
490ff4a4 is the IID of the LTEXT for the reason the lot is not available
b90b4dc3 is the IID of the Solar Inverters by SM2

I made sure the Type for the LUA was ca63e2a3, the Group is 4a5e8ef6, and the IID was the same as the Exemplar IID. (490ff4a1) I then set the Property "Conditional Building" in the Exemplar to 0x01 and tested in the game. The Modular panel was greyed out as it should be, but would not display the reason for it not being available. (the contents of LTEXT 490ff4a4... only showing the description text) Furthermore, when I placed an Inverter down in a city the Solar Panels failed to become available.

All edits are done in the latest version of iLive Reader and I have all necessary dependencies. The lots work fine without setting the conditionals, and I cannot see any difference in my LUA scripting versus other functional reward lots... so what am I missing?

Is there some other setting I should be changing in the Exemplar... or some other Property I should be adding to it to let the game know that the LUA needs to be referenced? I'm at my wits end and would very much appreciate any help anyone could provide.

Thanks in advance and thanks to all the various contributors to the SC4 community over the years.

Andreas

It's been a while since I was making a reward lot, but if I remember correctly, the instance ID of the LUA file must start with a zero. It should be sufficient if you take the lot's instance ID (490ff4a1), replace the 4 with a 0, and edit the first line of the LUA script accordingly.
Andreas

RobertaME

An interesting thought, though I should point out that two of the functional reward lots that I've been examining have IIDs that start with "F" (JBSimio's Post Office Reward) and "1". (xannepan's SC4 Functional Airports Version 2.2 runway rewards)

That said, I tried your suggestion and no change. It still doesn't display the LTEXT showing why the lot isn't plopable and even after building the Inverter the panels remain unbuildable.

I feel like I'm missing a step... like there's something else you need to do to make a lot a reward lot other than adding the "Conditional Building" Property to the Exemplar and adding the LUA and LTEXT files.

Does the logic of my LUA file seem sound? It's been a long time since I did any real programing, (longer than a lady likes to admit) but the logic and language seem sound to me. I would of course love a second set of eyes to confirm it though.

Thanks for your help! ;D

Andreas

Unfortunately, programming is the one thing that doesn't want to go into my head, so I always have a hard time to verify any code. I understand the basics and can edit things, but I'm lost when I have to write things from scratch. For your lot, I suggest to exchange the code to something simple, like a basic ,,number of residents" or so, then you can check if the files, ID and such work propely. As for the ,,zero" thingy, the ID of the LUA file might not be relevant, but at least the package ID in the code always starts with a zero in any script that I have seen.
Andreas

RobertaME

So I changed the conditions to something easy to get (Pop 5k) and I still get the same issue... Item greyed out, no description message as to why I can't get it, and doesn't change when the conditions are satisfied.

Are you sure there isn't anything else needed in the file other than the Conditional Building property in the Exemplar and adding the LUA and LTEXT files? Something in the Exemplar that points to the LUA file to get it to run the script? Because it's acting like it doesn't see the LUA file at all.

My next step is to take an existing working Reward property and trying to modify it to have the same properties as my target building... but there are still many Exemplar properties that I don't fully understand so this isn't my first choice. Any other options that you know of?

Thanks for the help! ;D

Andreas

Can you attach the lot in question, or drop me an e-mail (andreas@simcityplaza.de)? Then I can have a look myself. In theory, everything that you did should make it working, but maybe I find something else by comparing your lot to mine when looking through all relevant properties.
Andreas

RobertaME

File is attached. Note that I did not make the lot, it was made by Simmer2 and I take no credit for it, nor am I intending to distribute it... it's for my use only and to help me learn how reward lots work. It also doesn't have the same stats as the original lot. I edited the properties to put it in line with what I feel is fair within the game to be balanced with the other power plants and not make them all obsolete. I also added a lot of realism, tweaking the rate of degeneration do 30 years before needing to be replaced, matching the degeneration curve to real life examples of commercial PVs, and jacking the build cost up a lot. (so this lot's stats are almost completely different than Simmer2's original on the LEX)

Note that it still has all the dependencies the original lot has. (SM2 Essentials, SM2 Mega Prop Pack Vol1, & SM2 Mega Prop Pack Vol2) I have also turned off the Conditional Building property in the Exemplar so I can use it in game for testing other things, so that will need to be set back to x01.

Thank you for taking the time to help me get this right! Once I'm done learning all this stuff I can try my hand at content creation and help give back to the community!  ()stsfd()

Andreas

I got the lot and tried a few things, but it didn't work as expected. Then I modified the reward conditions to something simple ("minimum population of 50"), and it worked as desired, which means that the lot itself should work as a reward alright. I was trying to reduce your reward conditions to something that is more easier than your calculation ("at least one power inverter"), but that broke the script somehow. I must be overlooking something, will check again tomorrow (it's bedtime in Europe).
Andreas

Andreas

Ok, I had another look at the files, and I guess I finally found a way how to make the reward working as desired. It appears that the sc4game.automata.get_source_building_count(hex2dec('b90b4dc3')) function doesn't work "out of the box", but only in conjunction with the BSC Essentials installed and a custom Occupant Group tied to the lot(s) that are supposed to be counted. If you look at the first LUA in the bsc_Essentials_OG.dat, daeley created a range of 0xB5C00### that is available for counting in the script, so you need to attach a unique Occupant Group to the Solar Power Inverter lot (I used 0xB5C00DC3 in my test run, obviously, you have to find one that hasn't been used elsewhere). If you use the same ID in the LTEXT file that displays the reward conditions, you will see that it properly displays the number of lots that have been plopped, too.

Now have another look at the reward lot (the Modular Solar Panels). Set Conditional Building to True again, and maybe change the REP count from 1 to the default 0, although it seems that both work fine. I also noticed that the Group IDs of the reward-related LTEXT files is always 0x6A231EA4, so you might need to change that for the texts being displayed properly. As mentioned before, most reward tutorials suggest that the package ID (first line in the LUA script) has to be 0, although it seems to work with other numbers, too. The instance ID of the LUA script doesn't have to match that, as it seems, so using the same one as the exemplar file should be ok. Finally, the sorting of the unlock conditions seem to follow a certain scheme, it should be "if xxx is met, then unlock the reward, otherwise display conditional text".

So after all that tinkering, I came up with a simple script that counts the number of inverter lots (using the 0xB5C00DC3 occupant group) which unlocks the solar panel lot. I tried using your complete reward conditions, but that didn't work, so maybe the syntax you used doesn't work. Unfortunately, I'm not capable enough to come up with a better formula, so you might have to tinker a bit more yourself. Another downside of making a lot a reward is that after plopping a reward lot, you have to go to the menu and select the lot again before plopping. This is kinda annoying, since you usually want to plop several solar panels in a row, once unlocked. I wonder if it makes more sense to plop a number of solar panels first, which will unlock the inverter lot after all.

Anyway, here's the reward script that I came up with, this one definitely works for me:

--#-package:090FF4A1# -- package signature

------------ Created by RobertaME, Jan 2019, modified by Andreas ------------------
------------ Requires --- Solar Inverters

--------- unlocker functions and variables -----------
Modular_Solar_Panels_hex_ID = "490FF4A1"
------------------------------------------------------
------------- unlocker news message ------------------

a = create_reward_cityplanning('490FF4A1')
function a.condition()
if  (sc4game.automata.get_source_building_count(hex2dec("B5C00DC3")) > 0)
then
return reward_state.AVAILABLE
else
return [[text@490FF4A4]]
end
end
a.once = 1
a.timeout = tuning_constants.ADVICE_TIMEOUT_LONG
a.title = [[text@490FF4A2]] -- title instance ID
a.message = [[text@490FF4A3]] -- body text instance ID
a.priority  = tuning_constants.ADVICE_PRIORITY_URGENT -- triggers popup
a.mood = advice_moods.GREAT_JOB -- green title
a.persist = 1
Andreas

RobertaME

Thank you so VERY much! I finally understand reward lots and LUA files!  ;D

I agree that having to go into the menu to plop each panel is a bit of a pain, but I got used to that when I was building my giant airport using Functional Airports and I would be plopping a large number of grass sections and the game would suddenly decide that building more grass was disallowed everywhere until I would go back into the menu and select the lot again... sometimes having to do this for every single section of grass. (plop a section, cursor turns red and won't allow plopping more... go back into the Airports menu and select the grass again... plop one more section... cursor turns red... go back to the menu... plop one more section... cursor turns red... etc.) Not sure what causes that, but it sure is irritating when plopping a large number of the same type lot. (it does it for parks too... ::shrug:: ) I just put up with it so going back into the menu for each panel is fine with me.

I've also been working on learning how to make plop lots growable and vice versa and editing FSH files for custom textures. (I know this probably sounds like old hat to you... but it's new and fun for me to make a change and see it reflected in the game!) I think I may even eventually try tackling my pet peeve in SC4... Monorails.

In real life one of the main advantages of Monorails over other more traditional rail systems is that the simple pylons supporting the track could be put darn near anywhere... even down the middle of an Avenue or along the side of a road... all without disturbing the existing roadways or other areas. So I want to eventually make new pieces for Monorail in Avenue and Monorail over Road. (and street, and rail, and ground highway, and RHW...) I know it's complex, time consuming, and there are issues with congestion modeling, but I think the result of being able to put Monorails into a long-established city without demolishing whole swaths of zoning would be worth it. (also they need more than just one set of gentle curves that the NAM gives you... those are fine, but are too big for any sort of congested area... and the default corners are too sharply angled) I know a lot of people never bother with Monorails in SC4 and so there hasn't been that much work done to improve them, but I figure if I can get down the basics of the 3d modeling (my weak area, I have solid work done on the network side... just trying to solve intersections ATM) I can pull it off and (hopefully) share my work with the community that has given me so much enjoyment.

Thanks again for all your help!