Jump to content

Need help with generating lua code [KleiCreator]


Recommended Posts

For my project KleiCreator, I need to generate lua code from Java.

I currently need help with creating all the templates for all the components. The current components:

 - Armor (has resistance)

- Axe (has efficiency)

- Dapperness (has rate)

- Durability (has max_durability

- Edible (has health, sanity & hunger)

- Equippable (has place [Hat, Chest, Hand])

- Waterproof (has effectiveness)

(Anything is brackets is something the user specifics. If I'm missing anything, please mention it and I'll add the field)

For these components, I need to generate a couple lines of lua code that I can insert in the prefab file. I've haven't made that many items before, and I don't really know where to start when implementing these features. Any and all help would be welcome.

Link to comment
Share on other sites

Here's how you can implement all of these components into a prefab.

1. Armor:

Spoiler

Armor(absorption, is_indestructable, condition, absorptiontags, weakness, onarmorhit, onarmorbreak)


inst:AddComponent("armor")
if is_indestructible then
	inst.components.armor:InitIndestructible(absorption)
else
	inst.components.armor:InitCondition(condition, absorption)
	inst.components.armor.onfinished = onarmorbreak or nil

	if weakness then
		for weakness, bonus_damage in pairs(weakness) do
			inst.components:AddWeakness(weakness, bonus_damage)
		end
	end
end

inst.components.armor:SetTags(absorptiontags or nil)
inst.components.armor.ontakedamage = onarmorhit or nil

absorption - a float value between 0 and 1
is_indestructable - a boolean
condition - an integer value, the health of the armor
absorptiontags - a table containing tags that this armor can block, nil if blocks everything
weakness - a table containing tags with the amount bonus damage assigned to them
onarmorhit - a function run when getting hit with this armor
onarmorbreak - a function run when this armor breaks

2. There's no "axe" component, I think you mean the "tool" component:

Spoiler

Tool(action, effectiveness)


inst:AddComponent("tool")
inst.components.tool:SetAction(action, effectiveness)

action - a string that determines the action this tool is used for
effectiveness - an integer value which determines the amount of "work" that is done per action

3. Dapperness is a part of the equippable component.

4. There's no "durability" component, I think you mean the "finiteuses" component:

Spoiler

FiniteUses(action, consumption, maxuses, onitembreak)


inst:AddComponent("finiteuses")
inst.components.finiteuses:SetConsumption(action, consumption)
inst.components.finiteuses:SetMaxUses(maxuses or 100)
inst.components.finiteuses:SetOnFinished(ontoolbreak)

action - a string that determines what action consumes the uses
consumption - an integer value which determines how much uses is consumed when performing an action
maxuses - an integer value, total uses of the item
onitembreak - a function run when the item depletes

5. Edible:

Spoiler

Edible(foodtype, secondaryfoodtype, health, hunger, sanity, degrades_with_spoilage, stale_health, spoiled_health, stale_hunger, spoiled_hunger, temperaturedelta, temperatureduration, oneaten, healthfn)


inst:AddComponent("edible")
inst.components.edible.foodtype = foodtype or FOODTYPE.GENERIC
inst.components.edible.secondarydooftype = secondaryfoodtype or nil
inst.components.edible.healthvalue = health or 10
inst.components.edible.hungervalue = hunger or 10
inst.components.edible.sanityvalue = sanity or 0
inst.components.edible.temperaturedelta = temperaturedelta or 0
inst.components.edible.temperatureduration = temperatureduration or 0

if degrades_with_spoilage then
	inst.components.edible.degrades_with_spoilage = degrades_with_spoilage
	inst.components.edible.stale_health = stale_health or TUNING.STALE_FOOD_HEALTH
	inst.components.edible.spoiled_health = spoiled_health or TUNING.SPOILED_FOOD_HEALTH
	inst.components.edible.stale_hunger = stale_hunger or TUNING.STALE_FOOD_HUNGER
	inst.components.edible.spoiled_hunger = spoiled_hunger or TUNING.SPOILED_FOOD_HUNGER
end

inst.components.edible:SetOnEatenFn(oneaten)
inst.components.edible:SetGetHealthFn(healthfn)

foodtype - a string that determines what type of food this is
secondaryfoodtype - a string, same as above
health - a float or integer value, amount of health this food gives
hunger - a float or integer value, amount of hunger this food gives
health - a float or integer value, amount of sanity this food gives
degrades_with_spoilage - a boolean which determines whether the food should use its stale/spoiled health and hunger values when spoiling
stale_health - a float value between 0 and 1, percentage of health this food gives when stale
spoiled_health - a float value between 0 and 1, percentage of health this food gives when spoiled
stale_hunger - a float value between 0 and 1, percentage of hunger this food gives when stale
spoiled_hunger - a float value between 0 and 1, percentage of hunger this food gives when spoiled
temperaturedelta - a float or integer value, amount of temperature gain/loss when eating this food
temperatureduration - a float or integer value, amount of time in which players temperature will change based on temperaturedelta
oneatenfn - a function run then this food is eaten
healthfn - a function which determines what health value should be applied to the eater, overrides "health"

6. Equippable:

Spoiler

Equippable(equipslot, equipstack, onequip, onunequip, onget, walkspeedmult, dapperness, dapperfn, isinsulated, equippedmoisture, maxequippedmoisture, restrictedtag)


inst:AddComponent("equippable")
inst.components.equippable.equipslot = equipslot or EQUIPSLOT.HANDS
inst.components.equippable.equipstack = equipstack or false
inst.components.equippable:SetOnEquip(onequip)
inst.components.equippable:SetOnUnequip(onunequip)
inst.components.equippable:SetOnPocket(onget)
inst.components.equippable.walkspeedmult = walkspeedmult or nil
inst.components.equippable.dapperness = dapperness or 0
inst.components.equippable.dapperfn = dapperfn or nil
inst.components.equippable.insulated = isinsulated or false
inst.components.equippable.equippedmoisture = equippedmoisture or 0
inst.components.equippable.maxequippedmoisture = maxequippedmoisture or 0
inst.components.equippable.restrictedtag = restrictedtag or nil

equipslot - a string that determines what slot this item can be equipped in
equipstack - a boolean, whether a stack of this item can be equipped (example, blowdarts)
onequip - a function run when this item is equipped
onunequip - a function run when this item is unequipped
onget - a function run when this item is put in the inventory
walkspeedmult - a float value, multiplies players movement speed when equipped
dapperness - a float or integer value, determines the amount of sanity gain/loss when equipped
dapperfn - a function that return the amount of sanity gain/loss when equipped, overrides "dapperness"
isinsulated - a boolean, whether this item should protect from lightning
equippedmoisture - a float or integer value that determines the rate of moisture gain when the item is equipped
maxequippedmoisture - a float or integer value that determines the maximum moisture this item can give
restrictedtag - a string, entities with this tag cannot equip this item

7. Waterproofer:

Spoiler

Waterproofer(effectiveness)


inst:AddComponent("waterproofer")
inst.components.waterproofer:SetEffectiveness(effectiveness or 1)

effectiveness - a float value between 0 and 1 that determines the protection this item provides against rain

 

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