Frictional Games Forum (read-only)
[SCRIPT] Need help with several scripts. - 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 - Development (https://www.frictionalgames.com/forum/forum-38.html)
+---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html)
+---- Thread: [SCRIPT] Need help with several scripts. (/thread-16413.html)

Pages: 1 2


Need help with several scripts. - Randael - 06-22-2012

Well, I have been trying to work around quite alot, trying to somehow edit already existing tutorial scripts (the exploding door for example) to work for my cause, but really nothing seems to work right. Ive been searching around quite a lot ... so here are my problems, im gonna try to make it as detailed as possible:

--Board problem was solved:
Code:
void OnStart()
{
    AddUseItemCallback("", "name_of_item", "name_of_entity", "name_of_callback", true);
}

void name_of_callback(string &in item, string &in entity)
{
    SetPropHealth(entity, 0);
    RemoveItem(item);}


Thx to Your Computer =)

-PROBLEM KINDA SOLVED!:

Then i have a problem with a Gate... a portcullis...cant actually call it a "swing"door i suppose.. There´s supposed to be a broken lever-hatch next to it with the lever lying around somewhere(i planned it so that the player needs to find the lever, insert it into the hatch, and then use it to open the Gate) ...
i searched around a bit, and didnt actually tried coding it, since it prolly is far too high forme. (im bloodyly new), i tried using a normal lever instead, but that just gave me errors aswell (the typical wrong signature or expected identifier stuff). I really would appreciate it if someone could give me a base-code i can orientate myself on there(or the complete one, which would be awesomexD I simply need to know what i need to lookout for).

--What do i need to attach a lever-handle to a broken hatch(small lever small hatch), making them 1 to open a gate, and if how to actually make it open the gate(a portcullis)?

-PROBLEM KINDA SOLVED!: (thx to myself)

Code:
Void OnStart()  {
AddEntityCollideCallback("lever1hatch", "llevergate1" , "func_levergate1", true, 1);
}
void func_levergate1(string &in asParent, string &in asChild, int alState)
{
SetEntityActive("lever1hatch" , false);

SetEntityActive("l1l" , true);

SetEntityActive("llevergate1", false);

SetMoveObjectStateExt("gate1", 1.0f, 0.05f, 0.1f, 0.5f, true);

SetLeverStuckState("lever1lever", 1, false); }


---------------------------------------------------------------------------------------------------------------------------
Opens gate, wout lever use though, and lever wont get stuck
---------------------------------------------------------------------------------------------------------------------------

--PROBLEM SOLVED

Code:
//Inside the door slam function:
void Doorslamfunction(whatever callback you used)
{
SetEntityPlayerInteractCallback("DoorNameHere", "DisplayText", false);
}
//Anywhere not inside a function, like OnStart():
void DisplayText(string &in asEntity)
{
SetMessage("Locked", "Basement", 0);
}
for the .lang file:
< LANGUAGE>
< CATEGORY Name="Locked">
< Entry Name="Basement">The door is locked. Damn!</Entry>
< /CATEGORY>
< /LANGUAGE>

--PROBLEM SOLVED( a bit different but who cares, it works)-- (thx to FastHunteR) How do I make a message using the if/else command appear when trying to open a swing door after an event occured? (door slammed shut behind the player and got locked).


Then I have a problem using the insanity crawl sound... i kinda would love it to play through but its only playing once ( like a second or 2) i would use the insanity effect aswell, but ... ive heared its not rly easy to work with them.
Code:
Void OnStart() {AddEntityCollideCallback("Player", "script_steps-ttr", "sstt1", true, 1);
AddEntityCollideCallback("Player", "script_steps-ttr2", "sstt2", true, 1);} void sstt1(string &in asParent, string &in asChild, int alState)
{
PlaySoundAtEntity("sstt1", "insanity_step_crawl", "script_steps-ttr", 0.0, false);
}

void sstt2(string &in asParent, string &in asChild, int alState)
{
PlaySoundAtEntity("sstt2", "insanity_step_crawl", "script_steps-ttr2", 0.0, false);
}

AddEntityCollideCallback("Player", "script_steps-ttr", "sstt1", true, 1);
AddEntityCollideCallback("Player", "script_steps-ttr2", "sstt2", true, 1); }

What do i need todo so it keeps playing for a while? maybe till a few seconds after the door shut scare? (slowly fading out... as if he/she/it is moving away from the door that slammed shut)
Im sorry for this amount of questions, but i really have problems getting around this, and its really hard(and demotivating) to work without a solid base, i most likely wont be able to get it working if i dont see a solid script that actually works , which I can use to orientate myself on in future trys.

(PS: please mention what should get into the OnStart section and whatnot... that stuff has been confusing me since)

Im looking forward to every tip or code I can get, if its just for 1 of those problems or for all of them together (I actually thought about writing a wiki/guide myself with the information i gather... i mean... who could explain a noob how to programme better then another noob? lol) . It would be for my usage too though, since i always can check back how i worked on something to get it working, which hopefully will reduce the amount of mistakes i do over time.

ADDS:

Code:
<LANGUAGE>

<CATEGORY Name="CustomStoryMain">

<Entry Name="Description">
Prepare for something worse...
</Entry>

</CATEGORY>

<CATEGORY Name="Inventory">

<Entry Name="ItemName_chamberkey">Blood stained key</Entry>

<Entry Name="ItemDesc_chamberkey">A key with lots of dryed blood on it.</Entry>

<Entry Name="ItemName_crowbar1">Blood stained crowbad</Entry>

<Entry Name="ItemDesc_crowbar1">A crowbar, looks like it was used quite often , but not for its usual purpose...</Entry>

</CATEGORY>


</LANGUAGE>
Any1 sees any mistake there? it just wont show ingame... only the description of the map.

Randael


RE: Need help with several scripts. - Your Computer - 06-23-2012

It'd be much easier if you understand scripting in general before anyone provides you with any code to begin with. Here are some useful links that can help you better understand HPL2 scripting:
http://wiki.frictionalgames.com/hpl2/tutorials/script/entihscript_beginner
http://wiki.frictionalgames.com/hpl2/tutorials/script/tutorial_1
http://www.youtube.com/watch?v=hrkpC5N_pZM&list=PLD326789BC99530C8&index=4
http://www.youtube.com/watch?v=gP6yQQAup-Q&list=PLD326789BC99530C8&index=6


RE: Need help with several scripts. - Randael - 06-23-2012

Im already aware of those posts, they confuse me much more than they help me though, the only thing i actually could use was the exploding door, and some improvised stuff and stuff i found out by myselfTongue. I need sth complete to work with, not just small parts of everything. I am better in analyzing things and splitting it into parts , putting it into sense myself than adding small parts up, still thanks though.

This might sound like a weird excuse for a lazy programmer, thats not the case =P Im still at the very beginning of the map, at the first room ( of about 22+ on the first map) , so i would need much more scripts before its done, since i have planned something rather complicated (which is a bad idea if you dont have much clue about what todo , but meh thats how i tick). So... i would still appreciate something i could work with, or atleast a custom storie i could use to orientate myself on (I havent played any, and cant remember having seen anything in a lets play like that, something i could use to dig myself through the code and stuff =P).


Randael


RE: Need help with several scripts. - Your Computer - 06-23-2012

Well, assuming you're using "wooden_boards_block" to block off the door. To break the wood by using an item on it you can use this code:

PHP Code:
void OnStart()
{
    
AddUseItemCallback("""name_of_item""name_of_entity""name_of_callback"true);
}

void name_of_callback(string &in itemstring &in entity)
{
    
SetPropHealth(entity0);
    
RemoveItem(item);




RE: Need help with several scripts. - Randael - 06-23-2012

(06-23-2012, 03:17 PM)Your Computer Wrote: Well, assuming you're using "wooden_boards_block" to block off the door. To break the wood by using an item on it you can use this code:

PHP Code:
void OnStart()
{
    
AddUseItemCallback("""name_of_item""name_of_entity""name_of_callback"true);
}

void name_of_callback(string &in itemstring &in entity)
{
    
SetPropHealth(entity0);
    
RemoveItem(item);

so i put an item reaction to the object , which sets the health of it to 0, and destroys the object or crowbar? adduseitemcallback... thats just what i needed^^ gonna try it out, much thx Big Grin

It works perfectly... thanks =) now i just hope in still get help for the other things


RE: Need help with several scripts. - Randael - 06-26-2012

--bump--(check first post for questions, and answers)


RE: Need help with several scripts. - Cruzore - 06-26-2012

--How do I make a message using the if/else command appear when trying to open a swing door after an event occured? (door slammed shut behind the player and got locked).
I think you should go for this:
SetEntityPlayerInteractCallback(string& asName, string& asCallback, bool abRemoveOnInteraction);
Calls a function when the player interacts with a certain entity.
Callback syntax: void MyFunc(string &in asEntity)

asName - internal name
asCallback - function to call
abRemoveOnInteraction - determines whether the callback should be removed when the player interacts with the entity

Paste that callback in the same function as the door slam occurs. make sure to replace the variables.
asName for the door name
asCallback for the name of function which will happen below
abRemoveOnInteraction should be on false, since you want to always see that text.

now for the function, for this we use the callback syntax void MyFunc(string &in asEntity) :

void YourFunctionNameHere(string &in asEntity)
{
SetMessage(string& asTextCategory, string& asTextEntry, float afTime);
}

Now for the SetMessage one:
asTextCategory and TextEntry: for those you have to edit the .lang file. Choose any category name and any Entry name, you can for example choose "Locked" as Category and "Basement" as the Entry name, it's all up to you.
afTime: How long the message will be displayed. A "0" will cause the life time to be calculated using the string length.

So, in the end, it may look like this:
//Inside the door slam function:
void Doorslamfunction(whatever callback you used)
{
SetEntityPlayerInteractCallback("DoorNameHere", "DisplayText", false);
}
//Anywhere not inside a function, like OnStart():
void DisplayText(string &in asEntity)
{
SetMessage("Locked", "Basement", 0);
}
for the .lang file:
<LANGUAGE>
<CATEGORY Name="Locked">
<Entry Name="Basement">The door is locked. Damn!</Entry>
</CATEGORY>
</LANGUAGE>

Sorry for the lang post, but wanted to make sure you understand it. You can ask me/us if you still got a question on this one.


RE: Need help with several scripts. - Randael - 06-26-2012

Alright, gonna test it out, i always had problems with playerinteractcallback though, hopefully it works this time.

IT WORKS, finally , thx xD

Well there´s just one problem, how do i remove the interaction afterwards? I could just make a new door and deactivate the old one, i would still like to deactivate the callback itself though


RE: Need help with several scripts. - Cruzore - 06-26-2012

use a global/local variable(depends on where you use the item)that is normally 0 and 1 when that item has been picked up, and initiate the callback only if that variable is 0.
Example:
void OnStart()
{
SetGlobalVarInt("CallbackVariable1", 0);
}
void UsedKeyOnDoor(syntax stuff)
{
SetGlobalVarInt("CallbackVariable1", 1);

}
void DisplayText(string &in asEntity)
{
if(GetGlobalVarInt("CallbackVariable1")==0)
{
SetMessage("Locked", "Basement", 0);
}
}
It should also work if you set the if for the callback itself, not the called function


RE: Need help with several scripts. - Randael - 06-26-2012

It works, thanks alot^^
Im just curious... noticed any mistake in my .lang file for the items? the names of them just wont show... notes now work aswell, but the items still dont. Can find it on the top post, last part.
(BESIDES the writing mistakesxD)