Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Starsector 0.97a is out! (02/02/24); New blog post: Simulator Enhancements (03/13/24)

Author Topic: what is wrong with this copypaste rules.csv of the LP_tithe  (Read 3202 times)

nomadic_leader

  • Admiral
  • *****
  • Posts: 725
    • View Profile

So I just want to make a simple mod that copies the LP tithe behavior to the pirates. Just using the same LPTitheCalc in the Somehow I got it working initially (sort of) but then it stopped working, and now I can't get it working again. Not even the initial setup. Seriously? What condition isn't being met?

Test scenario: I start a new game, console command spawnfleet pirates 10. Your newgame rep with pirates is already 68 which is Hostile, so it should be fine and match the conditions.

Attached is the whole mod file. Note I didn't really read the rules.csv documentation, I don't know java, don't understand fundamental concepts of starsector modding, etc. Thanks!

Here is the rules csv file.
(Man having to work with csv is really awkward. Even TSV would be more text editor friendly. But having to use some spreadsheet editor and mess around with the size of the cels and not have grep/regex, just in order to not look at a jumble of linebreaks is a real drag.)

Here's the rules.csv file in mod/data/campaign/rules.csv

Code
id,trigger,conditions,script,text,options,notes
#pirate bribe paying,,,,,,
PirateBribeCheck,BeginFleetEncounter,"$faction.id == pirates score:100
RepIsAtWorst $faction.id HOSTILE
!Pirate_bribePaid
!Pirate_bribeAskedFor
$relativeStrength >= 0
LPTitheCalc","Pirate_bribeConv = true 0
Pirate_bribeAskedFor = true 7
AddText ""You're being hailed by the $faction $otherShipOrFleet."" $faction.baseColor",,,
PirateBribePre,OpenCommLink,$entity.Pirate_bribeConv score:100,"SetTextHighlights $entity.LP_tithe
$entity.ignorePlayerCommRequests = true 1","""Submit and repent! Your use of sinful technologies may be forgiven, for a tithe of $entity.LP_tithe credits.

Resist, and only God's holy vacuum will show you mercy.""
OR
""Servant of Moloch! Redemption is not out of reach even for you. A tithe of $entity.LP_tithe credits may set you upon the first step of the Path of Ludd.""

""Forswear this pennance and be met with annihilation, cursed by Ludd in the next life. The choice is yours.""","payBribe:Pay the tithe
cutCommLink:Cut the comm link",
PirateBribePay,DialogOptionSelected,$option == payBribe,"AddText ""Lost $entity.LP_tithe credits"" textEnemyColor
SubCredits $entity.LP_tithe
$entity.Pirate_bribePaid = true 30
MakeOtherFleetNonHostilePirate_bribe true 30
AddText ""\""Blessings of Ludd be upon you.\""""
AddText ""The connection is cut before you have a chance to respond.""
ShowDefaultVisual
EndConversation","""Perhaps your soul is not yet lost to the machine.""
OR
""Truly, Ludd's hand has guided you.""",cutCommLink:Cut the comm link,


[attachment deleted by admin]
Logged

Histidine

  • Admiral
  • *****
  • Posts: 4661
    • View Profile
    • GitHub profile
Re: what is wrong with this copypaste rules.csv of the LP_tithe
« Reply #1 on: June 13, 2017, 05:37:21 AM »

If it makes error messages, post them.
If it doesn't have any errors but just doesn't use your dialog options: The checks for each CSV row and its conditions are written to console/starsector.log, so you can look in there and see where it's going wrong.

Anyway, I found two general issues:
- Variables being assigned need to be prefixed with '$', e.g. '$pirateCount = 1'. Else the game treats it as an attempt to call the rule command pirateCount.
- Typo: MakeOtherFleetNonHostilePirate_bribe should have a space: MakeOtherFleetNonHostile Pirate_bribe

Fixed those and now it works for me.

Code: csv
id,trigger,conditions,script,text,options,notes
#pirate bribe paying,,,,,,
PirateBribeCheck,BeginFleetEncounter,"$faction.id == pirates score:100
RepIsAtWorst $faction.id HOSTILE
!$Pirate_bribePaid
!$Pirate_bribeAskedFor
$relativeStrength >= 0
LPTitheCalc","$Pirate_bribeConv = true 0
$Pirate_bribeAskedFor = true 7
AddText ""You're being hailed by the $faction $otherShipOrFleet."" $faction.baseColor",,,
PirateBribePre,OpenCommLink,$entity.Pirate_bribeConv score:100,"SetTextHighlights $entity.LP_tithe
$entity.ignorePlayerCommRequests = true 1","""Submit and repent! Your use of sinful technologies may be forgiven, for a tithe of $entity.LP_tithe credits.

Resist, and only God's holy vacuum will show you mercy.""
OR
""Servant of Moloch! Redemption is not out of reach even for you. A tithe of $entity.LP_tithe credits may set you upon the first step of the Path of Ludd.""

""Forswear this pennance and be met with annihilation, cursed by Ludd in the next life. The choice is yours.""","payBribe:Pay the tithe
cutCommLink:Cut the comm link",
PirateBribePay,DialogOptionSelected,$option == payBribe,"AddText ""Lost $entity.LP_tithe credits"" textEnemyColor
SubCredits $entity.LP_tithe
$entity.Pirate_bribePaid = true 30
MakeOtherFleetNonHostile pirate_bribe true 30
AddText ""\""Blessings of Ludd be upon you.\""""
AddText ""The connection is cut before you have a chance to respond.""
ShowDefaultVisual
EndConversation","""Perhaps your soul is not yet lost to the machine.""
OR
""Truly, Ludd's hand has guided you.""",cutCommLink:Cut the comm link,
« Last Edit: June 13, 2017, 05:55:00 AM by Histidine »
Logged

nomadic_leader

  • Admiral
  • *****
  • Posts: 725
    • View Profile
Re: what is wrong with this copypaste rules.csv of the LP_tithe
« Reply #2 on: June 16, 2017, 09:26:27 AM »

Thanks so much! I really appreciate the guidance and help.

Now say if I eventually want to make a modified version of the LP_Tithe in api.impl.campaign.rulecmd  to calculate the fee in various ways, I can't just go and mess around with the .java file inside starfarer.api.zip. That's not allowed, right? And anyway that .zip is just for reference, right? The actual game uses a compiled version called starfarer.api.jar or .obj or something?

I have to make a new jar or new java in a proper part of the mod hierarchy?

I guess I'll take a look at the nexerlin source to see how you implemented new rulecmd stuff.
Logged

nomadic_leader

  • Admiral
  • *****
  • Posts: 725
    • View Profile
Re: what is wrong with this copypaste rules.csv of the LP_tithe
« Reply #3 on: June 16, 2017, 01:05:22 PM »

By the way, just in case anyone is curious, in addition it wasn't even loading the rules.csv because of the way my crummy old version of mac excel was saving the line breaks in the csv file or something. using my text editor i saved the file with windows style (CRLF) breaks.
Logged

Histidine

  • Admiral
  • *****
  • Posts: 4661
    • View Profile
    • GitHub profile
Re: what is wrong with this copypaste rules.csv of the LP_tithe
« Reply #4 on: June 16, 2017, 07:08:34 PM »

Yeah, starfarer.api.zip is just for reference. You could modify the contents of starfarer.api.jar directly, but that's obviously not recommended for a bunch of reasons.

Best thing to do is create a new mod, make a rules command class in the com.fs.starfarer.api.impl.campaign.rulecmd package, and compile to .jar (make sure to reference said jar in mod_info.json). Now you can use your new command in rules.csv.
Logged

nomadic_leader

  • Admiral
  • *****
  • Posts: 725
    • View Profile
Re: what is wrong with this copypaste rules.csv of the LP_tithe
« Reply #5 on: June 16, 2017, 08:13:42 PM »

So that kind of thing has to be compiled to jar? It can't just be an uncompiled .java file in the correct heirarchy of folders inside the mod, that's compiled when starsector is run or something?

For testing it would eliminate a step if I don't have to compile a new jar each time I change the .java file. And I don't want to obfuscate the code from any curious users. (though I know for this, one can just include a source directory)
Logged

Histidine

  • Admiral
  • *****
  • Posts: 4661
    • View Profile
    • GitHub profile
Re: what is wrong with this copypaste rules.csv of the LP_tithe
« Reply #6 on: June 16, 2017, 08:20:42 PM »

You can try Janino runtime compilation, but there's a bit more work involved and you can't use some Java features like generics. (There are also reports of it failing to load a class for no good reason)

To do it this way, put the .java file in data/scripts/<someSubDir> and define the class's package accordingly, then add the package to settings.json.
Logged

nomadic_leader

  • Admiral
  • *****
  • Posts: 725
    • View Profile
Re: what is wrong with this copypaste rules.csv of the LP_tithe
« Reply #7 on: June 18, 2017, 04:29:24 PM »

Hmm, ok I might try that too. I don't know what defining a class' package is, or what java generics are, but that sort of thing I can look up myself, now that I know what to look for.
Logged