Post new topic    
Liquid Metal Slime
Send private message
NPCs activating other NPCs 
 PostWed Dec 30, 2009 5:45 pm
Send private message Reply with quote
Another scripting question...

Let's say I create an NPC on a map, and another NPC touches the created npc. Is there any way to make the npc activate the script attached to the created npc or is that limited to heros only?

Example script:

Code:
plotscript,example,begin
   variable (posx)
   variable (posy)

   posx := npc X (2)
   posy := npc Y (2)
   if (npc at spot (posx,posy,1)) then (
   destroy npc (1)
   destroy npc (2)
   )
end

Cornbread Chemist
Liquid Metal King Slime
Send private message
 
 PostWed Dec 30, 2009 7:32 pm
Send private message Reply with quote
well, this sort of thing becomes easier if you have obstruction suspended. Cause then you can wait till the npcs are on top of each other which is easier to check for. Which would be what you're seeming to want to do with your script there.

One problem you might run into with this script is the layering.
Code:
if (npc at spot (posx,posy,1))

The 1 in this line of script is the layer the npc is on. If npc 2 is considered to be OVEr npc 1 (or whichever npc npc2 is touching) then the script won't work.
This can be fixed with either a for statement or some sort of get count command instead of the 1.

Another problem with the script also has to do with that 1.
You destroy npc 1 but it doesn't take npc1 to trigger this effect. To do that you'd need to do something like this.

Code:
if (  get npc ID( npc at spot (posx,posy,1) ) == 1 )




The last problem you might run into with this script is if you have more then 1 copy of either npc 1 or npc 2.

In that case you'd want to have a for command save the specific reference of each copy as a variable and then check each one for collision.



Hope this helps.
Liquid Metal Slime
Send private message
 
 PostWed Dec 30, 2009 11:00 pm
Send private message Reply with quote
Quote:
well, this sort of thing becomes easier if you have obstruction suspended. Cause then you can wait till the npcs are on top of each other which is easier to check for. Which would be what you're seeming to want to do with your script there.


That's what I was afraid of. I won't be able to leave obstruction suspended due to other factors in the game, so is there a better way to accomplish what I am trying to do?

Essentially, an npc is created that hosts a script and when pressed on by an npc it runs the script. That way the original idea anyways. Basically, I just need it to be triggered by an npc.

I appreciate the help on this.
Cornbread Chemist
Liquid Metal Slime
Send private message
 
 PostThu Dec 31, 2009 1:32 am
Send private message Reply with quote
You could use the automated NPC approach, where something happens whenever the NPC matches a condition.

To do this, use a timer. Have it expire and reset every few ticks until the condition is met. When the condition is met, have it launch the script.

I use direction and proximity conditions for mine.

For example:

Code:
If ((direction==east),and,(x==34)) then(
Do Script
stop timer (1)
)


The trick is to write a conditional that anticipates where the trigger NPC will be standing. This is where you would want to search for NPC references and their locations.

You can technically use this to achieve any NPC effect, including alter NPC and whatever you need the script to do.

Give it a try and let me know if you have any further questions on the matter.
Place Obligatory Signature Here
Liquid Metal King Slime
Send private message
 
 PostThu Dec 31, 2009 3:03 am
Send private message Reply with quote
If you want to do it without obstruction suspended, and assuming the two npc's are both moving around randomly or something. You could check all the squares around the npc. Well you'd most likely not have to ( or want to) check ALL the squares just the 4 to the left/right or up/down from your npc.

So you'd do something like this.
This script has not been tested. It's only an example.

Code:

plotscript,example,begin
   variable (posx)
   variable (posy)


if (  get npc ID( npc at spot (posx+1,posy,1) ) == 1 ) then (stuff)
if (  get npc ID( npc at spot (posx--1,posy,1) ) == 1 ) then (stuff)
if (  get npc ID( npc at spot (posx,posy+1,1) ) == 1 ) then (stuff)
if (  get npc ID( npc at spot (posx,posy--1,1) ) == 1 ) then (stuff)

end

script,stuff,begin
   posx := npc X (2)
   posy := npc Y (2)
   if (npc at spot (posx,posy,1)) then (
   destroy npc (1)
   destroy npc (2)
)
end


This is assuming of course that you don't run into the other probelm I saw with your script. Activation of the script itself. How are you gonna do that?
Liquid Metal Slime
Send private message
 
 PostThu Dec 31, 2009 5:49 pm
Send private message Reply with quote
I got it to work without having it triggered from an npc! Couldn't have done it without the help from both of you.

I do still have one question though. Is there any way to figure out exactly how many copies of an npc are on each map and store it into variables?

Also, would I be better off using different npcs rather than multiple copies of a single npc?
Cornbread Chemist
Liquid Metal Slime
Send private message
 
 PostThu Dec 31, 2009 6:10 pm
Send private message Reply with quote
This is what I'm working with right now:

Code:
plotscript,game,begin
   variable(playing)
   variable (mob1)
   variable (mob2)
   variable (mob3)
   variable (mob4)
   set variable(mob1,NPC reference(1,0))
   set variable(mob2,NPC reference(1,1))
   set variable(mob3,NPC reference(1,2))
   set variable(mob4,NPC reference(1,3))
   playing := true
   while (playing) do(
      variable (direction)
      variable (posx)
      variable (posy)
      variable (pposx)
      variable (pposy)
      if (  get npc ID( npc at spot (pposx,pposy) ) == mob1 ) then (
            #Commented out for now  if (npc at spot (pposx,pposy) == mob1) then (
         destroy npc (mob1)
         set variable (pposx,0)
         set variable (pposy,0))
      if (key is pressed(44)) then (
         if (npc copy count(2) == 0) then(
            if (pposx == 0) then (
               posx := hero X (0)
               posy := hero Y (0)
               direction := hero direction (0)
               if (direction == up) then (
                  create npc (2,posx,(posy)+1)
                  wait for npc (2)
                  pposx := npc X (2)
                  pposy := npc Y (2)
                  wait (5)
                  destroy npc(2))
            )
         )
      )
   wait (1)
   )
end


I have four enemies on the map. I'm trying to set the script so it checks which npc meets the condition to be deleted (I only have it set up to check the first enemy, mob1, right now). However, it seems like it is automatically deleting mob1 before pposx and pposy even have coordinates in them, which I'm not really sure why.
Cornbread Chemist
Liquid Metal King Slime
Send private message
 
 PostThu Dec 31, 2009 11:14 pm
Send private message Reply with quote
First, yes. There is an easy way to detect how many of a type of NPC are on a map.
It's a command:
NPC copy count (ID)


As for your script.
Right now I suspect it wouldn't work.
This is because you're comparing NPC id's with npc referneces.
You either have to change the MOB variables to ID's, check for only the reference (with might not work, I'm not sure), or do something like this.
Quote:
if ( get npc ID( npc at spot (pposx,pposy) ) == get npc ID(mob1 ) )
And of course you'd have to repeat said script for each of your mob variables.

Also, you're writing it in a very strung out way. Using things like the for command could lessen the writing. But I'm not really one to criticize on this sort of thing, since I do it all the time myself.
Liquid Metal Slime
Send private message
 
 PostFri Jan 01, 2010 7:58 pm
Send private message Reply with quote
Spoonweaver wrote:


Also, you're writing it in a very strung out way. Using things like the for command could lessen the writing. But I'm not really one to criticize on this sort of thing, since I do it all the time myself.


Dude, any suggestions on my writeup is much appreciated. I am anything but awesome at this stuff, and want to learn from any mistakes or redundancy that I create.

Well, with the suggested info, I had the script working properly. It seemed to single out each enemy on the map and destroy them accordingly.

Now, for some reason, it seems to kill them in order (mob1, mob2...), regardless of whether they are at the given spot or not. In other words, mob4 can roll over the bad area and kill mob1 instead of himself.

Also, it seems as when the hero is facing right and creates the bad spot, the bad spot is created on his left side (which is right) but is all the way up at the top of the screen (which is wrong). Not sure what a fix for that would be though.

I'll mark that particular spot in the code:

Code:
plotscript,game,begin
   mob1 := npc reference(1,0)
   mob2 := npc reference(1,1)
   mob3 := npc reference(1,2)
   mob4 := npc reference(1,3)
   playing := true
   while (playing) do(
      if ( get npc ID( npc at spot (pposx,pposy) ) == get npc ID(mob1 ) ) then (
         destroy npc (mob1)
         destroy npc (2)
         pposx := 99
         pposy := 99)
      if ( get npc ID( npc at spot (pposx,pposy) ) == get npc ID(mob2 ) ) then (
         destroy npc (mob2)
         destroy npc (2)
         pposx := 99
         pposy := 99)
      if ( get npc ID( npc at spot (pposx,pposy) ) == get npc ID(mob3 ) ) then (
         destroy npc (mob3)
         destroy npc (2)
         pposx := 99
         pposy := 99)
      if ( get npc ID( npc at spot (pposx,pposy) ) == get npc ID(mob4 ) ) then (
         destroy npc (mob4)
         destroy npc (2)
         pposx := 99
         pposy := 99)
      if (key is pressed(44)) then (
         if (npc copy count (2) == 0) then (
               posx := hero X (0)
               posy := hero Y (0)
               direction := hero direction (0)
               if (direction == up) then (
                  create npc (2,posx,(posy)+1)
                  wait for npc (2)
                  pposx := npc X (2)
                  pposy := npc Y (2))
               if (direction == down) then (
                  create npc (2,posx,(posy)-1)
                  wait for npc (2)
                  pposx := npc X (2)
                  pposy := npc Y (2))
               if (direction == left) then (
                  create npc (2,(posx)+1,(posy))
                  wait for npc (2)
                  pposx := npc X (2)
                  pposy := npc Y (2))
-->               if (direction == right) then (
                  create npc (2,(posx)-1,(posy))
                  wait for npc (2)
                  pposx := npc X (2)
                  pposy := npc Y (2)) <--
            )
         )
   wait (1)
   )
end

Cornbread Chemist
Liquid Metal King Slime
Send private message
 
 PostFri Jan 01, 2010 10:44 pm
Send private message Reply with quote
Oh, right, that WOULD happen.
This is actually because of the reduntacy I mentioned before.

You might have to use for statements after all.

And the other part is basically because to subtract you need 2 -'s. like this " -- " . Dunno, why you don't need 2 +'s but sure there's a reason.

So here's how it would go:

Code:


plotscript,game,begin

   playing := true
   while (playing) do(

variable (spoon)

for (spoon,0,NPC copy count (1)--1,1) do,begin
mob1:=npc reference (1,spoon)

      if ( get npc ID( npc at spot (pposx,pposy) ) == get npc ID(mob1 ) ) then (
         destroy npc (mob1)
         destroy npc (2)
         pposx := 99
         pposy := 99)

      end


      if (key is pressed(44)) then (
         if (npc copy count (2) == 0) then (
               posx := hero X (0)
               posy := hero Y (0)
               direction := hero direction (0)
               if (direction == up) then (
                  create npc (2,posx,(posy)+1)
                  wait for npc (2)
                  )
               if (direction == down) then (
                  create npc (2,posx,(posy)--1)
                  wait for npc (2)
                 )
               if (direction == left) then (
                  create npc (2,(posx)+1,(posy))
                  wait for npc (2)
                  )
               if (direction == right) then (
                  create npc (2,(posx)--1,(posy))
                  wait for npc (2)
                  )
            )
         )
pposx := npc X (2)
pposy := npc Y (2)
   wait (1)
   )
end



I also fixed up the attack part which hadn't been mentioned before your last post.

I'm kind of interested to see what you're doing with this script.
The wait for npc command and lack of a way to delete the npc after it's made if it misses the target intrigues me.
Liquid Metal King Slime
Send private message
 
 PostFri Jan 01, 2010 10:46 pm
Send private message Reply with quote
Oh, right, that WOULD happen.
This is actually because of the reduntacy I mentioned before.

You might have to use for statements after all.

And the other part is basically because to subtract you need 2 -'s. like this " -- " . Dunno, why you don't need 2 +'s but sure there's a reason.

So here's how it would go:

Code:


plotscript,game,begin

   playing := true
   while (playing) do(

variable (spoon)

for (spoon,0,NPC copy count (1)--1,1) do,begin
mob1:=npc reference (1,spoon)

      if (pposx == npx(mob1) ,and, pposy==npy(mob1) )  then (
         destroy npc (mob1)
         destroy npc (2)
        )

      end


      if (key is pressed(44)) then (
         if (npc copy count (2) == 0) then (
               posx := hero X (0)
               posy := hero Y (0)
               direction := hero direction (0)
               if (direction == up) then (
                  create npc (2,posx,(posy)+1)
                  wait for npc (2)
                  )
               if (direction == down) then (
                  create npc (2,posx,(posy)--1)
                  wait for npc (2)
                 )
               if (direction == left) then (
                  create npc (2,(posx)+1,(posy))
                  wait for npc (2)
                  )
               if (direction == right) then (
                  create npc (2,(posx)--1,(posy))
                  wait for npc (2)
                  )
            )
         )
pposx := npc X (2)
pposy := npc Y (2)
   wait (1)
   )
end



I also fixed up the attack part which hadn't been mentioned before your last post.

I'm kind of interested to see what you're doing with this script.
The wait for npc command and lack of a way to delete the npc after it's made if it misses the target intrigues me.\


EDIT: messed around with the script a little. Still haven't tested it though.
Liquid Metal Slime
Send private message
 
 PostSat Jan 02, 2010 5:32 am
Send private message Reply with quote
Thanks for the help. I had to change a couple of things but it works nicely. I'm hoping that after I get used to scripting for a while that I won't have to ask questions on so many things. I do appreciate the help though.

I'm getting close to have the entire script file working as intended, which means I can start working more on the actual game itself. I'm hoping that I will have a demo of it eventually.

However, I do have another problem at hand. Since I have the obstruction suspended and the collision script attached to the npc, it doesn't seem to work with the obstruction suspended since technically I cannot "step on" to activate it (which makes sense I guess).

Any ideas on a workaround for that? If you need a section of my script, let me know.
Cornbread Chemist
Liquid Metal King Slime
Send private message
 
 PostSat Jan 02, 2010 7:06 pm
Send private message Reply with quote
You might not need obstruction suspended at all. Try it without.
Liquid Metal Slime
Send private message
 
 PostSun Jan 03, 2010 3:04 am
Send private message Reply with quote
I did, and it does work. Only it works sporadically. Sometimes it will work, and sometimes it will not. Not sure what is up with that. In custom, the npc's are all the same except they all have different movement patterns. Here is the collision script itself:

Code:
plotscript,collision,begin
   health -= 1
   play sound (5,false,true)
   clear string (string:health)
   $1="Health: "
   append number (string:health, health)
   if (health == 0) then (game over)
end

Cornbread Chemist
Liquid Metal Slime
Send private message
 
 PostMon Jan 04, 2010 6:44 pm
Send private message Reply with quote
Figured it out. I'm not using it attached to an npc anymore and just running it from the script itself. Seems to be working fine so far.
Cornbread Chemist
Display posts from previous: