mentalistpro Posted March 9, 2020 Share Posted March 9, 2020 I am not sure what I have done wrong. I was trying to change the custom character's runspeed if s/he steps on marsh turf. However, the game crashes and provides no error log I could trace. Can someone help please? ;_; Here's the relevant scripts in the prefab file of the custom character. local function test_ground(inst) local x, y, z = GetPlayer().Transform:GetWorldPosition() if GetWorld().Map:GetTileAtPoint( x, y, z ) == GROUND.MARSH then inst.components.locomotor.runspeed = 7.8 print("onmarsh yay") else inst.components.locomotor.runspeed = 6 print("onground ****") end end Link to comment Share on other sites More sharing options...
Ultroman Posted March 9, 2020 Share Posted March 9, 2020 I think the problem stems from where you call it, since it requires both the player and the world to be spawned at the time of execution. That said, there has to be an error logged somewhere in the client log. There has to be. Can you share a client log from just after a crash happened? Link to comment Share on other sites More sharing options...
mentalistpro Posted March 11, 2020 Author Share Posted March 11, 2020 [00:00:37]: cGame::StartPlaying [00:00:37]: LOADING LUA [00:00:37]: DoLuaFile scripts/main.lua [00:00:37]: DoLuaFile loading buffer scripts/main.lua [00:00:37]: scripts/playerprofile.lua(642,1) loaded profile [00:00:37]: scripts/playerprofile.lua(372,1) FOUND THE NEW DATA true [00:00:37]: scripts/playerprofile.lua(372,1) FOUND THE NEW DATA true [00:00:37]: scripts/playerprofile.lua(372,1) FOUND THE NEW DATA true [00:00:37]: scripts/main.lua(234,1) running main.lua [00:00:37]: scripts/main.lua(241,1) Sim Seed = 39000 [00:00:37]: scripts/modindex.lua(327,1) loaded modindex [00:00:37]: scripts/modindex.lua(67,1) ModIndex: Beginning normal load sequence. [00:00:37]: scripts/modindex.lua(250,1) WARNING loading modinfo.lua: workshop-1363787470 does not specify if it is compatible with Hamlet. It may not work properly. [00:00:37]: scripts/modindex.lua(250,1) WARNING loading modinfo.lua: workshop-374307504 does not specify if it is compatible with Hamlet. It may not work properly. [00:00:37]: scripts/modindex.lua(250,1) WARNING loading modinfo.lua: workshop-609651550 does not specify if it is compatible with Hamlet. It may not work properly. [00:00:37]: scripts/modindex.lua(250,1) WARNING loading modinfo.lua: workshop-689104869 does not specify if it is compatible with Hamlet. It may not work properly. [00:00:37]: scripts/modindex.lua(405,1) Could not load mod_config_data/modconfiguration_customCHARACTER [00:00:37]: scripts/mods.lua(179,1) Loading mod: customCHARACTER (customCHARACTER ) [00:00:37]: scripts/mods.lua(206,1) Mod: customCHARACTER (customCHARACTER ) Loading modworldgenmain.lua [00:00:37]: scripts/mods.lua(214,1) Mod: customCHARACTER (customCHARACTER ) Mod had no modworldgenmain.lua. Skipping. [00:00:37]: scripts/mods.lua(206,1) Mod: customCHARACTER (customCHARACTER ) Loading modmain.lua [00:00:37]: LOADING LUA SUCCESS [00:00:38]: scripts/playerdeaths.lua(79,1) PlayerDeaths loaded morgue 4539 [00:00:38]: scripts/playerprofile.lua(642,1) loaded profile [00:00:38]: scripts/playerprofile.lua(711,1) bloom_enabled true [00:00:38]: DEVICE CAP 1583887975 [00:00:38]: scripts/saveindex.lua(103,1) Attempting to load save file saveindex [00:00:38]: scripts/saveindex.lua(112,1) loaded saveindex [00:00:38]: scripts/gamelogic.lua(1181,1) OnFilesLoaded() [00:00:38]: scripts/gamelogic.lua(1170,1) OnUpdatePurchaseStateComplete [00:00:38]: scripts/gamelogic.lua(151,1) Unload FE [00:00:38]: scripts/gamelogic.lua(153,1) Unload FE done [00:00:39]: scripts/mods.lua(296,1) Mod: customCHARACTER (customCHARACTER ) Registering prefabs [00:00:39]: scripts/mods.lua(302,1) Mod: customCHARACTER (customCHARACTER ) Registering prefab file: prefabs/customCHARACTER [00:00:39]: scripts/mods.lua(306,1) Mod: customCHARACTER (customCHARACTER ) customCHARACTER [00:00:39]: scripts/mods.lua(302,1) Mod: customCHARACTER (customCHARACTER ) Registering prefab file: prefabs/customCHARACTER_tentacle_warning [00:00:39]: scripts/mods.lua(306,1) Mod: customCHARACTER (customCHARACTER ) customCHARACTER_tentacle_warning [00:00:39]: scripts/mods.lua(319,1) Mod: customCHARACTER (customCHARACTER ) Registering default mod prefab [00:00:40]: Could not preload undefined prefab 0x4cbe21dc (disguisehat) [00:00:40]: scripts/gamelogic.lua(167,1) LOAD BE [00:00:41]: Could not preload undefined prefab 0x350a87f2 (note) [00:00:41]: Could not preload undefined prefab 0x350a87f2 (note) [00:00:41]: Could not preload undefined prefab 0x350a87f2 (note) [00:00:42]: Could not preload undefined prefab 0xf0533cd6 (area_maxwelllight) [00:00:42]: Could not preload undefined prefab 0x5f41a1f4 (brokenwalls) [00:00:42]: Could not preload undefined prefab 0x7ec8eb53 (nightmare_flame) [00:00:42]: Could not preload undefined prefab 0x5bb6aaea (paired_maxwelllight) [00:00:42]: Could not preload undefined prefab 0xed1e0dd6 (phonograph) [00:00:42]: Could not preload undefined prefab 0x223749c9 (player_common) [00:00:42]: Could not preload undefined prefab 0xe3941c2c (researchmachine) [00:00:42]: Could not preload undefined prefab 0xf20f2548 (ruin) [00:00:42]: Could not preload undefined prefab 0x92464c8a (stairs) [00:00:42]: Could not preload undefined prefab 0x8b7cefce (tree_clump) [00:00:42]: Could not preload undefined prefab 0xfa7e8231 (unlockable_players) [00:00:43]: Could not preload undefined prefab 0x48fc3ce3 (porkland) [00:00:43]: Could not preload undefined prefab 0x7c61e1f5 (shipwrecked) [00:00:43]: Could not preload undefined prefab 0xa552d992 (volcanolevel) [00:00:43]: Could not preload undefined prefab 0xaf0f7120 (bundle_unwrap) [00:00:43]: Could not preload undefined prefab 0xed95c616 (bundle_blueprint) [00:00:43]: Could not preload undefined prefab 0x97f0225e (bundle_large) [00:00:43]: Could not preload undefined prefab 0x22010b52 (bundle_medium) [00:00:43]: Could not preload undefined prefab 0x995e7e0a (bundle_small) [00:00:44]: scripts/gamelogic.lua(175,1) LOAD BE: done [00:00:44]: MiniMapComponent::AddAtlas(minimap/minimap_data.xml) [00:00:44]: MiniMapComponent::AddAtlas(../mods/customCHARACTER/minimap/customCHARACTER.xml) then it crashed EDIT: or shall i put the function in locomotor component instead? EDIT2: While I don't understand why error is not recorded in the log, I am finally able to update character speed based on turf type. @Ultroman was right that it might not be a good idea to call both player and world during the game start. I simply override the function Locomotor:UpdateGroundSpeedMultiplier(). I have put the scripts below for people who are interested. And also, sorry for asking a new question @Ultroman -- is there a way to keep old functions in component while overriding for the purpose of compatibility? #1 Go to your custom character prefab file. ------------------------------------------------------------------------------------ #2 Add two functions local function EnableSpeedBoost(inst) local ground = GetWorld() local x,y,z = inst.Transform:GetWorldPosition() local tile = ground.Map:GetTileAtPoint(x,0,z) if tile and tile == GROUND.??? then inst.components.locomotor.groundspeedmultiplier = 1.3 end end local function UpdateSpeedBoost(inst) inst:ListenForEvent("locomote", EnableSpeedBoost) end ------------------------------------------------------------------------------------ #3 Modify fn() at the bottom inst:DoTaskInTime(0.1, EnableSpeedBoost) inst:DoTaskInTime(0.1, UpdateSpeedBoost) ------------------------------------------------------------------------------------ This will prevent game crash, since you cannot detect both the world (which is a prefab) and character at the same time. You need to create some time gap. Link to comment Share on other sites More sharing options...
Ultroman Posted March 11, 2020 Share Posted March 11, 2020 14 hours ago, mentalistpro said: And also, sorry for asking a new question @Ultroman -- is there a way to keep old functions in component while overriding for the purpose of compatibility? Yes. Using the modding API Klei has provided. You should never overwrite an existing function entirely, but since you ask about it, I'm guessing I don't have to tell you why it's a bad idea. This post has some examples on how to extend functions. The code you have now uses AddComponentPostInit, so the change is applied to ALL entities which have a locomotor (which is almost anything that can move on its own volition). You should make this change inside the player character Lua instead, inside its master_postinit. The downside to this method, is that you can't change what the original function does. What you CAN do, however, is change the variables which are put into its parameters (in this case none) or call the original function, saving the result in a variable, and then change the result with your own code before returning it. In your case, UpdateGroundSpeedMultiplier doesn't return anything, but changes variables directly. You'll need to change those same variables to your liking. Link to comment Share on other sites More sharing options...
mentalistpro Posted March 11, 2020 Author Share Posted March 11, 2020 thanks for the help man Have a good day!!! Link to comment Share on other sites More sharing options...
Ultroman Posted March 11, 2020 Share Posted March 11, 2020 57 minutes ago, mentalistpro said: thanks for the help man Have a good day!!! You're very welcome You, too And godspeed! Link to comment Share on other sites More sharing options...
mentalistpro Posted March 16, 2020 Author Share Posted March 16, 2020 For latecomers, I have updated my scripts above. Don't use AddComponentPostInit, edit the prefab file of your custom character instead. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.
Please be aware that the content of this thread may be outdated and no longer applicable.