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
Restore rusty valve when you die (still unsolved)
Apjjm Offline
Is easy to say

Posts: 496
Threads: 18
Joined: Apr 2011
Reputation: 52
#11
RE: Restore rusty valve when you die (still unsolved)

Here is one way you can use CreateEntityAtArea (as others have suggested).

Put a script area around where you want the valve to appear. Ill Assume for now you called it "ScriptArea_Valve". Don't put a valve there at the start.

As we want to be able to generate an infinite number of valves we are going to want a way to generate new names for them. That's where this first function comes in:
//Function for generating unique names
string generateNewName(string prefix)
{
   AddLocalVarInt("generateNewName_Count_" + prefix,1); //Add one to a count of how many times this was called
   return prefix + GetLocalVarInt("generateNewName_Count_" + prefix); //Use the count to generate a unique valve name
}

Next we want to use this code to be able to create valves. We will create another function which will create a valve at a specified area.
//Create a new valve entity at an area
void createNewValveAtArea(string &in asArea)
{
        //This will generate "Spawning_Valve_1" "Spawning_Valve_2" etc...
    string newValveName = generateNewName("Spawning_Valve_");
    
    //Create the valve
    CreateEntityAtArea(newValveName,"[FileName].ent",asArea,false);
    
    //Do any stuff with the valve here (E.g. callbacks) but use newValveName instead of "Spawning_Valve"
    //E.g. AddEntityCollideCallback(newValveName,"SomeEntity","SomeFunction",false,1);
    
    //Finally we need to keep track of what the most current valve name is (for later)
    SetLocalVarString("CurrentValvename",newValveName);
}

Now we have the code down to generate valves, we need to make a valve spawn when we start the map, as well as set up the checkpoint (your checkpoint code is probably elsewhere rather than OnStart though).
void OnStart()
{
    //Create a valve with all it's callbacks etc
    createNewValveAtArea("ScriptArea_Valve");
    //Create a checkpoint which calls "cbDeath_ValveChase"
    CheckPoint("SomeName","SomeStartArea","cbDeath_ValveChase","SomeCategory","SomeEntry");
}


Finally, all we need to do is disable the old valve and create a new one on death:
void cbDeath_ValveChase(string &in asName, int alCount)
{
    //Disable the old valve
    string oldValve = GetLocalVarString("CurrentValvename");
    SetEntityActive(oldValve,false);
    //Create a new one
    createNewValveAtArea("ScriptArea_Valve");
    
    // **The rest of your checkpoint code here**
}

There are some blanks you will have to fill in, and that code untested but provided you can activate/deactivate the entity you are using this should work.
(This post was last modified: 08-14-2012, 03:36 PM by Apjjm.)
08-14-2012, 03:33 PM
Find
Steve Offline
Member

Posts: 178
Threads: 17
Joined: Jun 2012
Reputation: 7
#12
RE: Restore rusty valve when you die (still unsolved)

I think my brain just went brain dead :| I'll gonna try to figure it out somehow Confused but can I still make it so that the valves break?

CURRENTLY WORKING ON:
Final Light = 40%
Need of voice actors.
09-03-2012, 07:37 PM
Find
Apjjm Offline
Is easy to say

Posts: 496
Threads: 18
Joined: Apr 2011
Reputation: 52
#13
RE: Restore rusty valve when you die (still unsolved)

I can put together a sample map - i shall edit back later this evening when i get chance to put it together.
09-03-2012, 08:52 PM
Find
Steve Offline
Member

Posts: 178
Threads: 17
Joined: Jun 2012
Reputation: 7
#14
RE: Restore rusty valve when you die (still unsolved)

That would be nice thank you Big Grin

CURRENTLY WORKING ON:
Final Light = 40%
Need of voice actors.
09-03-2012, 09:09 PM
Find
Apjjm Offline
Is easy to say

Posts: 496
Threads: 18
Joined: Apr 2011
Reputation: 52
#15
RE: Restore rusty valve when you die (still unsolved)

Ok here is a very basic example map:
https://dl.dropbox.com/u/64805489/Breaka...xample.zip


When you use the breakable valve some piano music plays, and when you use the lantern you die (so that you can test the checkpoint code). All the script is commented so you should be able to see what you need to copy out into your code. The only point of interest in the level editor is the script area.
09-03-2012, 10:46 PM
Find
Steve Offline
Member

Posts: 178
Threads: 17
Joined: Jun 2012
Reputation: 7
#16
RE: Restore rusty valve when you die (still unsolved)

okay I know this took probaly some time to make I think I can handle it with this but one question I have like when you toch an area the valve will easy said break I have:
AddPropHealth("valve_iron_rusty_breakable_1", 100);
should I just make it;
AddPropHealth("CurrentValvename", 100); //////litterly//////
or wait I think I need newvalvename ig i'm wrong you may correct me I'll start to try this now Big Grin

CURRENTLY WORKING ON:
Final Light = 40%
Need of voice actors.
(This post was last modified: 09-04-2012, 03:53 PM by Steve.)
09-04-2012, 03:31 PM
Find
Apjjm Offline
Is easy to say

Posts: 496
Threads: 18
Joined: Apr 2011
Reputation: 52
#17
RE: Restore rusty valve when you die (still unsolved)

Ah, well rusty valve is a bit of a weird prop, so that approach won't work. The valve is actually a multi-body prop with a breakable joint. If you want to break the joint without the player touching the valve, all you need to do is apply a small impulse to the valve, and that will break the joint (You can also use BreakJoint - but you'd still need an impulse otherwise the wheel won't fall off the valve).

The following code assumes you have an area called ScriptArea_BreakValve, which if the player enters breaks the valve.
void OnStart()
{
        // The rest of your OnStart() event \\

    //Add a collision callback between the player and the area which breaks the valve
    AddEntityCollideCallback("Player","ScriptArea_BreakValve","cbCollide_PlayerValveBreakArea",true,1);
}

void YourCheckPoint(string &in asName, int alCount)
{
   // The rest of your Checkpoint code (Spawining the valves etc) \\

   //Re-Add a collision callback between the player and the area which breaks the valve
   AddEntityCollideCallback("Player","ScriptArea_BreakValve","cbCollide_PlayerValveBreakArea",true,1);
}

//This Callback is called when the player walks in an area to break the valve
void cbCollide_PlayerValveBreakArea(string &in asParent, string &in asChild, int alState)
{    
    //Get the current valve's name:
    string valveName = GetLocalVarString("CurrentValvename");
        
    //Because the valve is implemented by an incredibly weak breakable joint
    //We can just apply a small impulse to the valve to break it, as well as make the wheel fall off
    //If you want the wheel to rotate or tumble or something, adjust the values below
    AddPropImpulse(valveName,0,0,0.5f,"local");
}
09-04-2012, 04:27 PM
Find
Steve Offline
Member

Posts: 178
Threads: 17
Joined: Jun 2012
Reputation: 7
#18
RE: Restore rusty valve when you die (still unsolved)

Finaly I got it thanks to all you guys especially Apjjm
 
Edit:
I didn't see jet what you said but it worked because I already had prop force to let it shoot allitle to the left because you "hit" it with a rockbut thanks

CURRENTLY WORKING ON:
Final Light = 40%
Need of voice actors.
(This post was last modified: 09-04-2012, 04:42 PM by Steve.)
09-04-2012, 04:40 PM
Find




Users browsing this thread: 1 Guest(s)