Announcement

Collapse
No announcement yet.

Adding objects to the map

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Adding objects to the map

    Hi, I'm new to UScript, I have a basic question. I know I add stuff with Spawn() function, my question is: how do I add an object near my starting location at game startup?

    I know Spawn() takes starting location as its 4th (I think) argument, but how do I access my current location within the script, is there a variable that represents myself in the script so I could access my x, y values and pass them to the Spawn() function?

    And another question, if I want to add a KVehicle object, what argument should I pass to the Spawn() function, is it

    Spawn(class'KVehicle',,,starting_loc, rotattion)

    ?

    Thanks.

    #2
    First you neead an actor, so if you assign your pawn to a variable such as 'other' an object can be spawned at it's location using
    Code:
    other.location
    hope this helps.

    Comment


      #3
      Originally posted by FireCrack
      ...so if you assign your pawn to a variable such as 'other'...
      Yeah, but the problem is, how do I do that, how do I access my Pawn, is there a special variable, or do I have to iterate thru all the Actors to find the Pawn I controll? How do I access the variable for the player-controlled Pawn?

      I was going to create a new model in Maya and put it on map, near my pawn, just to test how it all works.

      I thought I would create a new class for my new model, based on one of the existing classes, then I must find a way (and a place) to initialize it all, ie to add that model to that map once the game starts. What is the best way to do it, what class should I base my initialization class on? It will then get the coords of my Pawn and spawn the new model (structure/weapon, whatever it will be) on the map.

      I have some experience with scripts and AIs, but I'm new to UScript so I don't know how this all works.

      Comment


        #4
        Well there are a couple of ways to go about this.

        1) Open up a test map in UnrealED, and have only 1 player start spot. Then put the Starting spot for your object a few feet away from the player start. Then when the game starts, the player should start a few feet away from the object.

        2) To do it without messing with the map, there is this way. NOTE this is a heavy handed way to sort of **** slap the game to do it, but here goes.

        In your game code (the code that extends xDeathMatch or whatever type of game you are extending) look in the Timer() function in the MatchInProgress State.

        function Timer() // Im not sure whats passed offhand, dont have code in front of me.
        {
        local Controller myController;
        local YourCarClass myCar;
        local vector carStart;

        foreach allactors(Class 'Controller', myController)
        {
        if(myController.IsHumanControlled()) // Im not sure of the exact function, but there is a function to determine if you are human controlled.
        {
        carStart = myController.Pawn.Location + <10,10,0>;
        myCar = Spawn(class'myCar',,,carStart,);
        }
        }
        super.Timer();
        }

        Now, the above code assumes that you are the only human controlled character in the game. Also, you might have to find a better way to add vectors, Im not up on my vector addition lately.

        Good Luck!

        Comment


          #5
          Nah, messing with the map is not the way to go for me.

          I was hoping that there was a function or a variable for a locally controlled human pawn, but I guess the code you posted will work too. Although I don't understand why you decided to put it into timer? Isn't it better to use PostBeginPlay() for example, I don't know if that's possible though, since i'm new to UScript.

          Anyway, i'm gonna try to implement your code, thanks for the reply.

          Comment


            #6
            You can put it in PostBeginPlay, I just didnt know if the controller and pawns would be spawned in that function.

            I THINK that the bots are added in the matchinprogress state, which begins after the postbeginplay has been finished.

            So, it might work with postbeginplay, but I just didnt know if the controllers and pawns would already be there.

            Comment


              #7
              Oh one more thing.

              Since this is in a timer, you might want to have a boolean that tells whether the thing has already been spawned. You know, dont want like 1400 cars show up.

              Comment


                #8
                Yep, sure, I'll have to add a bool to check if it's already done.


                I THINK that the bots are added in the matchinprogress state, which begins after the postbeginplay has been finished.
                So, it might work with postbeginplay, but I just didnt know if the controllers and pawns would already be there.
                I see, I didn't think about that. Gotta try it.

                Comment

                Working...
                X