1. Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

  2. LOOKING FOR A VERSION OF SKRIPT?

    You can always check out our Wiki for downloads and any other information about Skript!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Calculate coordinates at a target block

Discussion in 'Skript' started by AkroDogy2005, May 20, 2022.

Thread Status:
Not open for further replies.
  1. AkroDogy2005

    AkroDogy2005 Member

    Joined:
    Apr 20, 2018
    Messages:
    18
    Likes Received:
    1
    Hi, I'm trying to make a calculation so that when the arrow reaches the center point of the block it receives 3 points, farther from the center 2 points and farthest from the center of the block 1 point.
    This is my actual code:
    Code (Text):
    1. on projectile hit:
    2.     if {shape::*} is true:
    3.         if {game::*} is true:
    4.             projectile is arrow:
    5.                 shooter is player:
    6.                     if event.getHitBlock() is target:
    7.                         set {_x::*} to x-location of projectile
    8.                         set {_y::*} to y-location of projectile
    9.                         set {_z::*} to z-location of projectile
    10.                         set {_xar1} to "%event-block's x-location%"
    11.                         set {_yar1} to "%event-block's y-location%"
    12.                         set {_zar1} to "%event-block's z-location%"
    13.                         message "Hit coords %{_x::*}% %{_xar1}%  %{_y::*}% %{_yar1}%  %{_z::*}% %{_zar1}%" to shooter
    14.                         message "&e+1 point" to shooter
    15.                         if {_x::*} > {_xar1}+0.5:
    16.                             message "test"
    17.     else:
    18.         cancel event
    19.        
    When test it i don t get any "test" message:
    Can someone help me with?
     

    Attached Files:

  2. BanditEagle

    BanditEagle Active Member

    Joined:
    May 3, 2021
    Messages:
    55
    Likes Received:
    0
    Try this:
    Code (Text):
    1. on projectile hit:
    2.     if {shape::*} is true:
    3.         if {game::*} is true:
    4.             projectile is arrow:
    5.                 shooter is player:
    6.                     if event.getHitBlock() is target:
    7.                         set {_x} to x-location of projectile
    8.                         set {_y} to y-location of projectile
    9.                         set {_z} to z-location of projectile
    10.                         set {_xar1} to "%event-block's x-location%"
    11.                         set {_yar1} to "%event-block's y-location%"
    12.                         set {_zar1} to "%event-block's z-location%"
    13.                         message "Hit coords %{_x}% %{_xar1}%  %{_y}% %{_yar1}%  %{_z}% %{_zar1}%" to shooter
    14.                         message "&e+1 point" to shooter
    15.                         if {_x} > {_xar1}+0.5:
    16.                             message "test"
    17.     else:
    18.         cancel event
     
  3. AKRODOGY

    AKRODOGY Active Member

    Joined:
    Mar 20, 2018
    Messages:
    52
    Likes Received:
    2
    Tried it but the variable is not working, if i put {_x} instead of {_x::*} i ll not get the test message and on the first message with all coords i ll get a <none> instead of a coord
     
  4. BanditEagle

    BanditEagle Active Member

    Joined:
    May 3, 2021
    Messages:
    55
    Likes Received:
    0
    oh i know why now. you are comparing a number with a string, since you set {_xar1} as a string while {_x::*} as a number. If you make {_xar1} to a number as well it should work.
     
  5. AkroDogy2005

    AkroDogy2005 Member

    Joined:
    Apr 20, 2018
    Messages:
    18
    Likes Received:
    1
    nop, same thing it doesn t display any message like "test"
     
  6. David09sm

    David09sm Member

    Joined:
    May 21, 2022
    Messages:
    1
    Likes Received:
    0
    //How to print to console: console.log(JSON.stringify(13));
    // http://paulirish.com/2011/requestanimationframe-for-smart-animating
    //shim layer with setTimeout fallback
    window.requestAnimFrame = (function(){
    return window.requestAnimationFrame ||
    window.webkitRequestAnimationFrame ||
    window.mozRequestAnimationFrame ||
    window.oRequestAnimationFrame ||
    window.msRequestAnimationFrame ||
    function(callback){
    window.setTimeout(callback, 1000 / 60);
    };
    })();
    //namespace the game
    var SHOOT ={
    //setting up the values
    WIDTH: 400,
    HEIGHT: 400,
    entities: [], //Targets and bullet entities
    score: {
    shot: 0,
    hit: 0,
    escaped: 0,
    accuracy: 0
    },
    canvas: null,
    ctx: null,
    nextTarget: 100,
    offset: {
    top: 0,
    left: 0
    },
    cannon: {
    w: function(){return SHOOT.WIDTH / 5;},
    h: function(){return SHOOT.HEIGHT / 5;},
    x_loc: function(){return SHOOT.WIDTH * 0.4;},
    y_loc: function(){return SHOOT.HEIGHT * 0.8;}
    },

    init: function(){
    SHOOT.canvas = document.getElementsByTagName('canvas')[0];//Setting up canvas element
    //Must set canvas width otherwise space bar clicker browser automatically defaults 320 x 200
    SHOOT.canvas.width = SHOOT.WIDTH;
    SHOOT.canvas.height = SHOOT.HEIGHT;
    SHOOT.ctx = SHOOT.canvas.getContext('2d');//Setting up canvas context




    //Need something to listen for clicks
    window.addEventListener('click',function(e){
    e.preventDefault();
    SHOOT.Input.set(e);
    },false);


    //call the loop
    SHOOT.loop();
    },
     
  7. AkroDogy2005

    AkroDogy2005 Member

    Joined:
    Apr 20, 2018
    Messages:
    18
    Likes Received:
    1
    Hi, thanks for responding but I don't think the code is for me, im using skript and i saw that code written by you is for web browsers.
     
Thread Status:
Not open for further replies.

Share This Page

Loading...