Sign in to follow this  
Followers 0
Punk

[Help] Random Barrels Explode

9 posts in this topic

Hey guys, I'm having a problem here with my script, I wanted to try and solve it by myself but I can't seem to find the problem.

trap2()
{
	trig = getEnt("trig2","targetname");
	booms = getEntArray("br_trig_boom2","targetname");
	door = getEnt("trap2_door", "targetname");

	for(i=0; i<booms.size; i++)
		booms[i] thread check_barrels();

	trig waittill("trigger", player);
	trig delete();

	door moveZ(-82, 3);
	door waittill("movedone");

	for(i=0; i<booms.size; i++)//47 times
	{
		x = randomint(booms.size);

		target = getEnt(booms[x].target, "targetname");

		PlayFx(level.fire_barrel, target.origin + (0,0,32));
		
		wait 2;

		radius = spawn("trigger_radius", target.origin, 0, 40, 64);

		PlayFx(level.barrel_fx, target.origin);
		Earthquake(1, 1, target.origin, 125);
		target delete();
		booms[i] delete();

		players = braxi\_common::getPlayingPlayers();

		for(j=0; j<players.size; j++)
		{
			if(players[j] istouching(radius))
			{
				players[j] suicide();
				players[j] PlaySound("explo_metal_rand");
			}
		}
	}
	door moveZ(82, 3);
}

It's doesn't give a bad syntex or something like that, but after i activate trap, sometimes the barrels explode, other times it gaves me errors, Randomily, don't know if the one's who give bugs are always the same...

 

 

Errors: 

cannot cast undefined to string

undefined is not a field object

 

These errors start from line 20 and 22 and continuing below whenever target or trig is involved.

 

I know the problem is that the target that it finds from that trig is undefined (or the trigger it self), I want to know... why is it happening?

 

Not sure if you guys understood, I'll explain better if you have any questions, if the problem isn't solved, I'll make another trap... which i like to avoid

 

Also explanation of script: 

Acti activates

Doors closes

- Random Barrels explode Inside room

 

Hope I get any help :P

0

Share this post


Link to post
Share on other sites

If I'm not wrong (trying to help here)

target = getEnt(booms[x].target, "targetname");
 
PlayFx(level.fire_barrel, target.origin + (0,0,32));
		

Did you named your origin correct?, since he can't find the origin. Otherwise delete the origin and make a new one and check if other objects are with the same name aswell.

0

Share this post


Link to post
Share on other sites

Each trigger has a target, in this case a barrel, after making a link, radiant attributes a name automatically (auto1..,etc). I don't have origins (script_origins), the thing is, every trigger has a barrel, and yet at one point, it says the trigger or target (still didn't figure it out which one, since i moved to other scripts and left this one to be last one until i get help) are undefined after it selecting it randomly from the triggers (0-46 which is correct).

0

Share this post


Link to post
Share on other sites

Each trigger has a target, in this case a barrel, after making a link, radiant attributes a name automatically (auto1..,etc). I don't have origins (script_origins), the thing is, every trigger has a barrel, and yet at one point, it says the trigger or target (still didn't figure it out which one, since i moved to other scripts and left this one to be last one until i get help) are undefined after it selecting it randomly from the triggers (0-46 which is correct).

 

Make a box (just a box) inside the radiant and give the key the name target and at value the name of the barrel (example: barrelexplosion1). Or select a barrel go to selection and select target, it will show a line which barrel isn't good from the script.

0

Share this post


Link to post
Share on other sites

Problem:

booms[i] delete();

Edit, I add this code but I didn't test the random method so that will be up to yourself. However it gives you an idea of a solution to your problem.

// =============================================================================
//  Boomstick time! (KF)
// =============================================================================
trap2()
{
    // Get the trap trigger and the door blocking it?!
    trig = getEnt("trig2","targetname");
    door = getEnt("trap2_door", "targetname");

    assert(isDefined(trig));
    assert(isDefined(door));

    // Get the barrel triggers and do WUT?
    booms = getEntArray("br_trig_boom2","targetname");
    assert(booms.size > 0);
    for (i = 0; i < booms.size; i++)
        booms[i] thread check_barrels();

    // Wait for the trap to be activated.
    trig waittill("trigger", player); // Does not work on my end; trigger_use messed up again :/
    trig delete();

    // Open the door.
    door moveZ(-82, 3);
    door waittill("movedone");

    // Explode the barrels.
    trap2_work(booms);

    // Close the door.
    door moveZ(82, 3);
}

// =============================================================================
//  Gets an array containing index at a random position.
//  <max> The maximum entries.
//  [return] The array with shuffled indexes.
// =============================================================================
trap2_randomOrder(max)
{
    // Fill an array with all the available indexes.
    idxArr = [];
    for (i = 0; i < max; i++)
        idxArr[i] = i;

    // Create the array that is going to hold the shuffled indexes.
    shuffled = [];

    // i decrement; j increment
    j = 0;
    for (i = max - 1; i >= 0; i--)
    {
        // Pick a random index.
        idx = randomInt(idxArr.size);

        // Add the index to the current shuffled.
        shuffled[j] = idxArr[idx];
        j++;

        // Shift the array.
        for (s = idx; s < idxArr.size; s++)
        {
            // It must be higher than zero to work.
            add = (s + 1);
            if (add < idxArr.size)
                idxArr[s] = idxArr[add];
        }
        idxArr[idxArr.size - 1] = undefined;
    }

    // Return the shuffled array.
    return shuffled;
}

// =============================================================================
//  Does the actual work of exploding the barrels.
//  <booms> The trigger used to explode the barrels.
// =============================================================================
trap2_work(booms)
{
    // randIdx is an array with all the indexes at a random position;
    // therefor you can simply loop through it the normal way.
    randIdx = trap2_randomOrder(booms.size);

    for (i = 0; i < randIdx.size; i++)
    {
        x = randIdx[i];
        barrelTrig = booms[x];

        // Get the target and play an effect on it.
        barrel = getEnt(barrelTrig.target, "targetname");
        PlayFx(level.fire_barrel, barrel.origin + (0,0,32)); // The actual barrel.
        wait 2;

        // Spawn the trigger radius that kills people.
        radius = spawn("trigger_radius", barrel.origin, 0, 40, 64);

        // Play an effect again but with an earthquake this time.
        PlayFx(level.barrel_fx, barrel.origin);
        Earthquake(1, 1, barrel.origin, 125); // Barrel explosion

        // Delete the target and the trigger.
        barrel delete();
        barrelTrig delete();

        // Kill the players that are touching the kill trigger.
        players = getEntArray("player", "classname");
        for (j = 0; j < players.size; j++)
        {
            if (players[j] isTouching(radius))
            {
                players[j] suicide();
                players[j] PlaySound("explo_metal_rand");
            }
        }
    }
}
Edited by Scillman
0

Share this post


Link to post
Share on other sites

 

Problem:

booms[i] delete();

 

Yes I after I took another look this afternoon I realized  the problem was there, because having an array of 47 "spaces" and then randomly deleting one in the middle, and being picked as the next exploding barrels, would cause problems, I then tried to put a verification if that space in the array is defined, but it would still cause an error, I then moved on to other traps, as this was occupying too much time.

 

As for you're script you provided, I've tested it, but still causes the same errors. :(

0

Share this post


Link to post
Share on other sites

As for you're script you provided, I've tested it, but still causes the same errors. :(

 

Oops forgot one line, added that to my original post  ^_^

0

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  
Followers 0