Page 1 of 1

Attempting to replicate user_script.lvl support

Posted: Thu Mar 10, 2016 4:04 am
by AnthonyBF2
Zerted informed me that the script game_interface.lua inside of ingame.lvl is what detects and runs user_script.lvl files, if they are detected. Since he is not so active I must bring this to open forum and see about getting help elsewhere.

I have tried two things in my game_interface.lua but none are working.

The first attempt is to see if the game can find user_script_1.lvl and attempt to run it. It did not work.

Code: Select all

if ScriptCB_IsFileExist("user_script_1.lvl") then
ReadDataFile("user_script_1.lvl")
end
The second code I tried is just directly reading the file, also did not work.

Code: Select all

ReadDataFile("user_script_1.lvl")
My contents of user_script_1.lvl are

Code: Select all

OnCharacterSpawn(
function(character)
if IsCharacterHuman(character) then
MissionVictory(1,2)
end
end
)
So if everything were to be working, the game should skip to victory as soon as player spawns, but it's not happening. Thanks for any help!

Re: Attempting to replicate user_script.lvl support

Posted: Thu Mar 10, 2016 12:11 pm
by Maveritchell
Does it work to pass in two inputs to MissionVictory? Are you sure your userscript works?

Re: Attempting to replicate user_script.lvl support

Posted: Thu Mar 10, 2016 12:24 pm
by Anakin
Please add print("userscript 1 entered") at the top of your user script 1 to make sure that it is loaded correctly. Maybe your execute path of game_interface is not the same where your script is.

An other way is to add a output to your if condition, to make sure it returned 1 and not 0.

Re: Attempting to replicate user_script.lvl support

Posted: Thu Mar 10, 2016 2:08 pm
by AnthonyBF2
MissionVictory(1,2) does work and I cannot use print because this mod is for PS2 and it doesn't have debugging.

Re: Attempting to replicate user_script.lvl support

Posted: Thu Mar 10, 2016 2:39 pm
by commanderawesome
Try this for loading the script:

Code: Select all

ReadDataFile("user_script_1.lvl")
ScriptCB_DoFile("user_script_1")

Re: Attempting to replicate user_script.lvl support

Posted: Thu Mar 10, 2016 2:48 pm
by AnthonyBF2
commanderawesome wrote:Try this for loading the script:

Code: Select all

ReadDataFile("user_script_1.lvl")
ScriptCB_DoFile("user_script_1")
Yes! That makes it work, thanks!!! :mrgreen:

I have a situation with that code you posted commanderawesome, the game only works when a user script file is found. If there are none found, the game crashes at load screen.

I tried using;

Code: Select all

if ScriptCB_IsFileExist("user_script_1.lvl") then
	ReadDataFile("user_script_1.lvl")
	ScriptCB_DoFile("user_script_1")
end
But that didn't work. It still crashes if a user script file isn't found.