Do activated NPCs know 'who' they are?
Moderators: marionline, SDHawk
- marionline
- Metal Slime
- Posts: 673
- Joined: Sat Feb 26, 2011 9:23 pm
Do activated NPCs know 'who' they are?
I want to make NPCs that change theit look if used.
The command would be "Alter NPC (who,NPCstat:picture,picture number)", right?
How do I know what to write into the who field?
Would I have to write the same script a dozen times, eachtime with another variable depending on the NPC?
Or could the NPC activated tell me it's number automatically? Or is there another easier way
The command would be "Alter NPC (who,NPCstat:picture,picture number)", right?
How do I know what to write into the who field?
Would I have to write the same script a dozen times, eachtime with another variable depending on the NPC?
Or could the NPC activated tell me it's number automatically? Or is there another easier way
- SwordPlay
- Chemical Slime
- Posts: 966
- Joined: Sun Jan 22, 2017 9:32 am
- Location: London, England
- Contact:
yes, they can tell you automatically.
you need to add an argument after the name of your script, and it will be filled automatically with a reference to the NPC that triggered it.
If you want this script to branch depending on the NPC who triggered it, you should use SWITCH/CASE
http://hamsterrepublic.com/ohrrpgce/doc ... out-switch
for each "case" it will do something different (you can use whichever cases you need)
etc.,
You can use a second argument to automatically get the value in the NPC's script argument. You can find this next to where you set a script for an NPC
This argument "NPC" is not the NPC's ID, but the NPC unique reference (ID, copy number)
So if you use "Delete NPC(NPC)" or "Walk NPC(NPC,)" it will delete or walk only this NPC.
http://hamsterrepublic.com/ohrrpgce/doc ... creference
(but this command "alter NPC" changes all NPCs with the same ID, not just the one that triggered it)
you need to add an argument after the name of your script, and it will be filled automatically with a reference to the NPC that triggered it.
then you can use this argument "NPC" to refer to this NPC.plotscript, NPC change, NPC, begin
Alter NPC (NPC,NPCstat:picture,picture number)
end
If you want this script to branch depending on the NPC who triggered it, you should use SWITCH/CASE
http://hamsterrepublic.com/ohrrpgce/doc ... out-switch
so this will "switch" based on the NPC ID of "NPC"SWITCH(get NPC ID(NPC))do(
CASE(1)do( this will activate if the NPC ID is 1)
CASE(2)do( this will activate if the NPC ID is 2)
)
for each "case" it will do something different (you can use whichever cases you need)
etc.,
You can use a second argument to automatically get the value in the NPC's script argument. You can find this next to where you set a script for an NPC
Then you can use SWITCH/CASE and IF/THEN to do specific things for each NPC and argumentplotscript, change NPC, NPC, ARG, begin
This argument "NPC" is not the NPC's ID, but the NPC unique reference (ID, copy number)
So if you use "Delete NPC(NPC)" or "Walk NPC(NPC,)" it will delete or walk only this NPC.
http://hamsterrepublic.com/ohrrpgce/doc ... creference
(but this command "alter NPC" changes all NPCs with the same ID, not just the one that triggered it)
Last edited by SwordPlay on Thu Feb 08, 2018 1:17 am, edited 22 times in total.
I could be wrong, but I think the first argument in a script called from a NPC is the script argument defined in Edit NPCs, and the second argument is the NPC reference.
So just put in an argument like "arg" for the first argument and don't use it (although you could), then make use of the second argument which will be the NPC reference.
So just put in an argument like "arg" for the first argument and don't use it (although you could), then make use of the second argument which will be the NPC reference.
Bit of a loaded answer here for a loaded question; I'm not too sure how to start answering this so here we go.
Long answer, still no but we can "fake it." An NPC in OHR or in any game in a very general sense is just a collection of data. Sprite Picture, pallet, movement behavior... etc all of this is just data, numbers that are in an index. Think of the way it behaves as a free no strings attached vending machine.
Yes that's correct, now you just need to create a plotscript for it, set the event for it to activate, test for a variety of situations and improve as necessary.
This is important to know. Because each instance of an NPC you create is different. Let's say you create data for sheep NPCs. You plop down 18 of them and a herder, why not? So that's 19 NPCs on one map.
Now the sheep are all created from the same data. And right now the herder only has one of them on the map. Within OHR it would look something like this.
For NPC data OHR starts counting at zero. Idky, blame Bob. Column A is just for visualization aid it would actually be 0 for sheep & 1 for person, column B is the NPC number, column C is the NPC copy.
This is what you need to consider when it comes to identifying which NPC you want reference. It's also things like these that make programming [s]FUN![/s] interesting.
Especially for something like the "Alter NPC" command. That command alters the data for all NPCs that were created from that data. Meaning it would change all copies of that NPC type.
If I wanted one sheep to turn into a hamster by altering it's sprite, all of the sheep copies would change into hamsters.
So to finally answer your question, it depends where and how that data is stored. And it also depends on what you want the outcome to be.
Anyway, that's a very simple example of a function. And it's always better to create functions. If created properly they can automate and have you doing less work. You just need to consider exactly what it is you need to do then have at it. If you don't know how to start this... well
If you want to learn to code, hspeak is an O.K. place to start with. Your best bet however would be start smaller and learn the basics about programming and computers (*NOTE: Now that I'm proofreading this, I don't know how much you actually know about programming! If you actually know how to and if I'm coming off as condescending, sorry!) At the end of the day, programming really just boils down to problem solving. How do I make X do Y?
There are a few places to start that I would suggest...
- Khan Academy
-Crash Course: Computer Science
An Intro to Programming class at your local Community College
"NPC reference (ID, copy)"
"get NPC ID (reference)"
"NPC copy count (ID)"
Short answer, no.marionline wrote:Do activated NPCs know 'who' they are?
Long answer, still no but we can "fake it." An NPC in OHR or in any game in a very general sense is just a collection of data. Sprite Picture, pallet, movement behavior... etc all of this is just data, numbers that are in an index. Think of the way it behaves as a free no strings attached vending machine.
- 1. You push a button on the machine because you're hungry = (You want an NPC in your game to do X)
2. You push in the code to select an item = (You create the NPC data by inputting it into the NPC menu)
3. The machine uses the code to select some chips from X row, Y column = (OHR stores the data to use whenever you call it, i.e. you place an NPC in map 1)
4. The machine gives you your chips! = (When you load your game, the NPC's data is outputted how you designed it!)
I haven't touched anything in the NPC library so make of that what you will. But luckily for us the OHR team have spent over two decades to get us to this point but anyway! I digress...marionline wrote:I want to make NPCs that change theit[sic] look if used.
The command would be "Alter NPC (who,NPCstat:picture,picture number)", right?
Yes that's correct, now you just need to create a plotscript for it, set the event for it to activate, test for a variety of situations and improve as necessary.
I'm assuming that you can have >32767 different types of NPCs in your map data. But... the limitations on OHR will only let you have 300 NPCS on the map at once.marionline wrote:How do I know what to write into the who field?
This is important to know. Because each instance of an NPC you create is different. Let's say you create data for sheep NPCs. You plop down 18 of them and a herder, why not? So that's 19 NPCs on one map.
Now the sheep are all created from the same data. And right now the herder only has one of them on the map. Within OHR it would look something like this.
Code: Select all
Sheep 0, 0
Sheep 1, 1
Sheep 2, 2
Sheep 3, 3
Sheep 4, 4
Sheep 5, 5
Sheep 6, 6
Sheep 7, 7
Sheep 8, 8
Sheep 9, 9
Sheep 10, 10
Sheep 11, 11
Sheep 12, 12
Sheep 13, 13
Sheep 14, 14
Sheep 15, 15
Sheep 16, 16
Sheep 17, 17
Sheep 18, 18
Person 19, 0
This is what you need to consider when it comes to identifying which NPC you want reference. It's also things like these that make programming [s]FUN![/s] interesting.
Especially for something like the "Alter NPC" command. That command alters the data for all NPCs that were created from that data. Meaning it would change all copies of that NPC type.
If I wanted one sheep to turn into a hamster by altering it's sprite, all of the sheep copies would change into hamsters.
So to finally answer your question, it depends where and how that data is stored. And it also depends on what you want the outcome to be.
Now this is where I'm going to get a bit complicated. What you're getting at is called a function. In programming a function is code that creates a specific output everytime with whatever is inputted into it.marionline wrote:Would I have to write the same script a dozen times, eachtime with another variable depending on the NPC?
Code: Select all
# Psuedo code, none of this would work on anything
# I want to send a message to Alice for her birthday!
# So I make this!
# "say:" will write in big letters on the monitor
# whatever it is that's typed after that command
my code, begin
say : Happy Birthday to you
say : Happy Birthday to you
say : Happy Birthday to Alice!
say : Happy Birthday to you
end
# Now I want to say happy birthday to Bob!
# So I send him this!
my code for Bob, begin
say : Happy Birthday to you
say : Happy Birthday to you
say : Happy Birthday to Bob!
say : Happy Birthday to you
end
# Now Carl and David, and Ester and now Flippy wants one,
# that's too much work for me. How about I write this?
# Instead of writing their name, I'm going to have
# that piece of information remain as a "blank"
# with "Person" acting as that "blank"
my function, (Person), begin
say : Happy Birthday to you
say : Happy Birthday to you
say : Happy Birthday to (Person)
say : Happy Birthday to you
end
# Now this is my next code that will call that
# function in order to automate this.
# "TYPE SOMETHING" is a command that waits for me to
# type something on my keyboard then it waits for me to
# press enter and finally it moves onto the next line of code.
# In this case, it will store the result of that input as data inside "X".
# "send to" is a command that sends the results of my
# code to a person from my email contact list
message, begin
variable [X] = (TYPE SOMETHING)
# I type Carl
# X is stores the name Carl and it is
# inserted into where "Person" was written
# in "my function"
# Then it sends the results to Carl and ends
run (my function (X))
send to (X)
end
# The results for that are
Happy Birthday to you
Happy Birthday to you
Happy Birthday to Carl!
Happy Birthday to you
# And all I had to do was type something in instead
# of creating a new version of my code! SWEEEET!
# And now I do this for everyone from C-Z
If you want to learn to code, hspeak is an O.K. place to start with. Your best bet however would be start smaller and learn the basics about programming and computers (*NOTE: Now that I'm proofreading this, I don't know how much you actually know about programming! If you actually know how to and if I'm coming off as condescending, sorry!) At the end of the day, programming really just boils down to problem solving. How do I make X do Y?
There are a few places to start that I would suggest...
- Khan Academy
-Crash Course: Computer Science
An Intro to Programming class at your local Community College
Yes there's a few commands that already do that. But they each return a different number.marionline wrote:Or could the NPC activated tell me it's number automatically? Or is there another easier way
"NPC reference (ID, copy)"
"get NPC ID (reference)"
"NPC copy count (ID)"
Last edited by KutKu on Thu Feb 08, 2018 6:19 am, edited 5 times in total.
@KutKu, while your enthusiasm is appreciated, a lot of what you posted was misinformative. There is in fact a specific and documented way to achieve what the original poster was trying to do.
So anyways, I'm going to get more specific and in-depth with a simple example of activating an NPC and changing its appearance.
Do note that the "alter NPC" command changes settings for all copies of that NPC, not just the copy in question. So if you're going to work with multiple NPCs that do the same thing, alter NPC is not a good approach, because using one NPC will change all the other copies, which is probably not desired behavior.
Here, you just manage the picture you want the NPC to change to inside the Edit NPCs menu in the map editor, that way you don't have to hard code a specific sprite set into your .HSS file.
So let's say you have a NPC that uses walkabout set 1 by default, and you want it to change to walkabout set 2 after activated. Just have the NPC use the above script, and set its script argument to 2. Easy peasy.
So anyways, I'm going to get more specific and in-depth with a simple example of activating an NPC and changing its appearance.
Do note that the "alter NPC" command changes settings for all copies of that NPC, not just the copy in question. So if you're going to work with multiple NPCs that do the same thing, alter NPC is not a good approach, because using one NPC will change all the other copies, which is probably not desired behavior.
Code: Select all
plotscript, change npc graphic, arg, ref, begin
## Set the NPC's argument in Edit NPCs to the
## walkabout set that you'd like it to change to.
alter npc (ref, NPCstat:picture, arg)
end
So let's say you have a NPC that uses walkabout set 1 by default, and you want it to change to walkabout set 2 after activated. Just have the NPC use the above script, and set its script argument to 2. Easy peasy.
Last edited by Foxley on Thu Feb 08, 2018 7:20 pm, edited 1 time in total.
- Bob the Hamster
- Lord of the Slimes
- Posts: 7658
- Joined: Tue Oct 16, 2007 2:34 pm
- Location: Hamster Republic (Ontario Enclave)
- Contact:
Another cool way to change an NPC's appearance is with the "change NPC ID" command. Given an NPC reference, you make that NPC become a different NPC
That also means that the NPC's text box, script trigger, movement type, they all change too, which may or may not be what you want, depending on your goal.
That also means that the NPC's text box, script trigger, movement type, they all change too, which may or may not be what you want, depending on your goal.
- marionline
- Metal Slime
- Posts: 673
- Joined: Sat Feb 26, 2011 9:23 pm
Thank you very much for your answers and hints!
I think I can make something useful from all of you posts.
And my script for opening doors and walking throug works!
Still, the switch case script to choose the door to open does not seem to work.
Can you help me spot my mistake?
I think I can make something useful from all of you posts.
And my script for opening doors and walking throug works!
Still, the switch case script to choose the door to open does not seem to work.
Can you help me spot my mistake?
Code: Select all
plotscript, open_air_lock, arg, door_number, begin,
# arg is npc agument, not used
# door_number is the npc number in the map npc's editor
show text box (9) # for testing, works
wait for text box
switch(door_number) do (
case(109, 110, 111, 112, 113) do
# seems not to be triggred, why?
(open_air_lock_north(arg, door_number))
case(115, 116, 122) do
(open_air_lock_east(arg, door_number))
case(114, 117, 123) do
(open_air_lock_west(arg, door_number))
case(118, 119, 120, 121) do
(open_air_lock_both_ways(arg, door_number))
)
end
plotscript, open_air_lock_north, arg, door_number, begin,
suspend player
variable (picture_number, door_x, door_y)
picture_number := read NPC (door_number, NPCstat:picture)
door_x := NPC X (door_number)
door_y := NPC Y (door_number)
# open door
Alter NPC (door_number, NPCstat:picture, picture_number)
wait(5)
Alter NPC (door_number, NPCstat:picture, picture_number + 1)
wait(5)
Alter NPC (door_number, NPCstat:picture, picture_number + 2)
# make wall walkabel
write pass block (door_x, door_y, 0) #0 makes walkabel
# walk through door
# walk hero (me, north, 3)
# wait for hero
# no walking on/through NPCs !? :-(
set hero position (me, door_x, door_y)
set hero position (me, door_x, door_y --1)
# close door
wait(5)
Alter NPC (door_number, NPCstat:picture, picture_number + 1)
wait(5)
Alter NPC (door_number, NPCstat:picture, picture_number)
# make unwalkabel, though I guess NPC just blocking the way is good too.
# write pass block(door_x ,door_y, south)
resume player
end
Last edited by marionline on Thu Feb 08, 2018 9:14 pm, edited 1 time in total.
- Bob the Hamster
- Lord of the Slimes
- Posts: 7658
- Joined: Tue Oct 16, 2007 2:34 pm
- Location: Hamster Republic (Ontario Enclave)
- Contact:
Code: Select all
# door_number is the npc number in the map npc's editor
If you want to get the npc number in the npc editor, you can fetch it with the "get npc id" command. Try the following:
Code: Select all
plotscript, open_air_lock, arg, ref, begin,
# arg is npc agument, not used
# ref is the npc reference.
variable(door_number) # the npc number in the map npc's editor
door_number := get npc id(ref)
show text box (9) # for testing, works
wait for text box
switch(door_number) do (
case(109, 110, 111, 112, 113) do
# This should work now! :)
(open_air_lock_north(arg, door_number))
- Bob the Hamster
- Lord of the Slimes
- Posts: 7658
- Joined: Tue Oct 16, 2007 2:34 pm
- Location: Hamster Republic (Ontario Enclave)
- Contact:
Oh, also, since open_air_lock_north and similar scripts never use "arg" you can leave it out completely.
The unused "arg" is required for a script that is triggered by activating an NPC. You don't need it for any other scripts.
Code: Select all
(open_air_lock_north(door_number))
Code: Select all
plotscript, open_air_lock_north, door_number, begin,
The unused "arg" is required for a script that is triggered by activating an NPC. You don't need it for any other scripts.