Frictional Games Forum (read-only)
Script help - 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 help (/thread-20936.html)

Pages: 1 2


Script help - Rakez68 - 03-27-2013

Hello.

I need help with one script. I have 4 chemicals in a map and after picking up all the four chemicals to your inventory, you can use them on a chemistry pot which is on a table. After that, you'll be able to pick it up to your inventory and later use it.

My current script looks like this:
void OnStart()
{
for("int i=0;i<=4;i+") AddUseItemCallback("Chem"+i, "GetAcidComplete", "UsedChemsOnPot", true, 0);
}
void UsedChemsOnPot(string &in asItem, string &in asEntity)
{
{
if("asParent" == "Chem1" && GetLocalVarInt("Var1") == 1)
{
SetLocalVarInt("Var1", 1);
}
else if("asParent" == "Chem2" && GetLocalVarInt("Var1") == 1)
{
SetLocalVarInt("Var1", 1);
}
else if("asParent" == "Chem3" && GetLocalVarInt("Var1") == 1)
{
SetLocalVarInt("Var1", 1);
}
else if("asParent" == "Chem4" && GetLocalVarInt("Var1") == 1)
{
SetLocalVarInt("Var1", 1);
}
}
if(GetLocalVarInt("Var1") == 4)
{
PlayMusic("26_event_agrippa_head.ogg", false, 0.7, 0.1, 10, false);
}
}

It gives me this error right now:

FATAL ERROR: Could not load script file 'custom_stories/His dearest friend/Maps/WineCellar.hps'!
main (16, 23) : ERR :Expected ';'

And if i remove the " from ("int i=0;i<=4;i+"), it gives me this error:

FATAL ERROR: Could not load script file 'custom_stories/His dearest friend/Maps/WineCellar.hps'!
main (15, 23) : ERR : Expected ';'

It doesn't make sense..

Would really appreciate if you'd tell me is the script itself even right, and if it is, what's the problem?


RE: Script help - Adrianis - 03-27-2013

Code:
void OnStart()
{
    for(int i=1;i<=4;i++) AddUseItemCallback("Chem"+i, "GetAcidComplete", "UsedChemsOnPot", true, 0);
    SetLocalVarInt("Var1", 0);
}

void UsedChemsOnPot(string &in asParent, string &in asChild, int alState)
{

    PlayGuiSound("16_lever_stuck", 0.3f);
    PlaySoundAtEntity("", "impact_metal_chain_med", "Player", 0.0f, false);
    
    if("asParent" == "Chem1" && GetLocalVarInt("Var1") == 1)
    {
        AddLocalVarInt("Var1", 1);
    }
    else if("asParent" == "Chem2" && GetLocalVarInt("Var1") == 1)
    {
        AddLocalVarInt("Var1", 1);
    }
    else if("asParent" == "Chem3" && GetLocalVarInt("Var1") == 1)
    {
        AddLocalVarInt("Var1", 1);
    }
    else if("asParent" == "Chem4" && GetLocalVarInt("Var1") == 1)
    {
        AddLocalVarInt("Var1", 1);
    }
    
    if(GetLocalVarInt("Var1") == 4)
    {
        PlayMusic("26_event_agrippa_head.ogg", false, 0.7, 0.1, 10, false);
    }
}

Several problems here

Firstly, the 'for' loop at the beginning of your script needs to be part of a function (it can't be loose in the script), for example OnStart like in my edited code above.

In the for loop, you start int i at 0, but you are running the loop whilst it is less than or equal to (<=) 4, which means it will run 5 times, so I changed it to 1 since you want to add the 1 to the names of the items. Also, in the last section of the for loop conditions you only had (i+), it needs to be (i++) which means (i + 1) in order to properly iterate.

I've added the SetLocalVarInt to OnStart, and changed all of the SetLocalVarInt's from within the if statements in 'UsedChemsOnPot', changed to AddLocalVarInt. The difference is that SetLocal...etc is telling the game "put the value of this variable to the number I specify", so it was constantly setting the value to 1, rather than adding 1 to the value as I think you wanted to. AddLocalVarInt is telling the game "add the number I specify to this variable", so it starts at 0 then adds 1 each time a chemical is used, eventually ending at 4 which is enough for the final if statement to run.


In the future, this kind of thread should be created in the 'Development Support' sub-forum Smile

Hope that works, let me know if your still getting problems with it.

EDIT: You changed it while I was writing Tongue
So, additionally, you need to not have "" around the conditions for the 'for' loop (conditions is the part in brackets)
You were also using too many braces '{}', you need to keep track of where the opening { and closing } are, so you don't include too many


RE: Script help - Rakez68 - 03-27-2013

It still doesn't work. the script now is:
void OnStart()
{
SetLocalVarInt("Var1", 0);
for(int i=1;i<=4;i++) AddUseItemCallback("Chem"+i, "GetAcidComplete", "UsedChemsOnPot", true, 0);
}
void UsedChemsOnPot(string &in asItem, string &in asEntity)
{
if("asParent" == "Chem1" && GetLocalVarInt("Var1") == 1)
{
AddLocalVarInt("Var1", 1);
}
else if("asParent" == "Chem2" && GetLocalVarInt("Var1") == 1)
{
AddLocalVarInt("Var1", 1);
}
else if("asParent" == "Chem3" && GetLocalVarInt("Var1") == 1)
{
AddLocalVarInt("Var1", 1);
}
else if("asParent" == "Chem4" && GetLocalVarInt("Var1") == 1)
{
AddLocalVarInt("Var1", 1);
}

if(GetLocalVarInt("Var1") == 4)
{
GiveSanityBoostSmall();
SetEntityActive("GetAcidComplete", false);
PlayMusic("26_event_agrippa_head.ogg", false, 0.7, 0.1, 10, false);
}
}

FATAL ERROR: Could not load script file 'custom_stories/His dearest friend/Maps/WineCellar.hps'!
main (16, 24) : ERR : No matching signatures to 'AddUseItemCallback(string@&, string@&, string@&, const bool, const uint)'


RE: Script help - Adrianis - 03-27-2013

Code:
AddUseItemCallback(string& asName, string& asItem, string& asEntity, string& asFunction, bool abAutoDestroy);

That's the function on the wiki

Code:
AddUseItemCallback("Chem"+i, "GetAcidComplete", "UsedChemsOnPot", true, 0);

That's the information you have put into that function. (string, string, string, bool, int)

Now, the error
Quote: No matching signatures to 'AddUseItemCallback(string@&, string@&, string@&, const bool, const uint)'
'No matching signature' means it doens't know what that function is. A function's 'signature' is its name, AddUseItemCallback, and it's list of 'parameters' (string@&, string@&, string@&, string@&, const bool). It doesn't recognise the signature of the funtion you are using.

Can you see what you did wrong?


RE: Script help - Rakez68 - 03-27-2013

I really had hard time trying to figure out how to solve it, but it just doesn't pop to my head. Why does it whine about the line (16, 24) which is
(int i=1;i<=4;i++)

No, I don't know what to do. It's a shame because I really want to learn these things Undecided

for(int i=1;i<=4;i++) AddUseItemCallback("", "Chem"+i, "GetAcidComplete", "UsedChemsOnPot", true, 0);
I first had only 3 strings,but if the wiki said there was supposed to be 4 strings, i added 1. now atleast the amount of strings match.

But it still doesn't work.


RE: Script help - PutraenusAlivius - 03-27-2013

Something is wrong with the AddUseItemCallback, just like what Adrianis pointed out. AUIC takes 5 arguments. 4 names and 1 bool. You use 3 names and 2 bool's. From the looks of it, the signature looked like AddEntityCollideCallback.

Anyway, change it to this. This is just an example.
AddUseItemCallback("INTERNALNAME", "ITEMTOUSE", "ENTITYFORITEMTOUSE", "FUNCTION", true);
Change
INTERNALNAME to whatever you want the internal name to be.
ITEMTOUSE to the name of what item do you want to use.
ENTITYFORITEMTOUSE to what your entity's name that is used by item.
FUNCTION to whatever your function is.
Don't change the true.
REMEMBER TO USE QUOTATION MARKS ("") AROUND THE NAMES!

EDIT:
I noticed that you edit it. It got 6 arguments.


RE: Script help - Rakez68 - 03-27-2013

It does load the map fine now. And I understand now the issue. But I have another problem now, something I can't understand.

I pick up all four chemicals, and I try to put them into the pot (which is on the table). There does not come text ''Cannot use this item this way.'' But the SECOND time I try, there comes the text.
The item does not disappear from my inventory, and no sound effect plays.
After putting all four chemicals to the pot, nothing happens. It is supposed to play the event after all 4 chemicals have been put into the pot.

SetLocalVarInt("Var1", 0);
for(int i=1;i<=4;i++) AddUseItemCallback("Chemicals", "Chem"+i, "GetAcidComplete", "UsedChemsOnPot", true);
}
void UsedChemsOnPot(string &in asItem, string &in asEntity)
{

if("asParent" == "Chem1" && GetLocalVarInt("Var1") == 1)

{
AddLocalVarInt("Var1", 1);
RemoveItem("Chem1");
PlaySoundAtEntity("", "unlock_door.snt", "Player", 0, false);
}
else if("asParent" == "Chem2" && GetLocalVarInt("Var1") == 1)
{
AddLocalVarInt("Var1", 1);
RemoveItem("Chem2");
PlaySoundAtEntity("", "unlock_door.snt", "Player", 0, false);
}
else if("asParent" == "Chem3" && GetLocalVarInt("Var1") == 1)
{
AddLocalVarInt("Var1", 1);
RemoveItem("Chem3");
PlaySoundAtEntity("", "unlock_door.snt", "Player", 0, false);
}
else if("asParent" == "Chem4" && GetLocalVarInt("Var1") == 1)
{
AddLocalVarInt("Var1", 1);
RemoveItem("Chem4");
PlaySoundAtEntity("", "unlock_door.snt", "Player", 0, false);
}

if(GetLocalVarInt("Var1") == 4)
{
GiveSanityBoostSmall();
SetEntityActive("GetAcidComplete", false);
PlayMusic("26_event_agrippa_head.ogg", false, 0.7, 0.1, 10, false);
}
}


RE: Script help - PutraenusAlivius - 03-27-2013

For mixing items (Like mixing 4 chemicals to a pot), use the AddCombineCallback.

From the Script Functions page,
AddCombineCallback(string& asName, string& asItemA, string& asItemB, string& asFunction, bool abAutoDestroy);
asName - Internal Name
asItemA - Name of first item
asItemB - Name of second item
asFunction - Name of the function
abAutoDestroy - Determines whether the item is destroyed when combined.

Callback Syntax:
void Function(string &in asItemA, string &in asItemB)

Put it in the Inventory.hps. You should create one at the maps/ directory.


RE: Script help - Rakez68 - 03-27-2013

''Allows the player to combine items in his inventory.''

I'm not trying to do that.

The pot is on the table. You are not going to pick up the pot in any part. Once you have put all the chemicals into the pot, (which by the way has a script area on it, with item interaction on called GetAcidComplete)
So you don't exactly put the chemicals into the pot, you put them into the script area which has item interaction on. After successfully putting all four chemicals into the script area, the script area will disappear, allowing you to take the full chemistry pot to your inventory.

I'm sorry for not mentioning that earlier.

I'm trying to do the same as you do with using a key to a door, but now just with four items.


RE: Script help - PutraenusAlivius - 03-27-2013

(03-27-2013, 03:39 PM)Rakez68 Wrote: ''Allows the player to combine items in his inventory.''

I'm not trying to do that.

The pot is on the table. You are not going to pick up the pot in any part. Once you have put all the chemicals into the pot, (which by the way has a script area on it, with item interaction on called GetAcidComplete)
So you don't exactly put the chemicals into the pot, you put them into the script area which has item interaction on. After successfully putting all four chemicals into the script area, the script area will disappear, allowing you to take the full chemistry pot to your inventory.

I'm sorry for not mentioning that earlier.
Then you use AddUseItemCallback then.