Jump to content

Recommended Posts

In need of an example of how to make an item spawn where I need it to.I gave this and a few others a go.       SpawnPrefab("axe").Transform:SetPosition(inst.Transform:GetWorldPosition(-445, 20, 0))

Usually you'll want to store your prefab in a local variable for best possible access. The rest you did was fine though 20 in the y-direction would mean that the prefab spawns high above the ground and will fall down. I usually do it like this when spawning an item, in this case close to the player.

local pig = SpawnPrefab("pigman")local player = GetPlayer()local pos = player:GetPosition()pos.x = pos.x + 6pos.z = pos.z + 6pig.Transform:SetPosition(pos:Get())pig.components.combat:SuggestTarget(player)--this line shows why it might make sense to store the prefab in a variable

Calling down rain is actually a really easy oneliner, I guess you can figure it out  ; )

GetSeasonManager():ForcePrecip()

Hope it helps.

Usually you'll want to store your prefab in a local variable for best possible access. The rest you did was fine though 20 in the y-direction would mean that the prefab spawns high above the ground and will fall down. I usually do it like this when spawning an item, in this case close to the player.

local pig = SpawnPrefab("pigman")local player = GetPlayer()local pos = player:GetPosition()pos.x = pos.x + 6pos.z = pos.z + 6pig.Transform:SetPosition(pos:Get())pig.components.combat:SuggestTarget(player)--this line shows why it might make sense to store the prefab in a variable

Calling down rain is actually a really easy oneliner, I guess you can figure it out  ; )

GetSeasonManager():ForcePrecip()

Hope it helps.

Thank you very much!

Usually you'll want to store your prefab in a local variable for best possible access. The rest you did was fine though 20 in the y-direction would mean that the prefab spawns high above the ground and will fall down. I usually do it like this when spawning an item, in this case close to the player.

local pig = SpawnPrefab("pigman")local player = GetPlayer()local pos = player:GetPosition()pos.x = pos.x + 6pos.z = pos.z + 6pig.Transform:SetPosition(pos:Get())pig.components.combat:SuggestTarget(player)--this line shows why it might make sense to store the prefab in a variable

Calling down rain is actually a really easy oneliner, I guess you can figure it out  ; )

GetSeasonManager():ForcePrecip()

Hope it helps.

Is there an easy way to add the icon for your prefab to the minimap?

  • Developer

Is there an easy way to add the icon for your prefab to the minimap?

This should work:

local minimap = inst.entity:AddMiniMapEntity()minimap:SetIcon( "beehive.png" )

I'd also like to suggest checking out the Scripting with Sublime guide.  I didn't know how to add a minimap icon but I just searched for the word 'minimap' using Sublime and came up with a ton of examples.  The guide might be helpful if you need to search for other things in the future.

This should work:

local minimap = inst.entity:AddMiniMapEntity()minimap:SetIcon( "beehive.png" )

I'd also like to suggest checking out the Scripting with Sublime guide.  I didn't know how to add a minimap icon but I just searched for the word 'minimap' using Sublime and came up with a ton of examples.  The guide might be helpful if you need to search for other things in the future.

Of course, finding the code is obvious. But I never managed to add my own icons. Maybe I'm just stupid though  ^^'

  • Developer

Of course, finding the code is obvious. But I never managed to add my own icons. Maybe I'm just stupid though  ^^'

I think it should be as simple as compiling a new tex and specifying that name in the 'SetIcon' method but if it isn't, let me know and I'll look into it.

I would be very interested in knowing how exactly to read in a custom map icon - as far as I was aware, we couldn't do it, due to the way the map icons were set up!

Yes I always thought we had to add our icon to the sheet along with the added xml info,but this looks hopeful!

I'll do my best to add a custom minimap icon. I'll let you know if it works as expected.

EDIT: Nope, no way I'm gonna do this. I put the file in 5 different locations, used 3 different combinations of code and naming, all the same result:

Assert failure 'icon_element != NULL' at ..\source\game\components\MiniMapRenderer.cpp(371): Trace follows...

So, Cheerio any clues on how to do it exactly? Because the naming of the files in the minimap folder as well as the fact that the images are called "*.png" confuse me as to how it's done properly

Edited by Malacath
  • Developer

I'll do my best to add a custom minimap icon. I'll let you know if it works as expected.

EDIT: Nope, no way I'm gonna do this. I put the file in 5 different locations, used 3 different combinations of code and naming, all the same result:

Assert failure 'icon_element != NULL' at ..\source\game\components\MiniMapRenderer.cpp(371): Trace follows...

So, Cheerio any clues on how to do it exactly? Because the naming of the files in the minimap folder as well as the fact that the images are called "*.png" confuse me as to how it's done properly

That sucks.  I'll look into it :).

  • Developer

I'll do my best to add a custom minimap icon. I'll let you know if it works as expected.

EDIT: Nope, no way I'm gonna do this. I put the file in 5 different locations, used 3 different combinations of code and naming, all the same result:

Assert failure 'icon_element != NULL' at ..\source\game\components\MiniMapRenderer.cpp(371): Trace follows...

So, Cheerio any clues on how to do it exactly? Because the naming of the files in the minimap folder as well as the fact that the images are called "*.png" confuse me as to how it's done properly

So it used to be hard to do because you had to add your own images to the minimap atlas but in the next hotfix for the public preview it's much easier.  There will be basically 3 parts to setting up a minimap icon.

 

Step#1: Load a new atlas for your minimap

local image_path = resolvefilepath("images/myminimap.tex")local atlas_path = resolvefilepath("images/myminimap.xml")local Assets ={    Asset("IMAGE", image_path),    Asset("ATLAS", atlas_path),}
 
Step#2: Tell the minimap about your new atlas
GetWorld().minimap.MiniMap:AddAtlas(atlas_path)

 

Step#3: Tell your prefab which icon to use inside your minimap atlas

local minimap = inst.entity:AddMiniMapEntity()minimap:SetIcon( "myminimap.tex" )
 
And that should work.  Remember, this won't work until the new hotfix for the public preview is available which should be in the next couple of days.
 
 post-283016-0-14517700-1381894475_thumb.
post-283016-0-31132500-1381894478_thumb.

Brilliant!
Been looking forward to being able to do this. I didn't think it was possible, so I'm glad to know that was - and more importantly, is no longer - the case. =)

 

Edit: One thing! How big should our map icons be? What image-dimensions?

Edited by TheDanaAddams
  • Developer

Brilliant!

Been looking forward to being able to do this. I didn't think it was possible, so I'm glad to know that was - and more importantly, is no longer - the case. =)

 

Edit: One thing! How big should our map icons be? What image-dimensions?

They can be whatever size looks good to you, just make sure they're square.  Also if you have one or two icons, having seperate .tex files is fine but if you're going to add a bunch of minimap icons, it'll run way better if you make one big atlas with all the images inside.

They can be whatever size looks good to you, just make sure they're square.  Also if you have one or two icons, having seperate .tex files is fine but if you're going to add a bunch of minimap icons, it'll run way better if you make one big atlas with all the images inside.

Great, thanks a lot  ^^

 

@TheDanaAddams If I'm not mistaken then the vanilla minimap icons are 64x64.

This should work:

local minimap = inst.entity:AddMiniMapEntity()minimap:SetIcon( "beehive.png" )

I'd also like to suggest checking out the Scripting with Sublime guide.  I didn't know how to add a minimap icon but I just searched for the word 'minimap' using Sublime and came up with a ton of examples.  The guide might be helpful if you need to search for other things in the future.

Thanks for the scripting tools! I searched and tryed and tryed with no success, then read the rest of the thread ;)

Edited by afro1967

This should work:

local minimap = inst.entity:AddMiniMapEntity()minimap:SetIcon( "beehive.png" )

I'd also like to suggest checking out the Scripting with Sublime guide.  I didn't know how to add a minimap icon but I just searched for the word 'minimap' using Sublime and came up with a ton of examples.  The guide might be helpful if you need to search for other things in the future.

Another deal I need help with is tut example.I have created an animal and for the life of me can't get the animation to flip directions.Your help would be appreciated. If chased from behind he runs forward okay, but the darn stubborn ass will not turn around if chased from the front.

  • Developer

Thanks SetTwoFaced worked for now,but how will the face and back animation be called? SetFourFaced but how will the game specify?

There's a naming convention for the animations for four faced.  If you wanted to use a set of animations called 'walk_loop'and you set your prefab to four faced, your animations would have to be called 'walk_loop_up', 'walk_loop_down' and 'walk_loop_side' and the animation system will handle picking the right animation for you.

There's a naming convention for the animations for four faced.  If you wanted to use a set of animations called 'walk_loop'and you set your prefab to four faced, your animations would have to be called 'walk_loop_up', 'walk_loop_down' and 'walk_loop_side' and the animation system will handle picking the right animation for you.

Thanks again! I really am trying figure this code out for myself.

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