Jump to content

How to spawn a Mannequin


TungstenX

Recommended Posts

Good day,

I'm making a mod and would like to spawn a mannequin or corpse when player does xyz. I've looked at a few solution but it is not quit what I'm looking for. E.g. the solution (AddWorldInventoryItem) in the following topic will show the "icon" of the corpse, i.e. Base.CorpseMale  (https://pzwiki.net/wiki/PZwiki:Item_List#Corpse)

 

Is there a way to spawn the "model" of a mannequin or a corpse immediate given the player's coordinates?
In other words, the mannequin will appear next to the player when the player does xyz.

Link to comment
Share on other sites

  • 3 weeks later...

Here is how the function evolved so far. It is not working properly, seem to only work once.

I need to figure out how to dress it and change poses. Also having issue with sprite for mannequin. Currently I'm calling this method via a context menu to speed up the testing

 

function spawn(x, y, z)
  local player = getPlayer()
  local modData = player:getModData()
  
  -- Check if mannequin was spawned before - Only one
  if modData and modData.manny then
    local gmsc = modData.manny
    if gmsc.spawned then
      -- already spawned
      return
    end
  end
  
  -- Where to put Manny
  local targetSquare = getSquare(x,y,z)
  -- TODO: figure out direction to face
  local facingDir = "E"
  
  -- Create a Mannequin as a Manny
  -- TODO: That sprite thingy
  local newMannequin = IsoMannequin.new(player:getCell(), targetSquare, getSprite("Base.MannequinScarecrow01"))  
  newMannequin:setSquare(targetSquare)
  --TODO: Dress mannequin, change pose
  --update direction
  newMannequin:setDir(IsoDirections[facingDir])
  -- This is not working, why?
  -- This throws an error
  --newMannequin:addToWorld()
  
  -- Copy and paste, no idea what it does
  for i = 1, newMannequin:getContainerCount() do
    newMannequin:getContainerByIndex(i - 1):setExplored(true);
  end
  
  -- always on top, not working
  --targetSquare:AddSpecialObject( newMannequin )
  -- Not sure about this
  if isClient() then 
    newMannequin:transmitCompleteItemToServer()
  end
  
  -- Jumping the hoops, not sure if all is needed?
  triggerEvent("OnObjectAdded", newMannequin)
  getTileOverlays():fixTableTopOverlays(targetSquare)
  targetSquare:RecalcProperties()
  targetSquare:RecalcAllWithNeighbours(true)
  triggerEvent("OnContainerUpdate")
  IsoGenerator.updateGenerator(targetSquare)
  
  -- Add to player's modData
  modData.manny = {}
  modData.manny.mannequinObject = newMannequin;
  modData.manny.spawned = true;
end

 

Is this approach correct?

Is there a better way to do it?

That sprite thingy?

 

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...