Jump to content

[Help] Making my character give sanity aura around other player with a maximum of 2 players near


Recommended Posts

Hi! I'm making my first mod because i wanted to add a character i made in the game, i'm not really good at coding so i was wondering if someone could help me with a perk! :D

Basically what i want my character to do is to give a sanity aura (Like a gloomer) to other players around, with a maximum of 2 players near my character (If there's 1 person near he will still give sanity aura)

But when there are 3 or more players near my character, he will give an insanity aura instead 

 

I know that is it possible to make a character give sanity aura, but i'm not so sure if something this specific can be made :wilson_laugh:

Many thanks for the help!

Link to comment
Share on other sites

1 hour ago, Ultroman said:

These should get you all the information you need to make that perk.

Before you start, though, you should familiarize yourself with Lua and DST modding. Start with the newcomer post, do the Lua Crash Course linked there, perhaps browse my tutorial collection for some information about different parts of a mod.

Many thanks!! i'll check the guides!

  • Like 1
Link to comment
Share on other sites

I Tried writing the code but i ended up getting an error and i don't know how to fix it:(  

Spoiler
    local function FindPlayers(inst)
        local x, y, z = inst.Transform:GetWorldPosition()
            local players = TheSim:FindEntities(x, y, z, 30, {"player"} )
            return #players > 0 and players or nil
        end
        if players:GetCurrent() > 1 then
            for _,v in ipairs(players) do
                if v.components.sanity then
                    v.components.sanity:DoDelta(1)
        end
        if players:GetCurrent() < 2 then
            for _,v in ipairs(players) do
                if v.components.sanity then
                    v.components.sanity:DoDelta(-1)
        end
    end
    instDoPeriodicTask1function(inst
        Findplayers(inst) 
    end)
    

  

 

 

Spoiler

00:00:47]: Mod: Alexander The Lynx    Registering prefabs    
[00:00:47]: Mod: Alexander The Lynx      Registering prefab file: prefabs/alexander    
[00:00:47]: error calling LoadPrefabFile in mod Alexander The Lynx: 
[string "scripts/mainfunctions.lua"]:150: Error loading file prefabs/alexander
[string "../mods/Alexander The Lynx/scripts/prefabs/alexander.lua"]:135: 'end' expected (to close 'if' at line 106) near '<eof>'
LUA ERROR stack traceback:
        =[C] in function 'assert'
        scripts/mainfunctions.lua(150,1)
        =(tail call) ?
        =[C] in function 'xpcall'
        scripts/mods.lua(162,1)
        scripts/mods.lua(604,1) in function 'RegisterPrefabs'
        scripts/gamelogic.lua(279,1) in function 'LoadAssets'
        scripts/gamelogic.lua(914,1) in function 'cb'
        scripts/saveindex.lua(312,1) in function 'OnLoadSaveDataFile'
        scripts/saveindex.lua(327,1)
        =[C] in function 'GetPersistentStringInClusterSlot'
    ...
        =[C] in function 'GetPersistentString'
        scripts/saveindex.lua(278,1) in function 'Load'
        scripts/gamelogic.lua(1128,1) in function 'callback'
        scripts/playerprofile.lua(1034,1) in function 'Set'
        scripts/playerprofile.lua(889,1)
        =[C] in function 'GetPersistentString'
        scripts/playerprofile.lua(887,1) in function 'Load'
        scripts/gamelogic.lua(1127,1) in main chunk
        =[C] in function 'require'
        scripts/mainfunctions.lua(940,1)    
[00:00:47]: Disabling Alexander The Lynx because it had an error.    
[00:00:47]: [string "scripts/mainfunctions.lua"]:150: Error loading file prefabs/alexander
[string "../mods/Alexander The Lynx/scripts/prefabs/alexander.lua"]:135: 'end' expected (to close 'if' at line 106) near '<eof>'
LUA ERROR stack traceback:
        =[C] in function 'assert'
        scripts/mainfunctions.lua(150,1)
        =(tail call) ?
        =[C] in function 'xpcall'
        scripts/mods.lua(162,1)
        scripts/mods.lua(604,1) in function 'RegisterPrefabs'
        scripts/gamelogic.lua(279,1) in function 'LoadAssets'
        scripts/gamelogic.lua(914,1) in function 'cb'
        scripts/saveindex.lua(312,1) in function 'OnLoadSaveDataFile'
        scripts/saveindex.lua(327,1)
        =[C] in function 'GetPersistentStringInClusterSlot'
    ...
        =[C] in function 'GetPersistentString'
        scripts/saveindex.lua(278,1) in function 'Load'
        scripts/gamelogic.lua(1128,1) in function 'callback'
        scripts/playerprofile.lua(1034,1) in function 'Set'
        scripts/playerprofile.lua(889,1)
        =[C] in function 'GetPersistentString'
        scripts/playerprofile.lua(887,1) in function 'Load'
        scripts/gamelogic.lua(1127,1) in main chunk
        =[C] in function 'require'
        scripts/mainfunctions.lua(940,1)
[00:00:47]: [string "scripts/mainfunctions.lua"]:150: Error loading file prefabs/alexander
[string "../mods/Alexander The Lynx/scripts/prefabs/alexander.lua"]:135: 'end' expected (to close 'if' at line 106) near '<eof>'
LUA ERROR stack traceback:
        =[C] in function 'assert'
        scripts/mainfunctions.lua(150,1)
        =(tail call) ?
        =[C] in function 'xpcall'
        scripts/mods.lua(162,1)
        scripts/mods.lua(604,1) in function 'RegisterPrefabs'
        scripts/gamelogic.lua(279,1) in function 'LoadAssets'
        scripts/gamelogic.lua(914,1) in function 'cb'
        scripts/saveindex.lua(312,1) in function 'OnLoadSaveDataFile'
        scripts/saveindex.lua(327,1)
        =[C] in function 'GetPersistentStringInClusterSlot'
    ...
        =[C] in function 'GetPersistentString'
        scripts/saveindex.lua(278,1) in function 'Load'
        scripts/gamelogic.lua(1128,1) in function 'callback'
        scripts/playerprofile.lua(1034,1) in function 'Set'
        scripts/playerprofile.lua(889,1)
        =[C] in function 'GetPersistentString'
        scripts/playerprofile.lua(887,1) in function 'Load'
        scripts/gamelogic.lua(1127,1) in main chunk
        =[C] in function 'require'
        scripts/mainfunctions.lua(940,1)    
[00:00:47]: Mod: Alexander The Lynx      Registering prefab file: prefabs/alexander_none    
[00:00:47]: Mod: Alexander The Lynx        alexander_none    
[00:00:47]: Mod: Alexander The Lynx      Registering default mod prefab    
[00:00:47]: Mod: workshop-352373173 (Gesture Wheel)    Registering prefabs    
[00:00:47]: Mod: workshop-352373173 (Gesture Wheel)      Registering default mod prefab    
[00:00:47]: Mod: workshop-351325790 (Geometric Placement)    Registering prefabs    
[00:00:47]: Mod: workshop-351325790 (Geometric Placement)      Registering prefab file: prefabs/buildgridplacer    
[00:00:47]: Mod: workshop-351325790 (Geometric Placement)        buildgridplacer    
[00:00:47]: Mod: workshop-351325790 (Geometric Placement)      Registering default mod prefab    
[00:00:47]: Mod: workshop-1290774114 (Admin Scoreboard+)    Registering prefabs    
[00:00:47]: Mod: workshop-1290774114 (Admin Scoreboard+)      Registering default mod prefab    
[00:00:48]: Warning: Widget:SetFocusFromChild is happening on a widget outside of the screen/widget hierachy. This will cause focus moves to fail. Is     ScriptErrorWidget    not a screen?    
[00:00:48]: stack traceback:
    scripts/widgets/widget.lua:605 in (method) SetFocusFromChild (Lua) <602-627>
    scripts/widgets/widget.lua:656 in (method) SetFocus (Lua) <629-665>
    scripts/widgets/scripterrorwidget.lua:107 in (method) OnUpdate (Lua) <102-119>
    scripts/update.lua:90 in () ? (Lua) <33-129>
    =[C]:-1 in (method) RenderOneFrame (C) <-1--1>
    scripts/gamelogic.lua:134 in (upvalue) KeepAlive (Lua) <128-140>
    scripts/gamelogic.lua:281 in (upvalue) LoadAssets (Lua) <160-310>
    scripts/gamelogic.lua:914 in (local) cb (Lua) <909-916>
    scripts/saveindex.lua:312 in (upvalue) OnLoadSaveDataFile (Lua) <294-313>
    scripts/saveindex.lua:327 in () ? (Lua) <326-328>
    =[C]:-1 in (method) GetPersistentStringInClusterSlot (C) <-1--1>
    scripts/saveindex.lua:326 in (method) GetSaveData (Lua) <321-340>
    ...
    scripts/saveindex.lua:280 in () ? (Lua) <279-281>
    =[C]:-1 in (method) GetPersistentString (C) <-1--1>
    scripts/saveindex.lua:278 in (method) Load (Lua) <275-282>
    scripts/gamelogic.lua:1128 in (local) callback (Lua) <1127-1129>
    scripts/playerprofile.lua:1034 in (method) Set (Lua) <901-1037>
    scripts/playerprofile.lua:889 in () ? (Lua) <888-890>
    =[C]:-1 in (method) GetPersistentString (C) <-1--1>
    scripts/playerprofile.lua:887 in (method) Load (Lua) <886-891>
    scripts/gamelogic.lua:1127 in () ? (main) <0-0>
    =[C]:-1 in (global) require (C) <-1--1>    
[00:00:48]:     LOAD BE    
[00:00:50]: Could not preload undefined prefab (crabking_yellow_whirl_front)
[00:00:50]: Could not preload undefined prefab (crabking_yellow_whirl_back)
[00:00:52]:     LOAD BE: done    
[00:00:52]: Begin Session: 2DBB720A7A1228B6
[00:00:52]: saving to server_temp/server_save    
[00:00:52]: MiniMapComponent::AddAtlas( minimap/minimap_data.xml )
[00:00:52]: MiniMapComponent::AddAtlas( ../mods/Alexander The Lynx/images/map_icons/alexander.xml )
[00:00:52]: Loading 17 new character(s)    
[00:00:52]: Could not preload undefined prefab (alexander)
[00:00:52]: Total 17 character(s) loaded    
[00:00:53]: Loading Nav Grid    
[00:00:53]: World generated on version 406549, using seed: 1587744733    
[00:00:55]: Could not find anim build FROMNUM
[00:00:55]: Could not find anim build FROMNUM
[00:00:55]: Could not find anim build FROMNUM
[00:00:55]: Could not find anim build FROMNUM
[00:00:55]: Could not find anim build FROMNUM
[00:00:55]: Could not find anim build FROMNUM
[00:00:55]: Could not find anim build FROMNUM
[00:00:55]: Could not find anim build FROMNUM
[00:00:55]: Could not find anim build FROMNUM
[00:00:55]: Could not find anim build FROMNUM
[00:01:02]: Could not find anim build FROMNUM
[00:01:02]: Could not find anim build FROMNUM
[00:01:02]: Could not find anim build FROMNUM
[00:01:02]: Could not find anim build FROMNUM
[00:01:02]: Could not find anim build FROMNUM
[00:01:02]: Could not find anim build FROMNUM
[00:01:02]: Could not find anim build FROMNUM
[00:01:02]: Could not find anim build FROMNUM
[00:01:02]: Could not find anim build FROMNUM
[00:01:02]: Could not find anim build FROMNUM
[00:01:02]: Reconstructing topology    
[00:01:02]:     ...Sorting points    
[00:01:02]:     ...Sorting edges    
[00:01:02]:     ...Connecting nodes    
[00:01:02]:     ...Validating connections    
[00:01:03]:     ...Housekeeping    
[00:01:03]:     ...Done!    
[00:01:03]: 1 uploads added to server. From server_temp
[00:01:03]: Telling Client our new session identifier: 2DBB720A7A1228B6
[00:01:03]: Check for write access: TRUE
[00:01:03]: Check for read access: TRUE
[00:01:03]: ModIndex: Load sequence finished successfully.    
[00:01:03]: Reset() returning
[00:01:05]: Best lobby region is aws/US (ping 83)
[00:01:05]: Registering master server in US lobby
[00:01:15]: Registering master server in US lobby
 

 

Link to comment
Share on other sites

It tells you what's wrong right here:

[string "../mods/Alexander The Lynx/scripts/prefabs/alexander.lua"]:135: 'end' expected (to close 'if' at line 106) near '<eof>'

It expected an "end" to close your if-statement started at 106, but the if-statement is closed (going by your indentation) but the for-loop isn't closed. You need to close your for-loops with "end", just like the if-statements. Did you do the Lua Crash Course? It's very different compared to most other languages. You have to understand its object-model and weird syntax, in order to write anything good in it. For example, have fun coding without the "continue" keyword :)

Edited by Ultroman
Link to comment
Share on other sites

I could finally get the code to not crash! XD 

But whenever i select my character this shows up in the log:

[00:02:13]: WARNING! Could not find region 'alexander.tex' from atlas '../mods/Alexander The Lynx/images/names_gold_alexander.xml'. Is the region specified in the atlas?
[00:02:13]: Looking for default texture '' from atlas '../mods/Alexander The Lynx/images/names_gold_alexander.xml'.
[00:02:13]: Error Looking for default texture in from atlas '../mods/Alexander The Lynx/images/names_gold_alexander.xml'.
[00:02:14]: WARNING! Could not find region 'alexander.tex' from atlas '../mods/Alexander The Lynx/images/names_gold_alexander.xml'. Is the region specified in the atlas?
[00:02:14]: Looking for default texture '' from atlas '../mods/Alexander The Lynx/images/names_gold_alexander.xml'.
[00:02:14]: Error Looking for default texture in from atlas '../mods/Alexander The Lynx/images/names_gold_alexander.xml'.
[00:02:14]: WARNING! Could not find region 'alexander.tex' from atlas '../mods/Alexander The Lynx/images/names_gold_alexander.xml'. Is the region specified in the atlas?
[00:02:14]: Looking for default texture '' from atlas '../mods/Alexander The Lynx/images/names_gold_alexander.xml'.
[00:02:14]: Error Looking for default texture in from atlas '../mods/Alexander The Lynx/images/names_gold_alexander.xml'.
[00:02:16]: Spawn request: alexander from [Host] ★Usagi★
[00:02:16]: Skin request: () () () () ()
[00:02:16]: Can't find prefab alexander    
[00:02:18]: Registering master server in US lobby
 

Edited by Alexander Lynx
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...