Ask a simple question, get a simple answer
- Blackswamp
- Posts: 16
- Joined: Mon Aug 12, 2024 9:24 am
Re: Ask a simple question, get a simple answer
I dont any text in there. my init stops in 76 row.
Re: Ask a simple question, get a simple answer
and it's in ?
Code: Select all
mod_assets/scripts/
- Blackswamp
- Posts: 16
- Joined: Mon Aug 12, 2024 9:24 am
- Blackswamp
- Posts: 16
- Joined: Mon Aug 12, 2024 9:24 am
Re: Ask a simple question, get a simple answer
Hello. Hey I want to put custom amount of experience to monsters,what it give on kill, so what did I do wrong? Now it just acts nornally. Here is the code:
function onMonsterKilled(monster)
-- Check if the monster is the one you want to modify XP for
if monster.name == "turtle_1" then
local customXP = 1000
for i = 1, 4 do
local champion = party.party:getChampion(i)
champion:gainExp(customXP)
end
end
end
function onMonsterKilled(monster)
-- Check if the monster is the one you want to modify XP for
if monster.name == "turtle_1" then
local customXP = 1000
for i = 1, 4 do
local champion = party.party:getChampion(i)
champion:gainExp(customXP)
end
end
end
Re: Ask a simple question, get a simple answer
I think this should work:
Code: Select all
function setexp()
turtle_1.monster:setExp(1000)
end
Re: Ask a simple question, get a simple answer
here we go again, hi everybody. i've been away for long ime and now i forgot many things about LUA in LOG2.
so my question is:
ho can i find "breakable" objects in a map?
getClass() doesn't work. getHealth() doesn't work.
here is my short code in a script_entity:
with this script i want to individuate the breakable object wich is in the same cell than the script_entity so i search for all the objects in self.go and if it is breakable than add the connector. breakable objects also has "health" so i also tried this way without solution.
would someone help me please?
thank you in advance
so my question is:
ho can i find "breakable" objects in a map?
getClass() doesn't work. getHealth() doesn't work.
here is my short code in a script_entity:
Code: Select all
function connectBreakables()
local x, y = self.go.x, self.go.y
local lev = self.go.level
local mappa = Dungeon.getMap(lev)
local objects = mappa:entitiesAt(x, y)
for obj in objects do
local oggetto = obj.id
local forza = findEntity(oggetto).components:getHealth()
print("oggetto: "..oggetto.." - forza: "..forza)
if oggetto and forza then
oggetto.health:addConnector("onDie", self.go.id, "spannatorcia")
end
end
end
function spannatorcia()
self.go:spawn("torch")
end
would someone help me please?
thank you in advance
[...]
All those moments will be lost in time, like tears in rain.
Time to die.
All those moments will be lost in time, like tears in rain.
Time to die.
- Zo Kath Ra
- Posts: 937
- Joined: Sat Apr 21, 2012 9:57 am
- Location: Germany
Re: Ask a simple question, get a simple answer
You can list an entity's components with GameObject:componentIterator()
https://github.com/JKos/log2doc/wiki/Ob ... gameobject
Re: Ask a simple question, get a simple answer
i don't get it, can you be more specific about this concept?Zo Kath Ra wrote: ↑Sat Sep 21, 2024 9:20 pm You can list an entity's components with GameObject:componentIterator()
https://github.com/JKos/log2doc/wiki/Ob ... gameobject
or can someone explain what does it means?
[...]
All those moments will be lost in time, like tears in rain.
Time to die.
All those moments will be lost in time, like tears in rain.
Time to die.
Re: Ask a simple question, get a simple answer
You could use the object's own onInit hook to check for the script and connect to it. Each object could automatically connect to the script if their locations match at the start.
Or, alternatively this updated script finds and connects breakable objects on its own tile, and later spawns a torch after each connected breakable object is destroyed.
If your script moves around during the game, then you must call connectBreakables() each time the script is moved.
*The use of oggetto.health:getConnectorCount() < 1 above prevents having multiple onDie connectors (and spawning multiple torches when destroyed) in the case where connectBreakables() is called on a tile having a previously connected object.
If your script moves, and moves away from the tile before any breakable objects are destroyed then you probably want to remove those object's onDie connectors.
Or, alternatively this updated script finds and connects breakable objects on its own tile, and later spawns a torch after each connected breakable object is destroyed.
Code: Select all
function connectBreakables()
local x, y = self.go.x, self.go.y
local lev = self.go.level
local mappa = Dungeon.getMap(lev)
local objects = mappa:entitiesAt(x, y)
for obj in objects do
local oggetto = findEntity(obj.id)
if oggetto and oggetto.health and oggetto.health:getConnectorCount() < 1 then --[edited]
print("oggetto: "..oggetto.id)
oggetto.health:addConnector("onDie", self.go.id, "spannatorcia")
end
end
end
connectBreakables()
function spannatorcia()
self.go:spawn("torch")
print('spawned torch')
end
If your script moves around during the game, then you must call connectBreakables() each time the script is moved.
*The use of oggetto.health:getConnectorCount() < 1 above prevents having multiple onDie connectors (and spawning multiple torches when destroyed) in the case where connectBreakables() is called on a tile having a previously connected object.
If your script moves, and moves away from the tile before any breakable objects are destroyed then you probably want to remove those object's onDie connectors.
Last edited by Isaac on Sat Sep 28, 2024 6:31 am, edited 2 times in total.
Re: Ask a simple question, get a simple answer
this was my last try:
... and didn't work anyway
by the way, i tried your script and it works , but only where the script is. in fact self.go:spawn means spawn where Game ID is (the script himself).
but what if i try with allEntities? how can i identify the breakable object? how can i pass the variable of the finded breakable object to the spannatorcia() function considering the addConnection() caller?
Code: Select all
function connectBreakables()
local objects = Dungeon.getMap(self.go.level):allEntities()
local newObjects = {}
for i in objects do
if i then
table.insert(newObjects,i.id)
end
end
for _, obj in ipairs(newObjects) do
local oggetto = findEntity(obj).class
if obj.class == "Obstacle" and obj.class == "Health" then
obj.health:addConnector("onDie", self.go.id, "spannatorcia")
end
end
end
function spannatorcia()
self.go:spawn("torch")
end
by the way, i tried your script and it works , but only where the script is. in fact self.go:spawn means spawn where Game ID is (the script himself).
but what if i try with allEntities? how can i identify the breakable object? how can i pass the variable of the finded breakable object to the spannatorcia() function considering the addConnection() caller?
[...]
All those moments will be lost in time, like tears in rain.
Time to die.
All those moments will be lost in time, like tears in rain.
Time to die.