1. Hey Guest, is it this your first time on the forums?

    Visit the Beginner's Box

    Introduce yourself, read some of the ins and outs of the community, access to useful links and information.

    Dismiss Notice

[SOLVED] Setting the position at which a summoned blob spawns

Discussion in 'Modding Help' started by Frikman, Jul 12, 2016.

  1. Frikman

    Frikman Bison Rider

    Messages:
    162
    I've been making a lot of questions lately. So, thanks to FUN ctf I've been working on scrolls that let you summon blobs, but the problem with that it's that blobs will spawn always on the position of the scroll user, which is bad if I want to summon, say, sharks. I've been trying to play around with the lines that reference positions, but I can't get it to work.

    On the video I use a scroll, and I'd like to know how could I make the chickens (or blobs) spawn on the position of the stone block (or any different position, really).

     

    Attached Files:

  2. makmoud98

    makmoud98 You are already DEAD Forum Moderator Staff Alumni Tester

    Messages:
    586
    well if you look at line 45. this is where the blob is created.
    [​IMG]
    the server_CreateBlob function has 3 parameters. the blob name, the team number, and the position. in this case. the chickens are being created at this's position in this case this is the scroll.
    in reality you could replace this.getPosition() with any vector. like Vec2f(236, 150) for example (just random numbers). or maybe in this case, you could replace it with caller.getAimPos() (this is just where the person who used the scripts' cursor is). the caller blob is defined on line 27 here
    [​IMG]

    if you want to get the position of a specific tile, you can look at the ScrollMidas script for example. Its not very simple because you need to iterate through all the tiles around you and define which tile you would want to pick for spawning and you need to check for what type of tile it is and blah blah, it gets a bit complicated, but i can get more into detail if you want.
    [​IMG]

    basically all I am saying is that you could put ANY vector into that parameter. if you want to get creative with it, it will take more work. but lets say for example I want to spawn a chicken at the position of every player in the game, it would look something like this..
    [​IMG]

    when I first started modding, i began messing around with scrolls the most. anyway, hope this helps.
     
  3. Frikman

    Frikman Bison Rider

    Messages:
    162
    Ain't that nice. Thanks man, I tried setting a position with vectors and it wasn't working really well, but now I can make silly stuff like video related :^)

     
    makmoud98 likes this.
  4. blackjoker77777

    blackjoker77777 Haxor Tester
    1. Zen Laboratories

    Messages:
    441
    You can as well try something like this :
    1) Creating a variable, containing the number of tiles (based on the scroll position); a positive one for the right or a negative one for the left.
    (in this example I'm just covering where you want to spawn it on the X axis -Left and Right-, feel free to add one for the Y if you want to change the altitude it spawns at).
    upload_2016-7-12_21-58-24.png
    2) Generating the new position of the chicken, in a form of a vector (named position_ in this example).
    upload_2016-7-12_21-59-54.png
    As explained in the comments, we're multiplying the number of blocks with 8 because a block is made of 8 pixels.
    (Reminding you again that you still can change the Y position as well, just be creative).
    3) Change the position in which the chicken would spawn at by changing this line:
    upload_2016-7-12_22-5-30.png
    As you can see, we set the last parameter to the vector we already created in step 2 .
    4) Have fun.
    PS: If you need to make it so that it automatically detects whether it should spawn the chicken on your left or on your right, then you could use the boolean this.isFacingLeft() with a simple if/else statement.
    Something along the lines:
    //in this example, the x_blocks has always a positive value.
    if (this.isFacingLeft())
    {
    //we're facing left, then the X position of the chicken should be less than our blobs' (named this ) position.
    Vec2f position_(this.getPosition().x - (x_blocks*8),this.getPosition().y)
    }
    else
    {
    //we're facing right then the X position is supposed to be bigger than the one of our blob.
    Vec2f position_(this.getPosition().x + (x_blocks*8),this.getPosition().y)
    }
    Please note that I've written this in a hurry so forgive me in case I made any mistakes.
     

    Attached Files:

    Last edited: Jul 12, 2016