Fireandthethud Posted March 28, 2015 Share Posted March 28, 2015 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 More sharing options...
DarkXero Posted March 28, 2015 Share Posted March 28, 2015 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 More sharing options...
rezecib Posted March 28, 2015 Share Posted March 28, 2015 But if you do need Vector3 in the future, the problem is that it's outside of the modmain's sandbox, so you have to access it with GLOBAL.Vector3. Link to comment Share on other sites More sharing options...
Fireandthethud Posted March 29, 2015 Author Share Posted March 29, 2015 (edited) 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 March 29, 2015 by Fireandthethud Link to comment Share on other sites More sharing options...
rezecib Posted March 29, 2015 Share Posted March 29, 2015 @Fireandthethud, Use this:local pos = GLOBAL.Vector3(inst.Transform:GetWorldPosition():Get()) Link to comment 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