How do I make one, two, or three NPCs follow the hero?

From OHRRPGCE-Wiki
Jump to navigation Jump to search

This script will make certainly happy thousands of OHR programmers.(Note that if you intend to include in your game an Npc who fights with the heroes that this script is not for you.)

Another main thing to be aware of is that this system requieres advanced plotscripting knowledge. So oldies are more likely to use it the right way.

Here the way to follow. Go under custom.exe. On the map on which the screen will happen, choose an npc number on which picture set and a palette (It represents the Npc that is going to follow you)and KEEP THE NUMBER ON YOUR MIND AND/ OR A PIECE OF PAPER because you'll need it all the time .The npc is a basic Npc. It is not a vehicle, , it is usable repeatedly, it does not wanders and does not play a plotscript ((but you can choose to give it a plotscript before it joins).In that case use the "set tag(tag:my pet follows me,ON)" with a text box that says "I'm coming with you".(See above for further details)). Anyway, let's go on

In the following examples, I've chosen npc 0, but indeed you can choose whatever npc your want. Then you need to go into the tag menu and pick a FREE tag. Call him my pet (or my little brother is following me). Now edit the map on which you want the npc to wander and edit the npcs. Note that if you intend to keep the npc while several maps, you have to edit the npcs and each time give the correct appearance to NPC 0.

Leave the map menu and export names. Now we have finished with Custom, so you can leave and go back under Windows (or Linux if you're a linux user).

What you have to do now is to Launch hssed.exe or the note book and enter the following plotscripts


    Global variable (5, pet1moves)
    Global variable (6, pet2moves)


#--------------------------------------------------------
script,npc place, begin 
#Note that you shall not use a copy of an npc
#For this script I have chosen Npc 0 but it works with other numbers

if(checktag(tag:my pet follows me)==on, and, pet1moves==false)then, begin 

if (herodirection(me)==left)then,begin 
pet1moves:=true,
set npc position (0, herox+1, heroy) ,
set npc frame (0, 0),
wait for npc (0),
wait(2),
set npc frame (0, 1),
set npc direction (0, left),
pet1moves:=false

else,begin 
if (herodirection(me)==right)then,begin 
pet1moves:=true
set npc position (0, herox--1, heroy), 
set npc frame (0, 0),
wait for npc (0),
wait(2),
set npc frame (0, 1),
set npc direction (0, right),
pet1moves:=false


else,begin 
if (herodirection(me)==up) then, begin  
pet1moves:=true
set npc position (0, herox, heroy+1), 
set npc frame (0, 0),
wait for npc (0),
wait(2),
set npc frame (0, 1),
set npc direction (0, up),
pet1moves:=false


else,begin 
if (herodirection(me)==down)then,begin 
pet1moves:=true
set npc position (0, herox, heroy--1), 
set npc frame (0, 0),
wait for npc (0),
wait(2),
set npc frame (0, 1),
set npc direction (0, down),
pet1moves:=false

end 
end 
end 
end 

end #end of script
#--------------------------------------------------------


And then, this other plotscript, the keyispressed script

#--------------------------------------------------------
#This is an key is pressed script.
script, my pet goes with me, begin 

hero is walking (me)
#substitute this for the hero you want 
# note that you can use hero (0) instead hero(me)

hero direction (me) #=direction 
npcplace #(*,*,direction,*)

end


Save your file and compile your scripts. Now go back under custom.exe. Go to map you were before and edit the general map data. Go back until you find key is pressed script. Pick "My pet goes with me" as the key is pressed script. Then go on the text box menu and choose an text box that says that "your dog wants to go with you". Edit the conditional "always do the following" -> set tag 145=on (my pet follows me)

Now: What should you do to make an second or a third npc to follow you ? That's very simple! You just have to put command lines into npc place. Copy npc place and replace a) npc 0 by the second npc that is going to follow you (npc 5 for example) and 1 by 2 (except when one is in a "walk npc" command). Note also that you shall use another free tag.

Here is what you should obtain with this example

script,npc place, begin 


if(checktag(tag:my pet follows me)==on, and, pet1moves==false)then, begin 

if (herodirection(me)==left)then,begin 
pet1moves:=true,
set npc position (0, herox+1, heroy) ,
set npc frame (0, 0),
wait for npc (0),
wait(2),
set npc frame (0, 1),
set npc direction (0, left),
pet1moves:=false

else,begin 
if (herodirection(me)==right)then,begin 
pet1moves:=true
set npc position (0, herox--1, heroy), 
set npc frame (0, 0),
wait for npc (0),
wait(2),
set npc frame (0, 1),
set npc direction (0, right),
pet1moves:=false


else,begin 
if (herodirection(me)==up) then, begin  
pet1moves:=true
set npc position (0, herox, heroy+1), 
set npc frame (0, 0),
wait for npc (0),
wait(2),
set npc frame (0, 1),
set npc direction (0, up),
pet1moves:=false


else,begin 
if (herodirection(me)==down)then,begin 
pet1moves:=true
set npc position (0, herox, heroy--1), 
set npc frame (0, 0),
wait for npc (0),
wait(2),
set npc frame (0, 1),
set npc direction (0, down),
pet1moves:=false

end 
end 
end 
end 

#I have chosen Npc 5 as second npc 

if(checktag(tag:my other pet follows me)==on, and, pet2moves==false)then, begin 

if (herodirection(me)==left)then,begin 
pet2moves:=true,
set npc position (5,herox+2,heroy), 
set npc frame (5, 0),
wait(2),
set npc frame (5, 1),
set npc direction (5,left),
pet2moves:=false

else,begin 
if (herodirection(me)==right)then,begin 
pet2moves:=true,
set npc position (5,herox--2,heroy), 
set npc frame (5, 0),
wait(2),
set npc frame (5, 1),
set npc direction (5,right),
pet2moves:=false

else,begin 
if (herodirection(me)==up) then, begin  
pet2moves:=true,
set npc position (5,hero,heroy+2), 
set npc frame (5, 0),
wait(2),
set npc frame (5, 1),
set npc direction (5,up),
pet2moves:=false

else,begin 
if (herodirection(me)==down)then,begin 
pet2moves:=true,
set npc position (5,herox,heroy--2), 
set npc frame (5, 0),
wait(2),
set npc frame (5, 1),
# set npc frame is used to make fake walking
set npc direction (5,left),
pet2moves:=false

end 
end 
end 
end

end #end of plotscript
#--------------------------------------------------------


How does the script work ? Well that's rather easy: each time you make a move on a map and, if the tag have been activated previously the npc follows you even if you take a door (except in the door in question goes to a map that don't have a key is pressed script)

To be sure that your hero came along with his (her) pet or little brother during the game: put the key is pressed plotscript on each map the npc is supposed to follow you and be sure that npc (0) or npc (5) represents under all the maps the npcs that are supposed to follow you (in other terms that the NPC got the correct picture set and palettes .



How do I keep my npc pet with me when I take a door and go to a new map?

Well that's rather simple! We'll use 2 scripts. The global variable 8 allows us to make a while loop and get the npc pet back. Feel free to add command lines (or to create scripts and links them) if you want several npcs to follow you.


global variable (7, MyDirection)
global variable (8, put npc back)

-------------------------------------------------
plotscript autorunmap, none

while ((put npc back)==true) do, begin
putnpc back #launch the autonumber that place the npc on the new map
end

if (check tag(tag:my pet follows me)==ON) then, begin
suspend player
suspend npcs
create NPC (0, herox, heroy)
put npc back:= true
wait (1)
resume player
resume npcs

end, else, begin  # if tag is turned off== if the npc is not with you
create Npc (0, 2, 1) 
# npc turns invisible. Consult the article in the wiki of the hamster 
#republic if you have problems with this point.
alter NPC (0, Npcstat:picture, 0)
alter NPC (0, Npcstat:palette, 0)
wait for npc (0) 
# wait command RIGHT HERE is very important. Prevents
#Npc fom appearing on screen which is useful is you're near (x2,y 1)
#when the map is loaded

end #end of the if check tag


if (check tag(tag:my other pet follows me)==ON) then, begin
suspend player
suspend npcs
create NPC (5, herox, heroy)
put npc back:= true
wait (1)
resume player
resume npcs

end, else, begin  # if tag is turned off== if the  second npc is not with you

create Npc ((5, 2, 1) 
# npc turns invisible. Consult the article in the wiki of the hamster 
#republic if you have problems with this point.

alter NPC (5, Npcstat:picture, 0)
alter NPC (5, Npcstat:palette, 0)
wait for npc (5) 
# wait command RIGHT HERE is very important. Prevents
#Npc fom appearing on screen which is useful is you're near (x2,y 1)
#when the map is loaded

end #end of the if check tag

end #end of the plotscript
#-------------------------------------------------
script putnpc back, none

 if (check tag (tag:my pet follows me)==ON)  then, begin 
 suspend npcs
 suspend player
 set variable (MyDirect , hero direction (me))# On stock vers la où on va  
 
 if (MyDirection == left) then, begin
 create NPC (0, (hero X (0)+1),(hero Y (0)), MyDirection),
 put npc back:= false
 pet1moves:=false
 wait(1)
 resume npcs  
 resume player
 end, else,
 
 if (MyDirection == right) then, begin
 create NPC (0, (hero X (0)--1),(hero Y (0)), MyDirection),
 put npc back:= false
 pet1moves:=false
 wait(1)
 resume npcs
 resume player
 end, else,
 
 if (MyDirection == up) then, begin
 create NPC (0, (hero X (0)),(hero Y (0)+1),MyDirection), 
 put npc back:= false
 pet1moves:=false
 wait(1)
 resume npcs
 resume player
 end, else, 
 
 if (MyDirection == down) then, begin
 create NPC (0, (hero X (0)),(hero Y (0)--1),MyDirection),
 put npc back:= false
 pet1moves:=false
 wait(1)
 resume npcs
 resume player
 end  #end of the if directs 

# What follows s for the second npcs that follows you

 if (check tag (tag:my other pet follows me)== ON) then, begin 
 suspend npcs
 suspend player
 set variable (MyDirect , hero direction (me))# On stock vers la où on va  
 
 if (MyDirection == left) then, begin
 create NPC (5, (hero X (0)+1),(hero Y (0)), MyDirection),
 put npc back:= false
 pet2moves:=false
 wait(1)
 resume npcs  
 resume player
 end, else,
 
 if (MyDirection == right) then, begin
 create NPC (5, (hero X (0)--1),(hero Y (0)), MyDirection),
 put npc back:= false
 pet2moves:=false
 wait(1)
 resume npcs
 resume player
 end, else,
 
 if (MyDirection == up) then, begin
 create NPC (5, (hero X (0)),(hero Y (0)+1),MyDirection), 
 put npc back:= false
 pet2moves:=false
 wait(1)
 resume npcs
 resume player
 end, else, 
 
 if (MyDirection == down) then, begin
 create NPC (5, (hero X (0)),(hero Y (0)--1),MyDirection),
 put npc back:= false
 pet2moves:=false
 wait(1)
 resume npcs
 resume player
 end  #end of the if directs 

end #end of the plotscript 
-------------------------------------------------

To finish you may ask how do I prevent the npc from following me ?. Again that's rather simple, just turn the tag off with a text box or the set tag command. If you intend to use a teleport to map command, I recommend to complete it with a "set tag (tag:my pet follows me,OFF)" simple command line with a "put npc back:= false" so that you are use that custom won't make freeze the game by trying to put a npc on map whereas it's impossible because npcs (among other things) are (normally) suspended while cutescenes.

You will just have to turn on the tag when you want the npc to follow you again! Just be sure that you make the tag on again at the end of your plotscripts, so that your pet won't became invisible after the map (or a new map) (re)loads

If the first map is a map for which you want you pet npc able to follow you all along the game, you may need to use a tag to prevent the game from freezing during the intro. The tag needs to concerns both commands the while command and the if check tag. I've called the tag "pet not freeze intro" but you can choose any other name which can help you to remember what the tag is used for.



if (check tag(tag:pet not freeze intro)==ON) then, begin #use to prevent intro cutscenes from freezing

while ((put npc back)==true) do, begin
putnpc back #launch the autonumber that place the npc on the new map
end

if (check tag(tag:my pet follows me)==ON) then, begin
suspend player
suspend npcs
create NPC (0, herox, heroy)
put npc back:= true
wait (1)
resume player
resume npcs
end, else, begin  # if tag is turned off== if the npc is not with you
create Npc (0, 2, 1) 
# npc turns invisible. Consult the article in the wiki of the hamster 
#republic if you have problems with this point.
alter NPC (0, Npcstat:picture, 0)
alter NPC (0, Npcstat:palette, 0)
wait for npc (0) 
# wait command RIGHT HERE is very important. Prevents
#Npc fom appearing on screen which is useful is you're near (x2,y 1)
#when the map is loaded

end #end of the if check tag my pet follows me
end #end of the if check tag pet not freeze intro

Why do you need to do all that for the intro? Well simply because, you cannot yet act using the tag my pet follows me to prevent the while from beeing active.


Also be careful if you are have enabled the caterpillar command because it will create problems to calculate the distance the distance between the heroes and the Npc because the caterpillar party enables you to choose until 3 heroes and put them in you them in your active and make appear their grafics beside you. So it you have enabled the caterpillar party I recommand to replace 1 by 4 so that the Npc will appear just before the third hero. There will be like a hole when you have only 2 heroes with you. Moreover to highlight the fact that your pet (or your little brother) follows you I recommand not to use the caterpillar party and those plotscripts in the same time. I you want to use both caterpillar party and a npc that follows you be sure that heroes and locked at the end of each plotscript.