|
Post by doulos on Jun 14, 2016 22:56:01 GMT
So, I have an NPC that I want to call 2 guards at a certain life % (for testing purpose I have it set at 95%). I placed a local variable called babcount, set it to 0, and then I wanted to increment it twice in the code so that it calls both guards. What am I doing wrong here? I am sure it's easy to fix but I'm still learning how the scripting works here. Here is the full script.
I want the if statement (if crea.Isplayer) to be called twice, which is why I put the babcount < 2 before the do. I think that part is incorrect.
As an aside, which language is this syntax closest to so that I can look things up on my own?
|
|
|
Post by doulos on Jun 14, 2016 23:48:29 GMT
Nevermind, I think I figured it out. I just removed the whole babcount part and instead generated the 2nd npc inside the if statement. I see why it wouldn't incrmement the variable.
|
|
|
Post by Afara on Jun 15, 2016 7:08:25 GMT
Wow, this is exciting things. I tried the script and it seems to work fine! I'm thinking these types of scripts will become very common, I should add an even simpler way to make them. Like a special event you can register for, triggering at a certain health ratio (then would be no need for the spawnBLocked variable). Also adding room.Players would remove check for IsPlayer etc.
|
|
|
Post by Kreshnic on Jun 15, 2016 16:48:06 GMT
Well I thought I had a cool idea, then I remembered my idea sucked and what I thought was wrong. So if you saw my post before now then yes, I know it was wrong. If you didn't see it before now, then pretend like your not reading this . Also unless I am mistaken that looks like a variety of Basic, maybe VB or something built on VB. You probably already figured most of that out but I wanted to say it anyway .
|
|
|
Post by doulos on Jun 15, 2016 16:55:28 GMT
babcount iterates at the end of the for statement, so I thought that
1) babcount = 0
2) for loop spawns the creature
3) for loop iterates babcount by 1 (0+1 = 1)
4) babcount = 1
5) for loops spawns a second creature
6) for loop iterates babcount by 1 (1+1 = 2)
7) all done!
At least this was how I thought it was set up.
The part I think that was messing it up was:
for crea in iter(npc.Room.Creatures) - I'm not 100% sure on what that is checking. Does that mean for each creature in the room? If so then it would only spawn 1 guard no matter what babcount is at if there is only 1 player in the room. On the flipside my fix would still be wrong since if there was more than 1 player in the room it would now spawn 2 guards for each player.
Perhaps Afara could she some light on this for me.
|
|
|
Post by Kreshnic on Jun 15, 2016 17:12:56 GMT
Yea it took me a minute but then it hit me my reasoning for why it wasn't working was really why it was supposed to work. That iterator idea is probably right, if the player is not counted in the creature iterator then yea it would only run once. Oh well, I sounded cool for a second at least . I don't know if you can, but you could take a look at the script Afara put on the Stone Giant Templar(I think that's his name anyway). that guy spawns 3 guards when his health gets low. If you want to check it out I think now that I mentioned it I'm gunna go kill him agian, your welcome to tag along .
|
|
|
Post by doulos on Jun 15, 2016 17:25:18 GMT
No access to the Stone Giant Templar. My NPC is working as expected right now, but I need to test it with more than one player and see what happens!
|
|
|
Post by doulos on Jun 15, 2016 18:18:21 GMT
So I tested it out and with 2 players in the room, 4 guards are spawned. I'll need to write it up differently. Good to know though as I can think of some reasons why scaling spawns might be a good idea to defend against groups!
|
|