All righty, so basically I'm trying to break against the traditional crowbar-breaks-after-one-use shenanigans and I have at least four doors that will require using the crowbar, three being the regular mansion door and the last being boards covering a door.
I've been able to successfully script for a single door, but now that I have to add to it, I have no idea where to really start. While I know that I can use the Variables to help condense the scripts, I'm not entirely sure how to go about it or if with also needing to script for boards, if that might makes things a little different.
if(asEntity == "NameOfDoor")
{
//Setup the stuff you want to happen for this door
}
else if(asEntity == "ThisNameOfDoor")
{
//Setup the other door here
}
Basically, you do all four doors in one single use item script.
At least I hope this is what youre looking for.
Derp.
(This post was last modified: 09-21-2014, 08:21 PM by Neelke.)
Yeah, that's basically what I'm looking for, to be able to use the one item for all four functions, but I'm not entirely sure how to use the script you posted.
I'd suggest writing a script without the usage of normal names, but with asEntity and asItem instead. That way you can use the same thing few times. I'm not sure if it's possible thouh, haven't done that.
PS. I'm proud of ya for not breaking the crowbar in half. It's such a crap
I don't think I'm doing this correctly. This is the script that I'm running on a test map (to prevent any unsavory things from happening to the rest of the script file).
There are probably some other errors in here as I had previously used this to run another test and I don't think I quite found all the leftovers of that.
You used "asEntity" as the entity. This will not work, and there's a simple explanation.
asEntity, is referring to the parameters in a function.
Fx. when using a collide-function you write:
void CollideFunction(string &in asParent, string &in asChild, int alState)
Notice all the things inside the paranthesises! ^^^^^
You have 3 different parameters here: asParent, asChild and alState.
asParent and asChild has "string" in front of them, because you have to use a word.
alState has "int" in front of it, because it's a whole number, without decimals (1, 0, or -1)
But you wrote "asEntity" in voidOnStart(), which has nothing in the paranthesises. That's why it won't work.
for(int i=1; i<=4; ++i) is used to create a loop.
The first number "int i=1;" says that it has to start at 1.
The second number "i<=4;" says that it has to end at 4.
So by writing "mansion_"+i in the entities-space he selects all the mansion doors named, mansion_1, mansion_2, mansion_3, and mansion_4.
He did this, to save time and space. To understand it better, what he's actually doing is writing this:
Do you see?
He selects all the doors, but he uses the same crowbar. This means that the function "UseCrowbarOnDoor" will call when he uses "crowbar" on either of the selected doors.
In your script, you have chosen to name all the doors "Door_1", "Door_2", and so on...
Remember to rename these.
In this function you are only checking for 2 of the doors. If i recall correctly, you had 4. So the script is not done before you've done it to all 4 doors.
BUT! Since you are now learning about "asEntity" how about we optimize the script a bit?
Since you are using "asEntity" in the AddTimer it doesn't matter which door you are using it on, since it will always pick the door you are using it on anyway. (Because the door you are using the crowbar on will automatically be "asEntity").
Notice that I added an extra line about setting a "string" to asEntity. This will be useful later. I'm just storing the information. Just read along.
Also notice that I'm removing the crowbar. This is so that the player won't go and use the crowbar on another area, while the joint it active, because then suddenly 2 joints will be active, meaning 2 crowbars. And the player will be like: "Wut? How did i do that?"
You have chosen only to set "Joint" active. Since there's only 1 object named "Joint" in the map, and it's only placed at 1 of the doors, what will happen at the 4 other doors?
Good question. Right now, the answer is: The same "Joint" will go active again. Which is, (what I'm pretty sure) not what you want.
So instead, let's go and rename all the "Joints" into "Joint_Door_1" if it's at "Door_1", "Joint_Door_2" if it's at "Door_2". And so on...
Hopefully you get the idea now.
This is because "asTimer" was previously set to be "asEntity", which was the door we were using the crowbar on, in the first case: "Door_1". This means that the object that goes active is "Joint_Door_1", just as we renamed it to.
So what happens when the Joint collides with the area?
This is not general enough, since the exact same thing will happen, as the above where, only the first Joint will be deactivated.
So let's touch it up a bit:
I changed the SetEntityActive entity to asParent, because now we're just setting the Joint inactive.
And now you wanted to add a broken crowbar? Why is that exactly? Because since you're going to be using it again, it shouldn't just break should it?
I deleted that line.
And here comes the special thing. I'm now pulling back the information I stored earlier by using GetLocalVarString("CrowbarDoor"). This way, it'll remember what door it was we were using it on, because it we set it that way.
Also, notice that in the end I'm giving the player the crowbar again, so that he can use it again.
Just put "GetLocalVarString("CrowbarDoor")" instead of "Door_x", because "Door_x" isn't anything you have in the editor, and therefore nothing will happen.
Oh my goodness, Flawless!! Thank you so much! I knew something needed to happen with the +i, but thought it was the _x (facepalm). And it all made complete sense to me, so thank you thank you thank you!
Unfortunately though, I'm trying to run this on my test map, and I can't even use the crowbar on the door. I'm wondering if maybe some of the names don't match up, but this has become such a scrambled mess in my own head, I'm probably just looking it right over.
Crowbar: Crowbar_1 Door: Door_1 Joint: Joint_Door_1 Areas: AreaBreak_1 (for where the joint hits to call the script)
AreaEffect_1 (for the particles as the door opens)
So the question I have is: do I need to do the same variable technique for the areas as well? Is there anything else that I am missing?
On your SetEntityActive line within TimerPlaceCrowbar, try doing "Joint_"+asTimer instead. If your joint name is Joint_Door_1 and asTimer is the same as your door name, then doing what you have will result in Joint_Door_Door_1.
Just trace it back if you're unsure. asTimer = internal name from the AddTimer function calling, which is a few lines above. That internal name = asEntity of the UseCrowbarOnDoor function. asEntity in the function creating that callback is "Door_"+i, so "Door_1" for example, depending on the door.