Need to add more than one ship?

Have questions about CoD4 mapping that aren't covered in the tutorials section? Post here!

Moderator: Core Staff

Post Reply
Reality
CJ Newbie
CJ Newbie
Posts: 51
Joined: May 3rd, 2011, 9:57 pm

Need to add more than one ship?

Post by Reality » November 5th, 2011, 2:25 pm

I have a code for a space ship, at the moment I can only add one..I'm looking to add more but it shows an error 'getent used with one or more enitity' how can i make it so i can have multiple ships? This is the start of the code, and the only bit that needs changing, im not released it all because it wasn't scripted or belong to me BUT i do have permission to use it.

Code: Select all

mainfi()
{
 
        level.spaceFighterHealth = 1000;
        //thread constant_gravity();
 
        spacefighter_trigs = getEnt("spacefighter_trig", "targetname");
        spacefighter_trigs thread waitForPilot();
}
 
waitForPilot()
{
        fighter = getEnt("fighter", "targetname");
        fighter.isSpaceFighter = true;
        fighter thread preFlight();
 
        while(1)
        {
                self waittill("trigger", player);
 
                if(fighter.hasPilot)
                        continue;
 
                if(isDefined(player.isPiloting))
                        continue;
 
                if(player.sessionstate != "playing")
                        continue;
 
                if(!isAlive(player) || !isPlayer(player))
                        continue;
 
                if(isDefined(player.pers["isBot"]))
                        continue;
 
                if(player getStance() == "prone")
                        continue;
 
                fighter.hasPilot = true;
                fighter.owner = player;
                player.isPiloting = true;
                player thread pilotFighter(fighter);
        }
}

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13313
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: Need to add more than one ship?

Post by Drofder2004 » November 5th, 2011, 3:19 pm

Mapping:

Make sure all 'ships' have NO targetname.
Make sure all 'triggers' have a targetname of "spacefighter_trig".

Now, select the first 'trigger' then select the 'fighter' for that trigger, then click W.
They should now be linked by a line in Radiant.

Scripting:

Code: Select all

    mainfi()
    {
     
            level.spaceFighterHealth = 1000;
            //thread constant_gravity();
     
            spacefighter_trigs = getEntArray("spacefighter_trig", "targetname");
            for(i=0;i<spacefighter_trigs.size;i++)
                  spacefighter_trigs[i] thread waitForPilot();
    }
     
    waitForPilot()
    {
            fighter = getEnt(self.target, "targetname");
            fighter.isSpaceFighter = true;
            fighter thread preFlight();
     
            while(1)
            {
                    self waittill("trigger", player);
     
                    if(fighter.hasPilot)
                            continue;
     
                    if(isDefined(player.isPiloting))
                            continue;
     
                    if(player.sessionstate != "playing")
                            continue;
     
                    if(!isAlive(player) || !isPlayer(player))
                            continue;
     
                    if(isDefined(player.pers["isBot"]))
                            continue;
     
                    if(player getStance() == "prone")
                            continue;
     
                    fighter.hasPilot = true;
                    fighter.owner = player;
                    player.isPiloting = true;
                    player thread pilotFighter(fighter);
            }
    }
 
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

Reality
CJ Newbie
CJ Newbie
Posts: 51
Joined: May 3rd, 2011, 9:57 pm

Re: Need to add more than one ship?

Post by Reality » November 5th, 2011, 4:15 pm

Drofder2004 wrote:Mapping:

Make sure all 'ships' have NO targetname.
Make sure all 'triggers' have a targetname of "spacefighter_trig".

Now, select the first 'trigger' then select the 'fighter' for that trigger, then click W.
They should now be linked by a line in Radiant.

Scripting:

Code: Select all

    mainfi()
    {
     
            level.spaceFighterHealth = 1000;
            //thread constant_gravity();
     
            spacefighter_trigs = getEntArray("spacefighter_trig", "targetname");
            for(i=0;i<spacefighter_trigs.size;i++)
                  spacefighter_trigs[i] thread waitForPilot();
    }
     
    waitForPilot()
    {
            fighter = getEnt(self.target, "targetname");
            fighter.isSpaceFighter = true;
            fighter thread preFlight();
     
            while(1)
            {
                    self waittill("trigger", player);
     
                    if(fighter.hasPilot)
                            continue;
     
                    if(isDefined(player.isPiloting))
                            continue;
     
                    if(player.sessionstate != "playing")
                            continue;
     
                    if(!isAlive(player) || !isPlayer(player))
                            continue;
     
                    if(isDefined(player.pers["isBot"]))
                            continue;
     
                    if(player getStance() == "prone")
                            continue;
     
                    fighter.hasPilot = true;
                    fighter.owner = player;
                    player.isPiloting = true;
                    player thread pilotFighter(fighter);
            }
    }
 

It didn't work I get an error 'array is not an object' Ignore the Array(self.target... I tried it with and without 'Array' there.

Image

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13313
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: Need to add more than one ship?

Post by Drofder2004 » November 5th, 2011, 7:05 pm

Edit:
After reading the error again, it seems to read that "self.target" is being defined as an array (more specifically 'self').
I have reread the code a few times, and can see no reason for the
My guess is a mapping error.

Your map entities should be:

triggers
---------
targetname : spacefighter_trig
target : auto<#> (where <#> is a incrementing number)

ships
------
targetname : auto<#> (<#> incrementing as above)

The ships should have a line being drawn from them to the trigger, with an arrow pointing towards ths ship.

If you are 100% sure on the setup of the map, and the compile is correct and your GSC is correctly updating (use a print to check) then use "setDvar("fighter", self)" inside the waitForPilot thread to see what self is being defined as. (/fighter in console).
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

Rain
CJ Wannabe
CJ Wannabe
Posts: 1
Joined: November 5th, 2011, 8:07 pm

Re: Need to add more than one ship?

Post by Rain » November 5th, 2011, 8:09 pm

This error, was indeed caused by a error in the mapping, but I helped him out in Radiant and its all fixed. Thanks Drofder :wink:

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13313
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: Need to add more than one ship?

Post by Drofder2004 » November 5th, 2011, 8:58 pm

No probs.
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

Post Reply

Who is online

Users browsing this forum: No registered users and 34 guests