Frictional Games Forum (read-only)
Having issues w/ script - 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: Having issues w/ script (/thread-24125.html)

Pages: 1 2


Having issues w/ script - str4wberrypanic - 12-15-2013

Hello guys. I'm having a little problem with a script. This is what's supposed to happen:

The player picks up an item on map A and then he collides with a script area on map B. The script area on map B checks if the player has the item, and if he has, a clock plays a sound. If he hasn't the item, then nothing happens.
This is the script i'm using:



////////////////////////////
// Run first time starting map
void OnStart()

{

AddEntityCollideCallback("Player", "Start_Clock_Area", "Clock_Event", false, 1);

}

void Clock_Event(string &in asParent, string &in asChild, int alState)
{
if(HasItem("item_screwdriver_2"))
{
AddTimer("", 0.1f, "Useless_Timer");
PlaySoundAtEntity("", "Clock_Chimes", "clock_grandfather_2", 0, false);
}

else
{
return;
}
}

void Useless_Timer(string &in asTimer)
{
RemoveEntityCollideCallback("Player", "Start_Clock_Area");
}






There's also a timer to remove the collision because i want the event to happen only once. I tested this script and nothing happens even if i have the item in the inventory. Any help will be apreciated.


RE: Having issues w/ script - RaideX - 12-15-2013

this may be ur problem:

try to change this

PHP Code:
if(HasItem("item_screwdriver_2")) 

to this:

PHP Code:
if(HasItem("item_screwdriver_2") == true



RE: Having issues w/ script - str4wberrypanic - 12-15-2013

It didn't worked. D:
I have no idea of how to make this work. Maybe using global variables?


RE: Having issues w/ script - RaideX - 12-15-2013

(12-15-2013, 10:22 PM)str4wberrypanic Wrote: It didn't worked. D:
I have no idea of how to make this work. Maybe using global variables?

Yes. You could try using global variables.

Sidenote: when you use the AddEntityCollideCallback function you can select if the collidearea should be removed with the "bool abDeleteOnCollide" parameter. So you can remove the whole useless timer thing and just change your collide callback to this:

PHP Code:
AddEntityCollideCallback("Player""Start_Clock_Area""Clock_Event"true1); 



RE: Having issues w/ script - str4wberrypanic - 12-15-2013

Yeah, i know about this parameter. The thing is: the player collides with that area a lot of times, so it's necessary to check if he has the item every time. If i mark it as " true ", the event wouldn't happen because it would check the player inventory only once and remove the collidecallback. Anyway, i'll try using global variables, thank you.


RE: Having issues w/ script - Daemian - 12-15-2013

I think it's working, the sound it's not playing.
You could check that.


RE: Having issues w/ script - str4wberrypanic - 12-15-2013

It's not working. I tried another similar script in which a lot of plates fall from a shelf if the player has the same item.

It's so strange, i don't see any error in this script


RE: Having issues w/ script - Daemian - 12-15-2013

Can you try your code with these debug messages?
PHP Code:
void OnStart()



AddEntityCollideCallback("Player""Start_Clock_Area""Clock_Event"false1);
AddDebugMessage"OnStart"false );
}

void Clock_Event(string &in asParentstring &in asChildint alState)
{
AddDebugMessage"Collision with Area"false );
if(
HasItem("item_screwdriver_2") == true)
{
AddDebugMessage"HasItem=true"false );
AddTimer(""0.1f"Useless_Timer");
PlaySoundAtEntity("""Clock_Chimes""clock_grandfather_2"0false);
}

}

void Useless_Timer(string &in asTimer)
{
RemoveEntityCollideCallback("Player""Start_Clock_Area");
AddDebugMessage"UselessTimer"false );


It's your same script with some debug messages.


RE: Having issues w/ script - Romulator - 12-16-2013

Could you also make sure that your items are named correctly in the Level Editor? Like, item_screwdriver_2 and clock_grandfather_2 are named accordingly.

Also:
PHP Code:
PlaySoundAtEntity("""Clock_Chimes.snt""clock_grandfather_2"0false); //Missing .snt extension? 

I am not 100%, but if you're missing the .snt, I think that wont play the sound :o


RE: Having issues w/ script - FlawlessHappiness - 12-16-2013

Ok. I don't know how far you are.


IN MAP1

void OnStart()
{
SetEntityPlayerInteractCallback("item", "ItemCallback", true)
}

void ItemCallback(string &in asEntity)
{
SetGlobalVarInt("Map2Area", 1);
}

void OnEnter()
{

}

void OnLeave()
{

}

____________________________________
IN MAP2

void OnStart()
{
AddEntityCollideCallback("Player", "ClockArea", "CollideClockArea", false, 1);
}

void CollideClockArea(string &in asParent, string &in asCHild, int alState)
{
if(HasItem("item") == true)
{
PlaySoundAtEntity("", "Clock_Chimes.snt", "clock_grandfather_2", 0, false);

}
}

void OnEnter()
{
if(GetGlobalVarInt("Map2Area") == 1)
{
SetEntityActive("ClockArea", true);
}
}

void OnLeave()
{

}

I don't know if this works, but try it.