 |
Castle Paradox
|
View previous topic :: View next topic |
Author |
Message |
October's Cry

Joined: 06 Jan 2007 Posts: 16
|
Posted: Sat Jan 06, 2007 7:46 pm Post subject: Lockpicking? |
|
|
Alright... I'm new here, not too new to OHR. But, none the less... This may be a little hard, especially for a newbie like me, but, I am trying to figure out a way to create a lockpicking effect. What I mean is. If you have a pick, you can open almost any lock... BUT, it would be randomized that you may or may not open it, and if you don't there can be a chance of being caught, and you will loose your pick, whether you are caught or not.
I started trying this with text boxes, and found it to be a little long, considering I would be creating a new text box for each door, and each part in the process. Is there a way to simplify this in script?
Thanx. |
|
Back to top |
|
 |
Newbie_Power

Joined: 04 Sep 2006 Posts: 1762
|
Posted: Sun Jan 07, 2007 2:10 am Post subject: |
|
|
I would attach the script to an NPC rather than a textbox, and the script can have textboxes if you want. The NPC would look like a door, and if you open the lock, the door would "turn" a different direction, and the NPC can be walked over.
You could do a mini-game where you have to line up three numbers in order to open said lock via a slot-machine type ordeal. The numbers would be displayed on the screen (I forgot what function you are supposed to use here.) |
|
Back to top |
|
 |
October's Cry

Joined: 06 Jan 2007 Posts: 16
|
Posted: Sun Jan 07, 2007 6:25 am Post subject: scripting errors... |
|
|
Thanx, good idea, but, my problem is that I'm not too good with scripting, so, I have no clue how to do such a thing. The script i tried won't compile, too many errors... not too good with if statments... if anyone knows how to put it in script, easy enough for me to figure out... that'll be GREAT.... |
|
Back to top |
|
 |
msw188
Joined: 02 Jul 2003 Posts: 1041
|
Posted: Sun Jan 07, 2007 4:19 pm Post subject: |
|
|
In order to do something like this (indeed, to do almost anything script-wise) you HAVE to get comfortable with 'if' statements. They always look like the following:
Code: | if ( 'something true/false' ) , then
begin
stuff #things you want to happen if the
stuff #'something true/false' is true
end
else
begin
other stuff #things you want to happen if the
other stuff #'something true/false' is false
end |
By 'something true/false', I mean something that the computer can recognize as true or false. Examples include:
Code: | if (Hero X (me) == 4) | This checks whether or not the leader of the heroes' main party is standing on a tile with an x-coordinate of four.
This checks whether or not tag 6 if turned on.
All the rest of that stuff (the commas, the words "then", "begin" and "end", where to hit enter) are important too for the computer to know what it is that it is supposed to do. The part with the word "else" is optional. You only need it if you want something to happen when the 'something true/false' turns out false.
For your specific problem involving the lockpicking, we'll need something like the following:
Code: | variable(x,Pick%,Caught%) #declare variables to be used in this script
x:=random(1,100) #set variable x randomly between 1 and 100
Pick%:=75 #make this number the percentage chance
#that you successfully pick the lock
#I am assuming a 75% chance of picking
Caught%:=20 #make this number the percentage chance
#that you are caught if the pick fails
#I am assuming a 20% chance of getting caught
#Here comes the if check to see whether or not you pick the lock
if (x<=Pick%), then
begin
#Do whatever happens if you pick the lock
#Probably you will want to destroy the npc that looked like the door
end
else
begin
#Here is where we put the events when x<=75 was false
#Thus, this is where we lose the pick, and check if we are caught
delete item (item:pick) #do you understand how to refer to your items?
x:=random(1,100) #redo because we are doing a new percentage
if (x<=Caught%), then
begin
#Do whatever happens if you are caught
end
end #this end is the end of the entire 'else' set |
Is that understandable? I tried to put plenty of comments to make it clear what was going on. If you have any more questions, don't hesitate to ask. I typed this twice because I accidentally left the site the first time. I hope that I didn't forget anything. _________________ My first completed OHR game, Tales of the New World:
http://castleparadox.com/gamelist-display.php?game=161
This website link is for my funk/rock band, Euphonic Brew:
www.euphonicbrew.com |
|
Back to top |
|
 |
October's Cry

Joined: 06 Jan 2007 Posts: 16
|
Posted: Sun Jan 07, 2007 8:03 pm Post subject: |
|
|
cool, that makes a lot more sense of things now... thanx.... |
|
Back to top |
|
 |
October's Cry

Joined: 06 Jan 2007 Posts: 16
|
Posted: Tue Jan 09, 2007 8:07 pm Post subject: still having issues.... UGGH! |
|
|
OK, for the most part... it works... but, sometimes it will run one script after the other... instead of just one, then end it.... thus, you may pick the lock fine, then you try again, and lose your pick or even get caught.... here's my script...
#-----------------------------------------------------------------#
define script (1,lock gartown1,none)
define script (2,lock gartown2,none) #I have like 6 in this one town which are identical copies of the script below, with slight variations.
#-----------------------------------------------------------------#
script, lock gartown1, begin
variable (x,pick%,caught%)
x:=random(1,100)
pick%:=95 #These #'s vary depending on each individual script and lock
caught%:=85
show text box (1) #Tells the door is locked
wait for text box
if (check tag (tag: lock pick)==ON) #Checks to see if pick is in inventory
then(
show text box (2) #Gives choice to pick or not
wait for text box
wait (5)
if (check tag (tag: Gartown Lock)==ON) #Tag set from option to pick
then(
if (x>=pick%) then(
suspend player
set hero direction (1,east)
wait for hero
wait (5)
set hero direction (1,west)
wait for hero
wait (5)
set hero direction (1,south)
wait for hero
wait (5)
set hero direction (1,north)
wait for hero
wait (5)
set hero picture (me, 0, outside battle) #Changes Appearance of hero for accuracy
wait for hero
wait (10)
set hero picture (me, 2, outside battle) #Changes it back
wait for hero
resume player
destroy NPC (0) #this varies depending on each door
set tag (tag: Gartown Lock, OFF) #Sets tag OFF so as to save on having a tag for EACH lock
show text box (3) #Says you picked the lock
wait for text box
)
x:=random(1,100)
if (x<=caught%) then(
suspend player
set hero direction (1,east)
wait for hero
wait (5)
set hero direction (1,west)
wait for hero
wait (5)
set hero direction (1,south)
wait for hero
wait (5)
set hero direction (1,north)
wait for hero
wait (5)
set hero picture (me, 0, outside battle)
wait for hero
wait (10)
set hero picture (me, 2, outside battle)
wait for hero
delete item (item:pick)
resume player
set tag (tag: Gartown Lock, OFF) #Again sets tag OFF
show text box (5) #Guard Catching you... will try to find a way to make NPC run to your position
wait for text box
)
else
begin
suspend player
set hero direction (1,east)
wait for hero
wait (5)
set hero direction (1,west)
wait for hero
wait (5)
set hero direction (1,south)
wait for hero
wait (5)
set hero direction (1,north)
wait for hero
wait (5)
set hero picture (me, 0, outside battle)
wait for hero
wait (10)
set hero picture (me, 2, outside battle)
wait for hero
delete item (item:pick)
resume player
set tag (tag: Gartown Lock, OFF) #Same as before
show text box (7) #Says you lost your pick
wait for text box
)
)
)
end
#----------------------------------------------#
PLEASE HELP!.... this is so annoying now... lol |
|
Back to top |
|
 |
msw188
Joined: 02 Jul 2003 Posts: 1041
|
Posted: Wed Jan 10, 2007 8:53 am Post subject: |
|
|
I'm pretty sure the problem is a missing 'else'. Right now, your script looks like this:
if (pick is successful),then
(
open door
)
if (caught),then
(
caught
)
else
(
lose pick
)
The problem is that right now, the if(caught) check runs regardless of whether you pick the door or now, and furthermore, you only lose your pick if you are not caught. The script should look like this:
if (pick is successful),then
(
open door
)
else
(
lose pick
if (caught),then
(
caught
)
) #this is the end of the else
There's also another problem: one of your checks are backwards. That is to say, if the variable pick% is your chances of succesfully picking the lock, then the correct way to check that is the ask if x<=pick% (ie, a random number from 1 to 100 has a 95% chance of being less than or equal to 95). Right now you have x>=pick%.
There is a way to compress all of these slightly different cases into one script that can be used anywhere (which would be especially useful if you plan on having the hero able to attempt to pick locks throughout the game). This would require the use of arguments in your script (to allow for the slight variations). If you would like to learn about this, just ask. We will only have to change a couple of things. _________________ My first completed OHR game, Tales of the New World:
http://castleparadox.com/gamelist-display.php?game=161
This website link is for my funk/rock band, Euphonic Brew:
www.euphonicbrew.com |
|
Back to top |
|
 |
October's Cry

Joined: 06 Jan 2007 Posts: 16
|
Posted: Wed Jan 10, 2007 6:17 pm Post subject: arguements.... hmmm, sure |
|
|
YES, I would LOVE to set it up with arguments, if i knew a little more of how... cause, i plan on using this probably 20 times per map... depending on treasure chests, boxes, doors... etc... thanx again... |
|
Back to top |
|
 |
msw188
Joined: 02 Jul 2003 Posts: 1041
|
Posted: Thu Jan 11, 2007 8:41 am Post subject: |
|
|
Okay, here we go.
ARGUMENTS IN GENERAL:
An argument is a number that a script receives from whatever it is that called the script. But in order to do anything with these numbers it is receiving, it needs to know that it is expecting them and it needs to give them names. The first part is done when you are defining the script at the top of your text file:
Code: | define script (1, Script Name, 3, 0, 0, 2) |
The number after the script name is the number of arguments that the script should expect to receive (the above example script would expect to receive three arguments whenever it is called). The numbers AFTER that are, in order, what the script should assume if the arguments are NOT sent to it. The example script above would assume, in the event that it is called without arguments being sent to it, that the first and second argument are zero, and the third argument is a two. These default values can be useful for error checking (ie, making sure that arguments were sent).
The second part is done at the beginning of the script in question. You name the incoming arguments like naming variables:
Code: | script, Script Name, arg1 name, arg2 name, begin |
Here, the first argument that is sent can be referred to in the rest of the script by the name "arg1 name", and the second will be referred to as "arg2 name". It will be easier to see, I think, when we get to our lockpicking script.
SCRIPT ARGUMENTS FROM NPCS:
Our lockpicking script is going to be called from NPCs (NOT textboxes; make sure the script is designed to be called directly from the NPC, not from a textbox that the NPC is linked to). All NPCs in custom are hard-wired to send two arguments automatically to any script that they call. The first argument it sends can be set by the game-maker in custom. You type in the number that you want this NPC to send as an argument in the 'Edit NPCs' menu in the Map Editor. The second argument that the NPC sends is a special number called an NPC reference. This number uniquely identifies which NPC called the script. If the script does not expect these arguments, then they are thrown away. We will make a script that expects and uses both of these arguments.
LOCKPICKING SCRIPT:
Here is my plan. The lockpicking script (I'm going to name it "LockPick") will receive two arguments from the NPC. The first one will be called "Percentages". It will be a four digit number that we can assign to any NPC in custom that will call this script. We type the number in custom so that the first two digits are always the Pick% and the second two digits are always the Caught%. For an NPC that has a 95% chance of being picked, and a 75% chance of having you caught, we'd type 9575 into the script argument slot in the 'Edit NPC' menu in the Map Editor. We have to be careful with one digit percentages. If the chance of being caught is, say, only 5%, and the chance of picking is 91%, the number would be 9105. If the pick percentage is only one digit, we can ignore the opening zero, so our number will only be three digits. If this is not clear, be sure to ask.
The second argument is the reference to the NPC. We will use this so the script knows which NPC to destroy in the event that the player successfully picks the lock. I'll call this argument "Which". Now the script:
Code: | define script (1, LockPick, 2, 0, 0)
#No real use for default values here I'm thinking
script, LockPick, Percentages, Which, begin
variable(x, pick%, caught%)
#Here is where we split the four digit Percentages
#into the pick and caught %'s. If you don't
#understand, feel free to ask how this is working.
caught%:=(Percentages,mod,100)
pick%:=( (Percentages--caught%)/100 )
|
From here the code is exactly the same, except that anywhere you have a destroy npc (#) command, you replace the specific number with the word "Which":
Destroy NPC (0) -> Destroy NPC (Which)
So that the script destroys whatever NPC called it.
Okay, that was quite a lot. Try to take it all in, but if anything is confusing don't hesitate to ask. _________________ My first completed OHR game, Tales of the New World:
http://castleparadox.com/gamelist-display.php?game=161
This website link is for my funk/rock band, Euphonic Brew:
www.euphonicbrew.com |
|
Back to top |
|
 |
msw188
Joined: 02 Jul 2003 Posts: 1041
|
Posted: Fri Jan 12, 2007 12:46 pm Post subject: |
|
|
Wait, I just thought of a problem with my script. As written, it is impossible to have a 100% chance of picking or being caught. The simplest fix I can think of would be to replace the random(1,100)'s with
x:=random(1,99)
This way 99 means 100% actually, and the other numbers will be a little off percent-wise, but I can't imagine it being enough to make any difference. Of course, 00 will still mean 0%. _________________ My first completed OHR game, Tales of the New World:
http://castleparadox.com/gamelist-display.php?game=161
This website link is for my funk/rock band, Euphonic Brew:
www.euphonicbrew.com |
|
Back to top |
|
 |
October's Cry

Joined: 06 Jan 2007 Posts: 16
|
Posted: Sat Jan 13, 2007 7:26 am Post subject: still problem... AHHHH |
|
|
ok, i still have an issue with it running one after the other.... i modified mine slightly, hoping it would work... because it was just that it would run lose lock pick, then maybe it would run the get caught maybe not... so i modified it for this instance and it worked..... but, now it seems to like to run it so that may happen, OR it'll run it so you successfully open it, then it runs get caught.... i'm so baffled, it's rediculous how this could be having so many issues over something which seems like it's just a matter of destroying a NPC if a random number is between X and y. Frustration so much.... i almost just want to leave it as is... lol _________________ check out my bands at....
Doom Metal at www.soundclick.com/octoberscry
Progressive metal at www.soundclick.com/outercharm
You know you want to..... i'll be redoing october's cry songs soon. |
|
Back to top |
|
 |
msw188
Joined: 02 Jul 2003 Posts: 1041
|
Posted: Sun Jan 14, 2007 2:52 am Post subject: |
|
|
I'm sorry October's Cry, but I am honestly having trouble understanding what you are saying. Less pronouns and more complete sentences would help I think, but best of all would be a posting of the entire script in question. _________________ My first completed OHR game, Tales of the New World:
http://castleparadox.com/gamelist-display.php?game=161
This website link is for my funk/rock band, Euphonic Brew:
www.euphonicbrew.com |
|
Back to top |
|
 |
October's Cry

Joined: 06 Jan 2007 Posts: 16
|
Posted: Sun Jan 14, 2007 7:14 am Post subject: |
|
|
sorry about all that stuff.... should of thought of what i was saying first... lol, so here's the complete script...
Code: |
#-------------------------------------------------#
define script (1,lockpick,2,0,0)
define script (2,fight guard,none)
#-------------------------------------------------#
global variable (1,evil)
#-------------------------------------------------#
script, lockpick,percentages,which, begin
variable (x,pick%,caught%)
x:=random(1,99)
pick%:=(Percentages,mod,100)
caught%:=((Percentages--caught%)/100)
show text box (1) #Tells the door is locked
wait for text box
if (check tag (tag: lock pick)==ON) #Checks to see if pick is in inventory
then(
show text box (2) #Gives choice to pick or not
wait for text box
wait (5)
if (check tag (tag: Gartown Lock)==ON) #Tag set from option to pick
then(
(evil-=1)
if (x<=pick%) then(
suspend player
set hero direction (me,east)
wait for hero
wait (8)
set hero direction (me,west)
wait for hero
wait (8)
set hero direction (me,south)
wait for hero
wait (8)
set hero direction (me,north)
wait for hero
wait (8)
set hero picture (me, 0, outside battle)
wait for hero
wait (10)
set hero picture (me, 2, outside battle)
wait for hero
resume player
destroy NPC (which)
set tag (tag: Gartown Lock, OFF) #Sets tag OFF so as to save on having a tag for EACH lock
show text box (3) #Says you picked the lock
wait for text box
)
else
begin
(evil-=1)
suspend player
set hero direction (me,east)
wait for hero
wait (5)
set hero direction (me,west)
wait for hero
wait (5)
set hero direction (me,south)
wait for hero
wait (5)
set hero direction (me,north)
wait for hero
wait (5)
set hero picture (me, 0, outside battle)
wait for hero
wait (10)
set hero picture (me, 2, outside battle)
wait for hero
delete item (item:pick)
resume player
set tag (tag: Gartown Lock, OFF) #Same as before
show text box (7) #Says you lost your pick
wait for text box
end
x:=random(1,99)
if (x<=caught%) then(
set tag (tag: Gartown Lock, OFF) #Again sets tag OFF
show text box (5) #Guard Catching you... will try to find a way to make NPC run to your position
wait for text box
show text box (6) #runs fight guard script....
wait for text box
)
)
)
end
#----------------------------------------------------------#
script, fight guard, begin
if (check tag (tag:fight guard)==ON)
then(
fight formation (1)
set tag (tag:fight guard, OFF)
show text box (15)
wait for text box
else(
increment good
end
end
end
|
_________________ check out my bands at....
Doom Metal at www.soundclick.com/octoberscry
Progressive metal at www.soundclick.com/outercharm
You know you want to..... i'll be redoing october's cry songs soon. |
|
Back to top |
|
 |
TMC On the Verge of Insanity
Joined: 05 Apr 2003 Posts: 3240 Location: Matakana
|
Posted: Sun Jan 14, 2007 4:32 pm Post subject: |
|
|
After a very quick scan over it:
Code: | pick%:=(Percentages,mod,100)
caught%:=((Percentages--caught%)/100) |
This isn't right. I can't really follow, but do you want pick% and caught% to add to 100? If so, you probably want something like this:
Code: | if (percentages>>100) then (pick%:=100) else (pick%:=percentages)
caught%:=(100--pick%) |
Also, you should clean up your script. Indent it correctly. A script with random indentation like yours is much harder to understand, and makes people not want to read it. There might be some very obvious mistakes hidden in there. _________________ "It is so great it is insanely great." |
|
Back to top |
|
 |
msw188
Joined: 02 Jul 2003 Posts: 1041
|
Posted: Sun Jan 14, 2007 7:34 pm Post subject: |
|
|
To the Mad Cacti: See my LockPick script above. The pick percentage and caught percentage come from a four digit argument passed from custom.
To October's Cry: The first problem (the one the Mad Cacti picked up on) is that you have the percentages backwards. It should be:
CAUGHT%:=(Percentages,mod,100)
PICK%:=((Percentages--caught%)/100)
As far as your script doing things wrong, my first suggestions would be to have one 'suspend player' command at the beginning and one 'resume player' command at the end to prevent the player from calling the script multiple times before it has a chance to work itself out. I must admit that I haven't done the thorough read of your script yet, and I have to get going now, but it would be very helpful if you follow The Mad Cacti's advice and indent the script properly. If you are not familiar with this, the usual indentation scheme is basically that you indent two spaces before and after every 'begin' you use [or '(', as you seem to be using for the if blocks], excepting the first. This way, you will be able to keep track easily of what commands belong to what if, and where exactly the end of an if block is. Example:
Code: | script,Yay,begin
#blah blah
#Yay!
if(something),then
begin
show text box(Yay)
wait for text box
end
else
begin
if(something else),then
begin
destroy hero (Yay)
#Eat some dinner
end
if(another something else),then
begin
create NPC (Yay)
end
end
end |
_________________ My first completed OHR game, Tales of the New World:
http://castleparadox.com/gamelist-display.php?game=161
This website link is for my funk/rock band, Euphonic Brew:
www.euphonicbrew.com |
|
Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|