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
Сode
darksky Offline
Member

Posts: 52
Threads: 8
Joined: Nov 2012
Reputation: 2
#11
RE: Сode

if you only call GetButtonPressed with "PressButton_1" ,"PressButton_2",... wouldn't it be better to make the function like this?

string GetButtonPressed(string entity)
{
    return StringSub(entity, 12, 1);
}
(This post was last modified: 02-23-2013, 11:05 PM by darksky.)
02-23-2013, 11:04 PM
Find
NaxEla Offline
Senior Member

Posts: 415
Threads: 5
Joined: Dec 2012
Reputation: 28
#12
RE: Сode

(02-23-2013, 11:04 PM)darksky Wrote: if you only call GetButtonPressed with "PressButton_1" ,"PressButton_2",... wouldn't it be better to make the function like this?

string GetButtonPressed(string entity)
{
    return StringSub(entity, 12, 1);
}

Yes, that would be better :p Good thinkin'
02-24-2013, 02:05 AM
Find
tonitoni1998 Offline
Member

Posts: 163
Threads: 54
Joined: Oct 2012
Reputation: 1
#13
RE: Сode

Took me like 30 min until i understood that code. Finally got it i guess Tongue gonna try doing it myself tomorrow

When you are looking for someone, to do the scripting for your Custom Story, ask me!
02-24-2013, 04:05 AM
Find
nightsxp Offline
Member

Posts: 53
Threads: 8
Joined: Sep 2011
Reputation: 0
#14
RE: Сode

(02-23-2013, 06:12 PM)NaxEla Wrote: I made a code for this a while ago... let me see if I still have it.

EDIT: Ok found it. This code will work if the script areas are called PressButton_1, PressButton_2, PressButton_3, etc... If you want to change the password, just change the number at the very top of the script.

PHP Code: (Select All)
const string correctCode "6274";
string playersGuessedCode "";

void OnStart(){}

void OnEnter()
{
    
SetLocalVarInt("ButtonsPressed"0);
    
    for(
int i=1i<=9i++) {
        
SetEntityPlayerInteractCallback("PressButton_"+i"PressedButton"false);
    }
}

void PressedButton(string &in entity)
{
    
int buttonsPressed;
    
    
AddLocalVarInt("ButtonsPressed"1);
    
    
playersGuessedCode += GetButtonPressed(entity);
    
buttonsPressed GetLocalVarInt("ButtonsPressed");
    
    
AddDebugMessage("Buttons Pressed: "+buttonsPressed+"  Guessed Code: "+playersGuessedCodefalse);
    
    if(
playersGuessedCode == correctCode) {
        
// unlock door or whatever here
        
for(int i=1i<=9i++) {
            
SetEntityActive("PressButton_"+ifalse);
        }
        
ResetCode();
        
AddDebugMessage("Correct code!"false);
        
        return;
    }
    
    if(
buttonsPressed == 4) {
        
ResetCode();
        
AddDebugMessage("Wrong code!"false);
    }
}

void ResetCode()
{
    
SetLocalVarInt("ButtonsPressed"0);
    
playersGuessedCode "";
}

string GetButtonPressed(string entity)
{
    if(
entity == "PressButton_1") {
        return 
"1";
    }
    else if(
entity == "PressButton_2") {
        return 
"2";
    }
    else if(
entity == "PressButton_3") {
        return 
"3";
    }
    else if(
entity == "PressButton_4") {
        return 
"4";
    }
    else if(
entity == "PressButton_5") {
        return 
"5";
    }
    else if(
entity == "PressButton_6") {
        return 
"6";
    }
    else if(
entity == "PressButton_7") {
        return 
"7";
    }
    else if(
entity == "PressButton_8") {
        return 
"8";
    }
    else if(
entity == "PressButton_9") {
        return 
"9";
    }
    else {
        return 
"";
    }
}

void OnLeave(){} 

._. diiificult =.= but thankss
02-24-2013, 02:22 PM
Find




Users browsing this thread: 2 Guest(s)