Page 394 of 396
Re: Ask a simple question, get a simple answer
Posted: Thu Aug 22, 2024 7:01 pm
by Blackswamp
I dont any text in there. my init stops in 76 row.
Re: Ask a simple question, get a simple answer
Posted: Thu Aug 22, 2024 7:12 pm
by THOM
Re: Ask a simple question, get a simple answer
Posted: Wed Aug 28, 2024 3:26 pm
by Blackswamp
yes it is
Re: Ask a simple question, get a simple answer
Posted: Wed Aug 28, 2024 3:32 pm
by Blackswamp
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
Re: Ask a simple question, get a simple answer
Posted: Wed Aug 28, 2024 5:43 pm
by Sutekh
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
Posted: Sat Sep 21, 2024 6:38 pm
by KhrougH
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:
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
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
Re: Ask a simple question, get a simple answer
Posted: Sat Sep 21, 2024 9:20 pm
by Zo Kath Ra
KhrougH wrote: ↑Sat Sep 21, 2024 6:38 pm
how can i find "breakable" objects in a map?
getClass() doesn't work. getHealth() doesn't work.
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
Posted: Thu Sep 26, 2024 8:02 pm
by KhrougH
i don't get it, can you be more specific about this concept?
or can someone explain what does it means?
Re: Ask a simple question, get a simple answer
Posted: Thu Sep 26, 2024 10:44 pm
by Isaac
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.
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.
Re: Ask a simple question, get a simple answer
Posted: Sat Sep 28, 2024 1:35 am
by KhrougH
this was my last try:
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
... 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?