Jump to content

Recommended Posts

I am newbie, who trying to learn lua and hoping to write a script that help me switch tool, weapon, Armour or hat fast without need to look at my inventory.

 

I was backtracking script to find GetPlayer(). But in the end, what i get is GetPlayer() in simutil.lua and nothing more. What i expect GetPlayer() components and more function listed below.

 

I was hoping that someone can teach me on how to know where to get function that is useful for modding.

GetPlayer() is simply a global function that returns a reference to the player entity.

 

So 'GetPlayer().components.health' refers to the health components of the player entity, 'Player().prefab' is the name of the player prefab and so on. To find which components are attached to the player entity, see the player prefab files and player_common.lua.

 

GetWorld() fills the same role for the world entity (to which components handling seasons and hound attacks and so on are attached).

There is also GetSeasonManager() for reasons I never questioned.

 

As said, it does nothing other than returning the player instance. i.e.:

 

local wilson = GetPlayer()

 

print("Has Tag:", wilson:HasTag("player") ) --Has Tag:   true

 

wilson:AddComponent("burnable") --this is a bad idea, but a good example

 

print("Player name is ", wilson.prefab) --Player name is    willow (could be any character)

There is also GetSeasonManager() for reasons I never questioned.

 

As said, it does nothing other than returning the player instance. i.e.:

 

local wilson = GetPlayer()

 

print("Has Tag:", wilson:HasTag("player") ) --Has Tag:   true

 

wilson:AddComponent("burnable") --this is a bad idea, but a good example

 

print("Player name is ", wilson.prefab) --Player name is    willow (could be any character)

When i look at your comment, it reminds me that don't starve is a command prompt.

 

I play around with the inventory.lua and enter this "for k,v in pairs(GetPlayer().inventory.equipslots) do print(k) end" .

 

Now, i am happy to figure out the key for slots are "hands", "body" and "head". I thought the key was 1, 2, 3. 

These functions are derived from the base C++ code.

The game's engine is written in hidden C++, but all the content is written in Lua, which we can see.

Pretty much anything involving "TheSim" is from the C++, as well as some other things.

Basically all you can do is look at examples of working code using the functions, either in mods or the game itself, and try to figure out what they do and how to use them.

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