Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Restoring broken item
Damascus Offline
Senior Member

Posts: 646
Threads: 118
Joined: Mar 2012
Reputation: 29
#1
Restoring broken item

In my custom story, I've put it an item that is destroyed when it's thrown hard enough against something (preset under the BreakEntity properties of the entity). However, I want to be able to restore it, unbroken, to its original position when it's destroyed.

So far, setting the entity active/inactive hasn't brought it back. Neither has ResetProp. I don't think I can create a different entity either, because it also needs to respond to the same script that worked on the original. Can anyone help me?

08-04-2013, 04:05 AM
Find
7heDubz Offline
Posting Freak

Posts: 1,329
Threads: 40
Joined: Feb 2013
Reputation: 41
#2
RE: Restoring broken item

dont let it break? or is it imperative to the story that it breaks?

08-04-2013, 05:13 AM
Find
Daemian Offline
Posting Freak

Posts: 1,129
Threads: 42
Joined: Dec 2012
Reputation: 49
#3
RE: Restoring broken item

Hey DAmascus ;p
I think you're gonna have to create the entity again along with its callbacks.
It worked fine for me.

08-04-2013, 05:20 AM
Find
Damascus Offline
Senior Member

Posts: 646
Threads: 118
Joined: Mar 2012
Reputation: 29
#4
RE: Restoring broken item

@WIWWM: Yeah, it is crucial the story that it breaks, but only under certain circumstances.

(08-04-2013, 05:20 AM)Amn Wrote: Hey DAmascus ;p
I think you're gonna have to create the entity again along with its callbacks.
It worked fine for me.

I used CreateEntityAtArea to respawn it, and it worked... twice. After I broke the item for the third time, it stopped coming back. I repeated the experiment several times, but every time, the CreateEntityAtArea only triggered twice. I'll include my code here:

PHP Code: (Select All)
void CheckGold(string &in asTimer)
{
    if (
GetPropHealth("potash_1") < 1)
    {
        if (
GetLocalVarInt("Pillar") == 1)
        {
            
AddTimer(""1.0f"BlowPillar");
            
SetEntityActive("SignArea_1"false);
        }
        else
        {
            
CreateEntityAtArea("potash_1""crystal_rock_02.ent""FulmGoldArea"false);
        }
    }
    else
    {
        
AddTimer("check"0.1f"CheckGold");
    }


Basically, this timer is constantly checking the health of the item. Once it breaks, if it's inside the proper area, a custom script is triggered. If it's not, a new item should respawn at FulmGoldArea.

(This post was last modified: 08-04-2013, 05:55 AM by Damascus.)
08-04-2013, 05:48 AM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#5
RE: Restoring broken item

When an entity breaks, it gets replaced with an entity that is supposed to represent its broken state. This "broken" entity no longer represents the original entity, therefore ResetProp, etc, doesn't work.

For your current code, you're probably going to have to increment the prop name. Not sure if inspection mode can help with writing a more suitable kind of code.

Tutorials: From Noob to Pro
08-04-2013, 09:48 AM
Website Find
Statyk Offline
Schrödinger's Mod

Posts: 4,390
Threads: 72
Joined: Sep 2011
Reputation: 241
#6
RE: Restoring broken item

What if you place a second entity of it, set it inactive, and when the first gets broken, activate the second entity?
(This post was last modified: 08-05-2013, 03:19 AM by Statyk.)
08-05-2013, 03:19 AM
Find
Daemian Offline
Posting Freak

Posts: 1,129
Threads: 42
Joined: Dec 2012
Reputation: 49
#7
RE: Restoring broken item

OnStart {
SetEntityCallbackFunc( "ent123", "ReplaceMeOnBreak" ); }

void ReplaceMeOnBreak ( string &in e, string &in t )
{ if t == "Break", CreateEntity e at area; SetEntityCallbackFunc( e, "ReplaceMeOnBreak" ); }


Something like that.

08-05-2013, 05:57 AM
Find
Damascus Offline
Senior Member

Posts: 646
Threads: 118
Joined: Mar 2012
Reputation: 29
#8
RE: Restoring broken item

Okay, I was stupid. The part of the script that was creating the new item wasn't resetting the timer. Now that I've fixed that, the item respawns endlessly. BUT, I have a new problem. When I break the first item within BlowPillarArea, the BlowPillar timer activates. However, with the new items that are produced, they do not trigger the timer, even if they are within BlowPillarArea. Instead, they simply respawn again.

This is especially odd because I know the new items all must have the same name, otherwise the script that is respawning them wouldn't work either!

PHP Code: (Select All)
void OnStart()
{
    
AddEntityCollideCallback("potash_1""BlowPillarArea""PillarVar"false0);
}

void PillarVar(string &in asParentstring &in asChildint alState)
{
    if (
alState == 1)
    {
        
SetLocalVarInt("Pillar"1);
    }
    else if (
alState == -1)
    {
        
SetLocalVarInt("Pillar"0);
    }
}

void CheckGold(string &in asTimer)
{
    if (
GetPropHealth("potash_1") < 1)
    {
        if (
GetLocalVarInt("Pillar") == 1)
        {
            
AddTimer(""1.0f"BlowPillar");
            
SetEntityActive("SignArea_1"false);
        }
        else
        {
            
CreateEntityAtArea("potash_1""crystal_rock_02.ent""FulmGoldArea"false);
            
AddTimer("check"0.1f"CheckGold");
        }
    }
    else
    {
        
AddTimer("check"0.1f"CheckGold");
    }


(This post was last modified: 08-05-2013, 06:30 AM by Damascus.)
08-05-2013, 06:02 AM
Find
Adrianis Offline
Senior Member

Posts: 620
Threads: 6
Joined: Feb 2012
Reputation: 27
#9
RE: Restoring broken item

Use a debug message to print the names of the new entities being created, to make sure that they do have the same name - the way the issue is manifesting sounds exactly like the names of the new ones are not the same.
You can do that in the collide callback function, print the name of the colliding entity

It's possible that there is some security code in the source to prevent errors by adding numbers to names of objects being created if the name is the same (in the same way that the level ed will add _x to an entity when you duplicate it)

(This post was last modified: 08-05-2013, 12:26 PM by Adrianis.)
08-05-2013, 12:25 PM
Find
Damascus Offline
Senior Member

Posts: 646
Threads: 118
Joined: Mar 2012
Reputation: 29
#10
RE: Restoring broken item

Unfortunately, I can't use debug mode (link). I will keep working on it today and see if I can find a way around it.

(This post was last modified: 08-05-2013, 10:46 PM by Damascus.)
08-05-2013, 10:43 PM
Find




Users browsing this thread: 6 Guest(s)