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
Xardas
Posts: 83
Joined: Fri Jul 28, 2017 12:30 am

Re: Ask a simple question, get a simple answer

Post by Xardas »

Thx guys. I was trying to seed it with os.time(), but like minmay said, i can't use it... :?
Anyways great explanation. Just one thing to add there. math.randomseed() only accepts integer values, so if you use math.randomseed(Time.systemTime()), you should multiply the Result of Time.systemTime() with 1000, since it returns the time resolution up to milliseconds, otherwise it's not very effective when running it on a loop, like in my case.
In order to get to the other side of the pit you have to get hit by the fireball and die....
Yep.....moving on!
User avatar
Isaac
Posts: 3188
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

Does removeConnector actually work for connectors to the onDrawGui hook?
(Because it never seems to for me. :? I can create party component connectors to it, but can never remove them.)
ColdDeadStone
Posts: 24
Joined: Sat Nov 26, 2016 12:12 pm

Re: Ask a simple question, get a simple answer

Post by ColdDeadStone »

Hello!

I would like to ask if you would have done it exactly the same way or if you know a better way for the following situation:

I have designed a new "Tinycritter" and I want it to play a sound at random intervals.

For this I gave the Critter class = "Timer" and configured this Timer with the following "OnInit" script:

Code: Select all

onInit = function(self)
self.go.sound:disable()
self.go.critterbrain:setSource("function randomintervals(sender)local random = math.random(5,15)sender.go.timer:stop()sender.go.timer:setTimerInterval(random)sender.go.sound:play("critterattention")sender.go.timer:start()end
self.go.timer:setTimerInterval(15)
--self.go.timer:addConnector("onActivate", "critterscript", "randomintervals")
self.go.timer:addConnector("onActivate", "self? sender?", "randomintervals")
self.go.timer:setCurrentLevelOnly(true)
end,
The Timer calls the following script: Edit2: (not anymore)

Code: Select all

function randomintervals(sender)
local random = math.random(5,15)
sender.go.timer:stop()
sender.go.timer:setTimerInterval(random)
sender.go.sound:play("critterattention")
--playSoundAt("critterattention", sender.go.level, sender.go.x, sender.go.y)
sender.go.timer:start()
end
Well, I don't know, is that the best way to reach the goal? It works, but I feel like there's a better way! A Sound class with a cooldown would be nice but I didn't find any information about it in the Wiki https://github.com/JKos/log2doc/wiki/Class-list

Edit: I have now added a Sound class and call sender.go.sound:play("critterattention") instead of playSoundAt.... this way the Sound "goes" with the fleeing Critter! Can I also add a Script Class and fill this script? Hmm...

Edit2: Okay, so I added a Script class and filled it with the Script. I can run the script with the console but not with the Timer! Typing in Console: testcritter.critterbrain:randomintervals() works but the Timer says: "warning! invalid connector target: self.go.critterbrain" 'self.go' don't work, 'self' don't work, 'sender.go' don't work and 'sender' don't work... Hmm...

I am open for every idea! So thanks for reading and happy Holidays! :D
Last edited by ColdDeadStone on Fri Dec 22, 2017 5:29 pm, edited 3 times in total.
Sorry for my poor english... hope you understand what i try to say! :)
kelly1111
Posts: 349
Joined: Sun Jan 20, 2013 6:28 pm

Re: Ask a simple question, get a simple answer

Post by kelly1111 »

ColdDeadStone: I am curious what kind of critter did you make (new animations etc?) and how did you do it? / and will you share it with the community ?
User avatar
akroma222
Posts: 1029
Joined: Thu Oct 04, 2012 10:08 am

Re: Ask a simple question, get a simple answer

Post by akroma222 »

ColdDeadStone wrote:
SpoilerShow

Code: Select all

 onInit = function(self)
    self.go.sound:disable()
    self.go.critterbrain:setSource("function randomintervals(sender)local random = math.random(5,15)sender.go.timer:stop()sender.go.timer:setTimerInterval(random)sender.go.sound:play("critterattention")sender.go.timer:start()end
    self.go.timer:setTimerInterval(15)
    --self.go.timer:addConnector("onActivate", "critterscript", "randomintervals")
    self.go.timer:addConnector("onActivate", "self? sender?", "randomintervals")
    self.go.timer:setCurrentLevelOnly(true)
    end,
The Timer calls the following script: Edit2: (not anymore)
SpoilerShow

Code: Select all

    function randomintervals(sender)
    local random = math.random(5,15)
    sender.go.timer:stop()
    sender.go.timer:setTimerInterval(random)
    sender.go.sound:play("critterattention")
    --playSoundAt("critterattention", sender.go.level, sender.go.x, sender.go.y)
    sender.go.timer:start()
    end
Hey ColdDeadStone,
I suspect the issue (and solution) involves one of these:

1. The order in which you have added components to your TinyCritter Object (this can be an issue)

2. The timer's onInit Hook not triggering when you start up the preview
( I remember someone having dramas with firing their onInit hooks - but I cant for the life of me recall who or where the thread is)

3. Perhaps try adding a ScriptController component to the critter object

4. Maybe try :
self.go.timer:addConnector("onActivate", self.go.id, "randomintervals")
...or
self.go.timer:addConnector("onActivate", self.go.critterbrain, "randomintervals")
EDIT ^^^ this might be the best place to start ;)

Also, this may help...
viewtopic.php?f=22&t=7951&p=110822&hilit=onInit#p110822

Sorry I cant be more precise :(
Quick reply before heading off to work - hope you solve it!
Akroma
ColdDeadStone
Posts: 24
Joined: Sat Nov 26, 2016 12:12 pm

Re: Ask a simple question, get a simple answer

Post by ColdDeadStone »

Code: Select all

self.go.timer:addConnector("onActivate", "self.go.id", "randomintervals")
self.go.timer:addConnector("onActivate", "self.go.critterbrain", "randomintervals")
self.go.timer:addConnector("onActivate", "sender.go.id", "randomintervals")
self.go.timer:addConnector("onActivate", "sender.go.critterbrain", "randomintervals")
Unfortunately, it doesn't work! I added a ScriptController but it didn't change anything. I can add the script via "OnInit" and even run it, but only from the console!

It would be nice to have everything already in the "defineObject" but actually it doesn't matter anyway since the critters belong to a side quest and you can "collect" them. That again calls a "script_entity" in the dungeon anyway, so I can do this with the Sound also "externally". It works externally in any case.

All well so far! I just thought there might be a better way but as I said before, my way is no problem because the critter at "onClick" calls a script in the Dungeon anyway!

Thanks for reading and your time too! Merry Christmas :P

@akroma222: I like your "punk alice" avatar btw ;)

Edit: I forgot to mention that I changed the order of the components... Timer, Script, ScriptController etc. in different sequences! But nothing worked. I start the "onInit" script mostly from the Model Component and had no problems with it so far! Connecting the Timer with a "script_entity" is also no Problem.
Sorry for my poor english... hope you understand what i try to say! :)
User avatar
akroma222
Posts: 1029
Joined: Thu Oct 04, 2012 10:08 am

Re: Ask a simple question, get a simple answer

Post by akroma222 »

ColdDeadStone wrote:

Code: Select all

self.go.timer:addConnector("onActivate", "self.go.id", "randomintervals")
self.go.timer:addConnector("onActivate", "self.go.critterbrain", "randomintervals")
self.go.timer:addConnector("onActivate", "sender.go.id", "randomintervals")
self.go.timer:addConnector("onActivate", "sender.go.critterbrain", "randomintervals")
Ohh, the 2nd argument for addConnector (target), in this case, doesnt need ""
=> Try these {"self.go.id", "self.go.critterbrain", "sender.go.id", "sender.go.critterbrain"} without the " " (I cant spell parenthesis, but spellcheck can :lol: )

Code: Select all

self.go.timer:addConnector("onActivate", self.go.critterbrain, "randomintervals")
ColdDeadStone wrote:@akroma222: I like your "punk alice" avatar btw ;)
Hahah thanks - I held a Disney Disaster themed Party and to design the invites I googled up a bunch of princesses doing not so princessy things :lol: :roll:
bongobeat
Posts: 1076
Joined: Thu May 16, 2013 5:58 pm
Location: France

Re: Ask a simple question, get a simple answer

Post by bongobeat »

Hello all,

is there a way to add a group of monster in a bossfight?
My asset pack: viewtopic.php?f=22&t=9320

Log1 mod : Toorum Manor: viewtopic.php?f=14&t=5505
minmay
Posts: 2789
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

Just add the monsters one by one the same way you would if they weren't in a group. You don't know their ids in advance, of course, but you can use Map:entitiesAt() to find them.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
bongobeat
Posts: 1076
Joined: Thu May 16, 2013 5:58 pm
Location: France

Re: Ask a simple question, get a simple answer

Post by bongobeat »

minmay wrote:Just add the monsters one by one the same way you would if they weren't in a group. You don't know their ids in advance, of course, but you can use Map:entitiesAt() to find them.
hum,
so
instead of doing it like that:

Code: Select all

spawn("medusa_2_xaafi_pair",45,15,5,1,0,"xaafiIngerence_8")
xaafiPremierBoss.bossfight:addMonster(xaafiIngerence_8.monster)
xaafiIngerence_8.monster:addConnector("onDie", "counter_39", "decrement")
SpoilerShow

Code: Select all

defineObject{
	name = "medusa_2_xaafi_pair",
	baseObject = "base_monster_group",	
	components = {
		{
			class = "MonsterGroup",
			monsterType = "medusa_2_xaafi",
			count = 2,
		}
	},
}
I do it with 2 classic monsters?

Code: Select all

spawn("medusa_2_xaafi",45,15,5,1,0)
spawn("medusa_2_xaafi",45,15,5,1,0)
but how I add them into a pair then? Sorry I don't understand.
My asset pack: viewtopic.php?f=22&t=9320

Log1 mod : Toorum Manor: viewtopic.php?f=14&t=5505
Post Reply