Jump to content

Spawning a specific prefab on player death?


Recommended Posts

Okay, So I want to make it so that upon a players death I can spawn a certain prefab, I'm trying to use a similar technique to the one used in Wickerbottom's books, but I run into a problem with the Vector3 function.

 

Is there a better way to go about this? Am I using the correct function: "AddPlayerPostInit" ?

AddPlayerPostInit(function(inst)local pt = Vector3(inst.Transform:GetWorldPosition())    if GLOBAL.TheNet:GetIsServer() then 	    inst:ListenForEvent("death", function() 			local num = math.random(1,3)--             for k = 1, num do--                local spawn = SpawnPrefab("beefalo")--                spawn.Transform:SetPosition(pt)--        end    end)     endend)
Link to comment
Share on other sites

local function beefedup(inst)    local pos = inst:GetPosition()    local num = math.random(1, 3)    for k = 1, num, 1 do        local rand = math.random(0, 10) - 5        local beefalo = GLOBAL.SpawnPrefab("beefalo")        beefalo.Transform:SetPosition(pos.x + rand, 0, pos.z + rand)    endend AddPlayerPostInit(function(inst)    if GLOBAL.TheNet:GetIsServer() then        inst:ListenForEvent("death", beefedup)    endend)

You don't need Vector3 if it causes you trouble. :-)

Link to comment
Share on other sites

Sorry This is a late reply :| but...

 

I got an error: "calling 'Setposition' on bad self {number expected, got table}"

 

I tried to use:

local pos = GLOBAL.Vector3(inst.Transform:GetWorldPosition())

and all that accomplished was a crash on loading the world, whilst @DarkXero 's suggestion only printed an error, w/o a crash 

 

 

Edit: The Error Line from my Log.txt:

[00:01:40]: [string "../mods/SpellsModsSwapTexturesDST/modmain.l..."]:98: calling 'SetPosition' on bad self (number expected, got table)

Edited by Fireandthethud
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...