Frictional Games Forum (read-only)

Full Version: Having issues w/ script
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
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.
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
It didn't worked. D:
I have no idea of how to make this work. Maybe using global variables?
(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); 
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.
I think it's working, the sound it's not playing.
You could check that.
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
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.
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
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.
Pages: 1 2