I was attempting to try some very basic scripting, namely making shortcuts for some of those RSI-inducing in-game commands. I was thinking this should work along the lines of defining a new command named "mo" and having that execute the actual bb.moveobjects command, for example.
But now I'm already stuck because all the examples I looked at are using commands that I can find in the game scripts (like set_clock_speed in clock.pyo.py), however that moveobjects one I can not find. =/ Same problem with the unlocking stuff ones.
Am I making this too complicated? Is there some other way of defining aliases? The way I understood it, one would have to do that when defining the command in Python, but maybe I'm misunderstanding ..
Also, does the "plunking loose files in /unpackedmod" thing still work?
I have a feeling you aren't supporting loose .py files any more .. could that be? Because I cannot even get a "Hello World" thing to work in .py form that I literally copied and pasted from mods I am currently using in my game =/ (the creator/s had put the .py in the zips along with the pyo)
Here it says "Loose .py files are supported out of the "Mods" folder" - I took this (in the context of hot loading scripts) to mean they would always be loaded when the game starts, just not *re*loaded. I tried both from the Mods folder and /Mods/unpackedmod, the unpackedmod folder is listed in my resource.cfg as well .. but still, all I get is "Unable to execute command".
I'd actually prefer not having to compile this .. would make it a lot easier to add on to it every now and then.
It could just as well be that I'm still making some stupid mistake in my code (I have no previous experience with Python) .. not sure.
I just tried the example Maslow mod as a loose .py file, and it works for me. Make sure the "Script Mods" option is checked. If it's unchecked, you'll have to restart the game.
Even as a loose file, the mod should show up the in the list... does it for you?
You mean the list in Game Options > Other > View Custom Content? I don't see anything there that could be the .py in question .. but to me it looks like it lists under "Script Mods" every .zip that it finds, not script mods per se (I have two zips listed there that do not contain any scripts, I just forgot to remove them). Also I have two empty lines in the nonscript department. Hm. What would it normally list there, the file name of the .py?
You mean the list in Game Options > Other > View Custom Content? I don't see anything there that could be the .py in question .. but to me it looks like it lists under "Script Mods" every .zip that it finds, not script mods per se (I have two zips listed there that do not contain any scripts, I just forgot to remove them). Also I have two empty lines in the nonscript department. Hm. What would it normally list there, the file name of the .py?
Correct. If you were to plop maslow.py in there, it should say maslow.
Still no dice, the Mods panel is entirely empty then.
Weird.
I will, for science, try going online, see whether that makes a difference .. I dunno whether this could be similar with CC not being recognised in the Library unless going online-but-not-really etc pp .. ETA, Nope.
ETA, do I perhaps need to tell the game something about .py files in resource.cfg?
@sims4.commands.Command('h', command_type=sims4.commands.CommandType.Live)
def headline(enable:bool=None, _connection=None):
if enable is not None:
if enable:
command = 'headlineeffects on'
sims4.commands.client_cheat(command, _connection)
else:
command = 'headlineeffects off'
sims4.commands.client_cheat(command, _connection)
else:
output("You need to turn this on or off with 't', 'true', 'on', '1', 'yes', 'y', 'enable' or 'f', 'false', 'off', '0', 'no', 'n', 'disable'")
The actual commands are working as expected (like with "h 1" or "h off" or whatever), but when I only type "h" I don't get the expected output .. and I don't understand why not. (The reason I want that is to prevent myself from forgetting that this is not a toggle)
?
lastexception.txt is not complaining about me (as it did yesterday, about my untidy whitespaces).
(I also have a feeling that the inner if is probably unnecessary as I can probably pass the bool directly somehow, I only don't want to change too many things at once)
The system requires you to enter a valid value for 'enable', i.e. a value that can be converted to a boolean. I believe 'None' is not being converted, and therefore the command is not being issued at all.
No the enable/disable thing worked fine -- I found what my problem was; I just didn't tell it what the output would be. I mean where to output it TO.
This works now:
@sims4.commands.Command('h', command_type=sims4.commands.CommandType.Live)
def headline(enable:bool=None, _connection=None):
output = sims4.commands.CheatOutput(_connection)
if enable is not None:
if enable:
command = 'headlineeffects on'
sims4.commands.client_cheat(command, _connection)
else:
command = 'headlineeffects off'
sims4.commands.client_cheat(command, _connection)
else:
output("You need to turn this on or off with 't', 'true', 'on', '1', 'yes', 'y', 'enable' or 'f', 'false', 'off', '0', 'no', 'n', 'disable'")
\o/
(You are already doing the boolean conversion for me )
ETA: oh but is there a way to give it multiple aliases for the same command? Like, can I pass it a list instead of the string somehow?
Well, I didn't get anything that mentioned the name of my .py .. it does talk about "xml.parsers.expat.ExpatError: not well-formed (invalid token)" but I'm also testing for stuff like "h 5" (and I'm also trying to get other things to work) so it's not very surprising that it finds *something* to complain about =D.
That was exactly what I tried =D but that did not work, the result was "invalid command" or "unable to" or something along those lines (in the console output) .. I didn't take a screenshot of the exact wording, but I can try again and post one.
My code was
@sims4.commands.Command('t', 'd', 'debug', command_type=sims4.commands.CommandType.Live)
def testing(enable:bool=None, _connection=None):
output = sims4.commands.CheatOutput(_connection)
if enable is not None:
if enable:
command = 'testingcheats on'
sims4.commands.client_cheat(command, _connection)
else:
command = 'testingcheats off'
sims4.commands.client_cheat(command, _connection)
else:
output("You need to turn this on or off with 't', 'true', 'on', '1', 'yes', 'y', 'enable' or 'f', 'false', 'off', '0', 'no', 'n', 'disable'")
I was wondering whether the aliases perhaps need to be in an array or something?
testingcheats on // to verify this is actually the correct command
testingcheats off // to verify this is actually the correct command
t // works as expected: outputs the else option, telling me about explicit en/disabling
t 1 // tries to pass the correct command apparently, but .. fails?
t on // tries to pass the correct command apparently, but .. fails?
same with t true, t 0 etc .. d and debug yield no resonse at all.
Weird becuase this is the exact same code as with headlineeffects, and it is working when I only say
I don't have the code nor the game itself with me right now, and I won't until January, so I can't try this out myself. There are a few shipped commands that use aliases... I would try finding some of those and see if/how they work.
Also, try to prepend a | to the command when entering it in the cheat window and see if that works.
Comments
Thanks, I'll try that
Here it says "Loose .py files are supported out of the "Mods" folder" - I took this (in the context of hot loading scripts) to mean they would always be loaded when the game starts, just not *re*loaded. I tried both from the Mods folder and /Mods/unpackedmod, the unpackedmod folder is listed in my resource.cfg as well .. but still, all I get is "Unable to execute command".
I'd actually prefer not having to compile this .. would make it a lot easier to add on to it every now and then.
It could just as well be that I'm still making some stupid mistake in my code (I have no previous experience with Python) .. not sure.
Even as a loose file, the mod should show up the in the list... does it for you?
You mean the list in Game Options > Other > View Custom Content? I don't see anything there that could be the .py in question .. but to me it looks like it lists under "Script Mods" every .zip that it finds, not script mods per se (I have two zips listed there that do not contain any scripts, I just forgot to remove them). Also I have two empty lines in the nonscript department. Hm. What would it normally list there, the file name of the .py?
Correct. If you were to plop maslow.py in there, it should say maslow.
Exhibit A:
Exhibit B:
???
Script mods are enabled, all those zipped ones are working fine.
Weird.
I will, for science, try going online, see whether that makes a difference .. I dunno whether this could be similar with CC not being recognised in the Library unless going online-but-not-really etc pp .. ETA, Nope.
ETA, do I perhaps need to tell the game something about .py files in resource.cfg?
See if that works.
Oh, that looks good both are listed in the Mods dialog now.
ETA, so, maslow is now actually working; mine is only working in the sense of being recognised by the game.
And now I also got the actual work part of the workingness to work =D
(Took me a while to realise just how nitpicky Python is about spaces and tabs and so on)
The code, for other interested parties:
Rinse and repeat for all other cheats you may want to de-verbosify ..
The actual commands are working as expected (like with "h 1" or "h off" or whatever), but when I only type "h" I don't get the expected output .. and I don't understand why not. (The reason I want that is to prevent myself from forgetting that this is not a toggle)
?
lastexception.txt is not complaining about me (as it did yesterday, about my untidy whitespaces).
(I also have a feeling that the inner if is probably unnecessary as I can probably pass the bool directly somehow, I only don't want to change too many things at once)
This works now:
\o/
(You are already doing the boolean conversion for me )
ETA: oh but is there a way to give it multiple aliases for the same command? Like, can I pass it a list instead of the string somehow?
There is. Check the definition for 'Command'.
I think it's something like
That was exactly what I tried =D but that did not work, the result was "invalid command" or "unable to" or something along those lines (in the console output) .. I didn't take a screenshot of the exact wording, but I can try again and post one.
My code was
I was wondering whether the aliases perhaps need to be in an array or something?
What I entered was, in order:
testingcheats on // to verify this is actually the correct command
testingcheats off // to verify this is actually the correct command
t // works as expected: outputs the else option, telling me about explicit en/disabling
t 1 // tries to pass the correct command apparently, but .. fails?
t on // tries to pass the correct command apparently, but .. fails?
same with t true, t 0 etc .. d and debug yield no resonse at all.
Weird becuase this is the exact same code as with headlineeffects, and it is working when I only say
in the first line .. so the problem is the aliases, I take it.
Also, try to prepend a | to the command when entering it in the cheat window and see if that works.