Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need script help asap! extremely difficult script!
DnALANGE Offline
Banned

Posts: 1,549
Threads: 73
Joined: Jan 2012
#9
RE: Need script help asap! extremely difficult script!

(12-19-2012, 07:00 PM)TheGreatCthulhu Wrote: The "a b c things" are not script, it's just me trying to explain to you what to do on a conceptual level.

Here, I made you an example: there's a single map and a relatively short hps script - just unpack to the custom_stories folder. It demonstrates how to do a pass code. Since you said you're using script areas, I made a similar setup. For simplicity, the pass code has only 3 digits. There's a door, and a... eh... console of sorts xD, which enables you to enter the password. The password is set in the example.hps script file, and it's currently 231 - but you can change that.

Here's the most important part of the script:
PHP Code: (Select All)
const int INVALID_VALUE = -1;   // represents some invalid value, just for readability...

int secretPassCode 231;
int numPresses 0;     // the number of button presses (so far)
int userEntry 0;

void OnEnter()
{
    
SetEntityPlayerInteractCallback("ScriptArea_1""OnButtonPress"false);
    
SetEntityPlayerInteractCallback("ScriptArea_2""OnButtonPress"false);
    
SetEntityPlayerInteractCallback("ScriptArea_3""OnButtonPress"false);
}

void OnButtonPress(string &in sender)
{
   
    
int digit GetDigitFromButton(sender);
    if (
digit == INVALID_VALUE)
        return;
        
    
PlaySoundAtEntity("""static_rock_start.snt"sender0.0ffalse);
        
    
userEntry += digit Pow(10numPresses);
    
    
AddDebugMessage(sender "; SUM: " userEntryfalse);
    
    ++
numPresses;   // increments numPresses by 1

    
if (numPresses >= 3)    // all digits were entered
    
{
        if (
userEntry == secretPassCode)
        {
            
SetSwingDoorLocked("door_1"falsefalse);   // Unlocks the door
            
PlaySoundAtEntity("""unlock_door.snt""door_1"0.0ffalse);
        }

        
// Otherwise, reset all the variables, so that the user can try again
        
userEntry 0;        
        
numPresses 0;            
    }


As you can see, it's not very long. A constant and some variables are declared at the top. Then, in OnEnter(), the same interaction callback function is hooked up with each script area. It's the OnButtonPress() function, and it get's called whenever a "button" (script area) is interacted with.

The line
int digit = GetDigitFromButton(sender);
calls another function I made, which simply takes the script area name as an argument, and returns a corresponding digit.
Here's how:
PHP Code: (Select All)
int GetDigitFromButton(string &in buttonID)
{
    
int result INVALID_VALUE;    
    
    if (
buttonID == "ScriptArea_1")
        
result 1;
    else if (
buttonID == "ScriptArea_2")
        
result 2;
    else if (
buttonID == "ScriptArea_3")
        
result 3;
    
    return 
result;


Now, in the OnButtonPress() function, this is the important line - it's the line that actually implements the "a b c thing" I was talking about:
userEntry += digit * Pow(10, 2 - numPresses);

I used the += shorthand, but it can be also written like this:
userEntry = userEntry + (digit * Pow(10, 2 - numPresses));

Here, the digit obtained earlier is first multiplied by a power of 10, depending where in the sequence it should be (that's what the Pow() function does). Then it's added to the overall sum that is going to become the user entry when the final button is pressed.

After each button press, I increment the numPresses counter. The line
++numPresses;

is equivalent to
numPresses = numPresses + 1;

Then I simply check if all 3 buttons where pressed, and if so, I compare the user code to the secret code. If they are equal, I unlock the door, if not, I reset everything, so that the user can try again.

BTW, the Pow() function is another function I wrote for this script:
PHP Code: (Select All)
// Raises an integer to some power
int Pow(int numberint power)  // doesn't support negative powers!
{
    if (
power == 0)
        return 
1;
   
    for (
int i 1power; ++i)
        
number *= number;
        
    return 
number;


That's the entire script - it's not that complicated.

P.S. If there happen to be any problems with the map, delete the map_cache file (in the "maps" dir), just in case.

I can see the number here is 231..
now IF it is possible i would like to have an ENTER\accept to the finishing toutch...

Now there are 3 numbers 231
I aint SOOO good as you, i appoligize for that!

I am an OK scripter but thisn is i bit too much for me atm...

Is it possible if you add me on skype?
Or offcourse you mauy explane here as well.

My name is redmaster12345

I am veyr thankfull already but its a bit too much :O
(This post was last modified: 12-19-2012, 07:35 PM by DnALANGE.)
12-19-2012, 07:34 PM
Find


Messages In This Thread
RE: Need script help asap! extremely difficult script! - by DnALANGE - 12-19-2012, 07:34 PM



Users browsing this thread: 5 Guest(s)