Ask a simple question, get a simple answer

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
User avatar
Blackswamp
Posts: 16
Joined: Mon Aug 12, 2024 9:24 am

Re: Ask a simple question, get a simple answer

Post by Blackswamp »

I dont any text in there. my init stops in 76 row.
User avatar
THOM
Posts: 1274
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: Ask a simple question, get a simple answer

Post by THOM »

and it's in

Code: Select all

mod_assets/scripts/ 
?
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
User avatar
Blackswamp
Posts: 16
Joined: Mon Aug 12, 2024 9:24 am

Re: Ask a simple question, get a simple answer

Post by Blackswamp »

yes it is
User avatar
Blackswamp
Posts: 16
Joined: Mon Aug 12, 2024 9:24 am

Re: Ask a simple question, get a simple answer

Post 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
User avatar
Sutekh
Posts: 127
Joined: Sun Nov 25, 2012 9:58 am
Location: UK

Re: Ask a simple question, get a simple answer

Post by Sutekh »

I think this should work:

Code: Select all

function setexp()
	turtle_1.monster:setExp(1000)
	end
User avatar
KhrougH
Posts: 76
Joined: Tue Sep 04, 2018 11:45 pm
Location: Roma

Re: Ask a simple question, get a simple answer

Post 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
[...]
All those moments will be lost in time, like tears in rain.
Time to die.
User avatar
Zo Kath Ra
Posts: 937
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: Ask a simple question, get a simple answer

Post 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
User avatar
KhrougH
Posts: 76
Joined: Tue Sep 04, 2018 11:45 pm
Location: Roma

Re: Ask a simple question, get a simple answer

Post by KhrougH »

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
i don't get it, can you be more specific about this concept?
or can someone explain what does it means?
[...]
All those moments will be lost in time, like tears in rain.
Time to die.
User avatar
Isaac
Posts: 3185
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post 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.
Last edited by Isaac on Sat Sep 28, 2024 6:31 am, edited 2 times in total.
User avatar
KhrougH
Posts: 76
Joined: Tue Sep 04, 2018 11:45 pm
Location: Roma

Re: Ask a simple question, get a simple answer

Post 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 :roll:

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