Jump to content

[Help] Need more explanation about GetPlayer()


D3monfiend

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...