Jump to content

New container objects work fine in Solo but in Multiplayer any objects inside disappear


Norby007

Recommended Posts

I have tried a few things without any luck. I have a check on load grid square that will convert the slurp burp machine into a container item. This works fine in single player but as soon as it is created in multiplayer any items left inside will disappear if you leave the area and return. I verified locally that once the machine is converted that it is not making a new one. I have a test server setup that I have been using but haven't figure out how to log the print commands so I can see what the code is doing in multiplayer. It's not throwing any errors in the log, just upon return the box is empty.

 

I also noticed that objects I set custom weight on also does not update between players and resets to the starting weight. I suspect there is something I need to send to the server that is sent back to all players upon the changes but I have not found a way to make that happen.

 

Any ideas? Thank you for your time.

 

local function replaceSodaFountain(SodaFountainObject)
    if not SodaFountainObject:getContainer() then
                local square = SodaFountainObject:getSquare()
                local spr = SodaFountainObject:getSprite():getName()

                sledgeDestroy(SodaFountainObject)
                SodaFountainObject:getSquare():transmitRemoveItemFromSquare(SodaFountainObject)
                SodaFountainObject:transmitCompleteItemToServer();
                SodaFountainObject:transmitUpdatedSpriteToClients()                
                if isClient() then SodaFountainObject:transmitCompleteItemToServer(); end

                SodaFountainObject:setSprite(spr)
                SodaFountainObject:getSprite():setName(spr)
                SodaFountainObject = IsoThumpable.new(getCell(), square, spr, false, ISDoubleTileFurniture:new("SlurpBurp", spr, spr));      
                SodaFountainObject:setIsThumpable(true)      
                SodaFountainObject:setIsContainer(true)
                SodaFountainObject:getContainer():setType("counter")
                SodaFountainObject:getContainer():setCapacity(50)
                SodaFountainObject:setCanPassThrough(false)                                      
                SodaFountainObject:setIsDismantable(false)                
                SodaFountainObject:setBlockAllTheSquare(true)
                SodaFountainObject:getSprite():getProperties():Set(IsoFlagType.waterPiped, "TRUE")

                square:AddTileObject(SodaFountainObject);
                if isClient() then SodaFountainObject:transmitCompleteItemToServer(); end
    end
end

Link to comment
Share on other sites

I finally got the code to work and will post the method that made it work when I get done with the mod update tonight. It will allow anyone using the code to convert any unused static sprite in the game into a container item that gets updated in the world for multiplayer support.

Link to comment
Share on other sites

This is how I finally solved the issue, not sure if all of the code is needed but it works so I am not going to fight it.

 


local function replaceSodaFountain(SodaFountainObject)
    if not SodaFountainObject:getContainer() then
        local square = SodaFountainObject:getSquare()
        local spr = SodaFountainObject:getSprite():getName()  
        local index = SodaFountainObject:getObjectIndex()
              sledgeDestroy(SodaFountainObject)
        SodaFountainObject:getSquare():transmitRemoveItemFromSquareOnServer(SodaFountainObject)
        SodaFountainObject:getSquare():transmitRemoveItemFromSquare(SodaFountainObject)            

              SodaFountainObject = IsoThumpable.new(getCell(), square, spr, false, ISWoodenContainer:new(spr, nil))  
                SodaFountainObject:setIsContainer(true)
                 SodaFountainObject:getContainer():setType("counter")
                 SodaFountainObject:getContainer():setCapacity(50)

                 square:AddTileObject(SodaFountainObject, index)
        square:transmitAddObjectToSquare(SodaFountainObject, SodaFountainObject:getObjectIndex())
        square:transmitModdata()
        SodaFountainObject:transmitModData()    
                SodaFountainObject:transmitCompleteItemToServer()
                 SodaFountainObject:transmitUpdatedSpriteToServer()
    end
end

local function GetVanillaSodaFountain(square)
    if square then
            local objects = square:getObjects()
            for i=1, objects:size()-1 do
                    local thisObject = objects:get(i)
                   local spr = thisObject:getSprite()
                   if spr then
                        local properties = spr:getProperties()
                        if properties:Val("GroupName") == "SlurpBurp" then
                    return thisObject
                        end
                    end
            end
        end
end


local function onLoadGridsquare(square)
    local SodaFountain = GetVanillaSodaFountain(square)

    if SodaFountain then
        replaceSodaFountain(SodaFountain)
    end
end

Events.LoadGridsquare.Add(onLoadGridsquare);

Link to comment
Share on other sites

It takes the slurp and burp machine and converts it into a container item so that later on I can drop in a menu to pull soda syrup and co2 tanks from the container. This bit was a mess as in multiplayer it would not update until I finally worked this out. 

 

When the grid square is loaded it looks for the machine. If found it sends it for replacement. If it's not already replaced it saves the index of the sprite and deletes it locally and from the server. Then it creates a new container with the specs that I wanted and reloads the original sprite's index. Then it updates the whole thing to the server with the mod data after dropping it on to the tile and updating the tile to the server. 

 

At least that is how I understand it. I only started coding in PZ about a month ago.

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