Frictional Games Forum (read-only)
HAI GUYS! - Printable Version

+- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum)
+-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html)
+--- Forum: Custom Stories, TCs & Mods (https://www.frictionalgames.com/forum/forum-35.html)
+--- Thread: HAI GUYS! (/thread-8484.html)

Pages: 1 2


HAI GUYS! - SLAMnesia - 06-07-2011

I'm in need of some help Smile
I have an idea I'd like to have work with the ever so amazing assistance of the Amnesia Community <3

I would like to have two cranks to open one door. No timer. just they both have to be turned all the way for the door to open. And both of the cranks are BROKEN! by that I mean they are on the ground somewhere, you find them and then to fix the whole crank mechanism you pick up the misplaced crank handles that were on the floor and place them from your inventory on a crank hole and it's magically fixed. Afterwards you may crank that door to freedom.
The whole thing is much like that part in Cistern Control Room when the crank brakes and you find the spare part to fix the wheel mechanism
ARE YOU UP TO THE TASK?!!?!?
I would seriously make love to whoever can do this
PS: im a man
PPS: a STRAIGHT man
PPPS: who would go gay for someone to help me <3


RE: HAI GUYS! - DannieWest - 06-07-2011

Okay sorry got no clue, but couldn't help commenting on this one cuz of how much I laughed at the last part "PS: im a man
PPS: a STRAIGHT man
PPPS: who would go gay for someone to help me <3" xD


RE: HAI GUYS! - ferryadams10 - 06-07-2011

I think you need to make a thread about a question of how to use variables cause there u need variables for. I'm still picking up some experience with variables scripts Tongue


RE: HAI GUYS! - SLAMnesia - 06-07-2011

Dannie you're my wingman on scripting :'( Ok, well eventually a variable thread is bound to show up, I don't think if I make one it'll catch on, someone with alot more experience and reputation could get one going.

and that "PS:" thing got me laughing too lol


RE: HAI GUYS! - Apjjm - 06-07-2011

Well, this looked like it would be a rather interesting problem, so I slapped together a quick map for the problem:
Mediafire download

If you just want the script:
Code:
/* OverView:

We have 2 cranks. These are used to crank the door open. The door is dynamically attached to the remaining crank
after the first one has undergone a full revolution. This is handled by crankStateChanged().

These cranks, however, state off de-activated until the player puts the cranks in.

*/

void OnStart() {
  //Intitate the crank enabling (using) part:
  //If you had a lot of cranks, you could easily set this up as a for loop.
  SetEntityActive("crank_base_1",false);
  SetEntityActive("crank_base_2",false);
  AddUseItemCallback("CBcrank", "crank_wood_1", "base_1", "attachCrankToBase", false);
  AddUseItemCallback("CBcrank", "crank_wood_2", "base_1", "attachCrankToBase", false);
  AddUseItemCallback("CBcrank", "crank_wood_1", "base_2", "attachCrankToBase", false);
  AddUseItemCallback("CBcrank", "crank_wood_2", "base_2", "attachCrankToBase", false);
  //Intiate the crank spinning part:
  //Say we have two cranks in total.
  SetLocalVarInt("CrankCount",2);
  //Say how many cranks are already in their finished state. This is currently 0.
  SetLocalVarInt("CranksDone",0);
}
void OnEnter() {}
void OnLeave() {}

/////////////////////////////////////////////////////////////
//CONSTANTS                                                //
/////////////////////////////////////////////////////////////
const string _crankSignature = "crank_base_"; //Constant so you can change the naming of your cranks.
const string _doorName = "vertical_door_1";   //Place the name of your door here

/////////////////////////////////////////////////////////////
//Called when one of the item cranks is used on a mount    //
/////////////////////////////////////////////////////////////
void attachCrankToBase(string &in asItem, string &in asEntity)
{
   if(GetLocalVarInt("ActivatedCrank"+asEntity) == 1)
    { //Person tried to use crank on crank!
      //Tell them they can't do this (May want to make custom message)?
      SetMessage("Inventory","UseItemDoesNotWork",0);
    }
   else
    { //As the names of the base are substrings of the crank's name, this part is really trivial.
      //Base names are done_1 and done_2. Crank names are crank_done_1 and crank_done_2.
      SetEntityActive("crank_"+asEntity,true);
      SetWheelStuckState("crank_"+asEntity,0,false); //This fixes random spinning when activate is called after attach.
      //Prevent more than one attach to this attach point by flagging this attach as done.
      SetLocalVarInt("ActivatedCrank"+asEntity,1);
      //Remove the item from the inventory
      RemoveItem(asItem);
    }
}

/////////////////////////////////////////////////////////////
//Called when one of the activated cranks is used and      //
//changes from one state to another (min -1 , max 1)       //
//this routine is called by BOTH CRANKS!                   //
/////////////////////////////////////////////////////////////
void crankStateChanged(string &in entity, int state) {
   AddDebugMessage("StateChanged for crank "+ entity + " to " + state,false);
  
   //Stores the entities state for future reference
   SetLocalVarInt("state_"+entity,state);
  
   //If the crank is uncranked, decrease cranksDone count, else increase it...
   //State is either +1 or -1. We make use of this to increase or decrease.
   AddLocalVarInt("CranksDone",state);
      
   //If we have only one crank left, then that crank needs to be attached to the door.
   int crankCount = GetLocalVarInt("CrankCount");
   if(GetLocalVarInt("CranksDone") == crankCount-1)
    { //Find the crank that isn't attached yet so we can attach it.
      for(int i=1; i<=crankCount; i++)
       {
        if(GetLocalVarInt("state_"+_crankSignature+i) != 1)
         { //Found it? Attach it! Don't need to loop further now.
             InteractConnectPropWithMoveObject("MoveDoor",_crankSignature+i,_doorName,true,false,1);
          i=crankCount;
         }
       }
    }
    
    //If this crank is not the last crank, and it was moved to it's maximum.
    //We can safely lock this crank in place, then forget about it.
    if( (crankCount > GetLocalVarInt("CranksDone")) && (state == 1) ) SetWheelStuckState(entity,1,true);
  }

An overview of the solution is as follows:

Entites:
  • base_1, base_2 - These are the "mounts" for the cranks
  • crank_base_1, crank_base_2 - the cranks you actually spin at the respective bases. Initially de-activated.
  • crank_wood_1, crank_wood_2 - the cranks you pick up
  • vertical_door_1 - the door that moves up/down with the cranks
Callbacks:
  • attachCrankToBase - Called when a crank_wood is used on a base
  • crankStateChanged - when a crank_base is turned

Intially the cank_base objects are de-activated, and item callbacks added for the crank_wood objects with each base. When a wood object is attached to a base, the crank_base at that base is activated - which can then be spun. When all the crank_bases are spun the door will lift (the door is attached to the last crank_base).

The callback routines are as loosely coupled as i could make them, so if you have different objects and different names you should just be able to change the constants and the onStart() routine and it will work. It will also work for any number of cranks.



RE: HAI GUYS! - SLAMnesia - 06-07-2011

Ok I am now gay for you Smile

on a serious note I'm at school and I can't try it till later on when things are done. It's obvious you put in your own time to help me (a stranger) out so fine sir are a greatly appreciated member of the amnesia community Big Grin Big Grin at least to me you are

<3
I hope that is as sincere as it sounds I work hard on "thank you's"


RE: HAI GUYS! - palistov - 06-07-2011

Off-topic, but Apjjm where do you learn your scripting methods? I opened the script to your tetris mod and was brutally maimed by double arrays and whatnot. I tried opening the AngelScript manual off of the website but it all looks like gibberish :S


RE: HAI GUYS! - Apjjm - 06-07-2011

Hope the code works out for you, if you need any more detailed explanations as to what parts are doing what then I can try to help Wink.

(06-07-2011, 09:21 PM)palistov Wrote: Off-topic, but Apjjm where do you learn your scripting methods? I opened the script to your tetris mod and was brutally maimed by double arrays and whatnot. I tried opening the AngelScript manual off of the website but it all looks like gibberish :S

I guess practice and experience, I know quite a few programming languages (have been programming for a while) so I am already familiar with the constructs I am using, and a few tricks about manipulating them. It is always harder to read code that isn't your own though, because you already know what your own code does; that's why the above example has a large amount of comments in - the Tetris code was a little rushed together to be honest, so it is by no means as nicely presented as I would have liked (Also, I didn't have folding regions set up, which I do now), which probably factors into the readability of it to quite a degree.


RE: HAI GUYS! - Acies - 06-07-2011

(06-07-2011, 09:21 PM)palistov Wrote: Off-topic, but Apjjm where do you learn your scripting methods? I opened the script to your tetris mod and was brutally maimed by double arrays and whatnot. I tried opening the AngelScript manual off of the website but it all looks like gibberish :S

He took the red pill.




RE: HAI GUYS! - palistov - 06-07-2011

(06-07-2011, 10:40 PM)Acies Wrote: He took the red pill.

Haha Acies!

Apjjm: Yeah it certainly looks like you know what you're on about. I personally think I've come a long way since I first started trying to read and write my own code for Amnesia, but I know there's many different and possibly easier ways to write the code I manage to flesh out.