Page 214 of 400
Re: Ask a simple question, get a simple answer
Posted: Fri Nov 10, 2017 2:23 pm
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.
Re: Ask a simple question, get a simple answer
Posted: Fri Dec 01, 2017 9:12 am
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.)
Re: Ask a simple question, get a simple answer
Posted: Fri Dec 22, 2017 3:49 pm
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!

Re: Ask a simple question, get a simple answer
Posted: Fri Dec 22, 2017 4:36 pm
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 ?
Re: Ask a simple question, get a simple answer
Posted: Sat Dec 23, 2017 5:23 am
by akroma222
ColdDeadStone wrote:
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
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
Re: Ask a simple question, get a simple answer
Posted: Sat Dec 23, 2017 10:47 am
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
@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.
Re: Ask a simple question, get a simple answer
Posted: Sat Dec 23, 2017 12:32 pm
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

)
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

Re: Ask a simple question, get a simple answer
Posted: Sat Dec 30, 2017 2:03 pm
by bongobeat
Hello all,
is there a way to add a group of monster in a bossfight?
Re: Ask a simple question, get a simple answer
Posted: Sat Dec 30, 2017 11:46 pm
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.
Re: Ask a simple question, get a simple answer
Posted: Sun Dec 31, 2017 8:02 pm
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")
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.