Jump to content

Recommended Posts

I'm working on a part of my mod----an interior room which is totally dark.To do this, I need to push the "overrideambientlighting" event in player's client side(I just need a visual effect,so I have no need to do this in server),so I use the ClientModRPC, whenever a player enters the dark room, I will let server send the RPC to the player's client side, which make the player feels dark(visually). This method works fine when I start the game with caves. However, when I start the game without cave and I enter the dark room, it seems the whole server in affected by the "overrideambientlighting", but I just need to "overrideambientlighting" in my client side !!!!! What's going on ??? Shouldn't the ClientModRPC works only in client side ???

And Here is my code,would you like to help me to find the problem ? (or th )

-- Should be client side override ambient lighting
AddClientModRPCHandler("gale_rpc","check_gale_interior_ambientlighting",function()
    if ThePlayer then
        ThePlayer:CheckInteriorAmbientLightAndOcean()
    else
        print("check_gale_interior_ambientlighting FAILED !!!")
    end
end)
 
AddPlayerPostInit(function(inst)
    if not TheNet:IsDedicated() then
        -- overrideambientlighting functions
        inst.InteriorAmbientLightAndOceanEnabled = false
        inst.EnableInteriorAmbientLightAndOcean = function(inst,enable)
            local oceancolor =TheWorld.components.oceancolor
 
            if enable then
                TheWorld:PushEvent("overrideambientlighting",Point(0 / 255, 0 / 255, 0 / 255))
 
                if oceancolor ~= nil then
                    TheWorld:StopWallUpdatingComponent(oceancolor)
                    oceancolor:Initialize(not enable and TheWorld.has_ocean)
                end
            else
                TheWorld:PushEvent("overrideambientlighting",nil)
 
                if oceancolor ~= nil then
                    TheWorld:StartWallUpdatingComponent(oceancolor)
                    oceancolor:Initialize(not enable and TheWorld.has_ocean)
                end
            end
           
           
 
            inst.InteriorAmbientLightAndOceanEnabled = enable
        end
 
        -- Check functions
        inst.CheckInteriorAmbientLightAndOcean = function(inst)
            local room = TheWorld.components.gale_interior_room_manager:GetRoom(inst:GetPosition())
            if room and room:IsValid() then
                if not inst.InteriorAmbientLightAndOceanEnabled then
                    inst:EnableInteriorAmbientLightAndOcean(true)
                end
            else
                if inst.InteriorAmbientLightAndOceanEnabled then
                    inst:EnableInteriorAmbientLightAndOcean(false)
                end
            end
        end
 
        -- Used for initialize ambient lighting
        inst:DoTaskInTime(0.1,function()
            TheCamera:CheckGaleInteriorCamera()  -- camera or sth
            inst:CheckInteriorAmbientLightAndOcean()
        end)
    end
end)
 
-- Sample: Server send rpc command to client side
-- SendModRPCToClient(CLIENT_MOD_RPC["gale_rpc"]["check_gale_interior_ambientlighting"],inst.userid)

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
×
  • Create New...