Sustenance Posted July 19, 2023 Share Posted July 19, 2023 (edited) Im trying to draw a circle around only the user of the mod. I can draw the circle fine but using AddPlayerPostInit put the circle on every player. I believe "if ThePlayer == inst then" should apply it to only the mod user but ThePlayer is always nil even using "DoTaskInTime(1,func()" The mod is client_only. This happens on both my client hosted worlds and dedicated servers. Full code (ThePlayer is used at the bottom) Spoiler local G = GLOBAL local function MakeCircle(inst,n,c_size,r,g,b) local circle = G.CreateEntity() circle.entity:SetCanSleep(false) circle.persists = false circle.entity:AddTransform() circle.entity:AddAnimState() circle:AddTag("CLASSIFIED") circle:AddTag("NOCLICK") circle:AddTag("placer") circle.Transform:SetRotation(n) circle.Transform:SetScale(c_size,c_size,c_size) circle.AnimState:SetBank("firefighter_placement") circle.AnimState:SetBuild("firefighter_placement") circle.AnimState:PlayAnimation("idle") circle.AnimState:SetLightOverride(1) circle.AnimState:SetOrientation(G.ANIM_ORIENTATION.OnGround) circle.AnimState:SetLayer(G.LAYER_BACKGROUND) circle.AnimState:SetSortOrder(3.1) circle.AnimState:SetAddColour(r, g, b, 0) circle.entity:SetParent(inst.entity) return circle end local show_wortox = GetModConfigData("SHOW_WORTOX") local show_wigfrid = GetModConfigData("SHOW_WIGFRID") local show_wormwood = GetModConfigData("SHOW_WORMWOOD") local show_woby = GetModConfigData("SHOW_WOBY") local show_cookpot = GetModConfigData("SHOW_COOKPOT") local show_abigail = GetModConfigData("SHOW_ABIGAIL") local show_bernie = GetModConfigData("SHOW_BERNIE") local show_ability_range = GetModConfigData("SHOW_ABILITY_RANGE") local wortox_color = GetModConfigData("WORTOX_COLOR") local wigfrid_color = GetModConfigData("WIGFRID_COLOR") local wormwood_color = GetModConfigData("WORMWOOD_COLOR") local woby_color = GetModConfigData("WOBY_COLOR") local cookpot_color = GetModConfigData("WORTOX_COLOR") local abigail_color = GetModConfigData("WORTOX_COLOR") local bernie_color = GetModConfigData("WORTOX_COLOR") local wortox_color = GetModConfigData("WORTOX_COLOR") local ability_range_color = GetModConfigData("ABILITY_RANGE_COLOR") --[[ to add: customize when ranges are shown (only your character, all players) fissure range of boarior only show ability range when holding a weapon with an ability ]] local show_config = { --could put all configs in a list ie) ["wortox"] = {show_wortox, wortox_color, 1.288} ["wortox"] = show_wortox, --heal ["wathgrithr"] = show_wigfrid, --battlecey ["wormwood"] = show_wormwood, --spores ["forge_bernie"] = show_woby, --buff ["forge_woby"] = show_cookpot, --burger throw ["forge_abigail"] = show_abigail, --attack ["forge_cookpot"] = show_bernie, --agro take } local color_config = { ["wortox"] = wortox_color, ["wathgrithr"] = wigfrid_color, ["wormwood"] = wormwood_color, ["forge_bernie"] = woby_color, ["forge_woby"] = cookpot_color, ["forge_abigail"] = abigail_color, ["forge_cookpot"] = bernie_color, } local circle_size = { ["wortox"] = 1.288, ["wathgrithr"] = 1.15, ["wormwood"] = 0.7, ["forge_bernie"] = 1.5, --TODO Testing ["forge_woby"] = 1.55, ["forge_abigail"] = 0, ["forge_cookpot"] = 1.288, } local size = 0 local color = {0.12, 0.12, 0.12} for entity,allowed in pairs(show_config) do if allowed then AddPrefabPostInit(entity,function(inst) size = circle_size[entity] color = color_config[entity] MakeCircle(inst,0,size,color[1],color[2],color[3]) MakeCircle(inst,2,size,color[1],color[2],color[3]) end) end end if show_ability_range then AddPlayerPostInit(function(inst) if true then --TODO check if player is the mod user size = 1.13 color = ability_range_color MakeCircle(inst,0,size,0,0,0) MakeCircle(inst,2,size,0,0,0) end end) end AddPlayerPostInit(function(inst) print("Player: " .. tostring(inst)) print(ThePlayer) if ThePlayer == inst then print("- ThePlayer") end if inst.HUD then print("- HUD") end inst:DoTaskInTime(1, function() print(ThePlayer) if ThePlayer == inst then print("- ThePlayer f") end if inst.HUD then print("- HUD f") end end) end) Output (on both my client hosted worlds and dedicated servers) is: Player: 103212 - wilson nil nil - HUD f Edited July 19, 2023 by Sustenance Link to comment https://forums.kleientertainment.com/forums/topic/149589-mod-help-theplayer-is-always-nil/ Share on other sites More sharing options...
_zwb Posted July 19, 2023 Share Posted July 19, 2023 You would need GLOBAL.ThePlayer instead of ThePlayer in modmain.lua Link to comment https://forums.kleientertainment.com/forums/topic/149589-mod-help-theplayer-is-always-nil/#findComment-1651534 Share on other sites More sharing options...
Sustenance Posted July 19, 2023 Author Share Posted July 19, 2023 2 hours ago, _zwb said: You would need GLOBAL.ThePlayer instead of ThePlayer in modmain.lua TYVM! I think when I did that before I must have not used DoTaskInTime Link to comment https://forums.kleientertainment.com/forums/topic/149589-mod-help-theplayer-is-always-nil/#findComment-1651693 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now