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.

Check if clicked player exists

Discussion in 'Skript' started by uGim, May 22, 2018.

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

    uGim Member

    Joined:
    Jan 19, 2018
    Messages:
    25
    Likes Received:
    0
    I tried some ways to do it but it doesn't work. What want is that when you left-click in any situation, it tells if you are clicking a player.


    Code (Skript):
    1. on leftclick:
    2.     if clicked entity is a player:
    3.         broadcast "it works"
    4.  
    For some reason this doesn't work and I have tried things like this:

    Code (Skript):
    1. on leftclick:
    2.     set {_entity} to "%clicked player%"
    3.     broadcast "%{_entity}%"
    4.  
    5. on leftclick:
    6.     set {_entity} to "%clicked entity%"
    7.     broadcast "%{_entity}%"
    It always says that {_entity} is <none> no matter what or who I leftclick.
     
  2. MusicManSK

    MusicManSK Active Member

    Joined:
    Nov 30, 2017
    Messages:
    230
    Likes Received:
    11
    hmm.. you can use
    Code (Skript):
    1. on leftclick on player
    but skript logs error:
    so for rightclick:
    Code (Skript):
    1. on rightclick on player
    and for leftclick:
    Code (Skript):
    1. on damage
    you can add condition:
    Code (Skript):
    1.  
    2. on damage:
    3.     attacker is player
    4.     victim is player
    5.  
     
    #2 MusicManSK, May 22, 2018
    Last edited: May 22, 2018
  3. uGim

    uGim Member

    Joined:
    Jan 19, 2018
    Messages:
    25
    Likes Received:
    0
    This is not what I am looking for. As I said, I want it to tell if I am clicking on player or not.
     
  4. MusicManSK

    MusicManSK Active Member

    Joined:
    Nov 30, 2017
    Messages:
    230
    Likes Received:
    11
    its that :emoji_grinning:
    Code (Skript):
    1. #"I want it to tell if I am clicking on player or not."
    2. on damage:
    3.     if attacker is player:
    4.         if victim is player:
    5.             broadcast "You clicked on player: %victim%" #YES
    6.         else:
    7.             broadcast "You clicked on entity: %victim%" #NO
     
  5. uGim

    uGim Member

    Joined:
    Jan 19, 2018
    Messages:
    25
    Likes Received:
    0
    You don't seem to get it. It should also tell if you are not attacking a player. Make it so it will broadcast when you don't hit a player.
    For example, if you missed your attack and didn't get the hit, it should tell you didn't hit a player. I am looking for a left click event, NOT a damage event.
     
  6. MusicManSK

    MusicManSK Active Member

    Joined:
    Nov 30, 2017
    Messages:
    230
    Likes Received:
    11
    ohhh oke :emoji_grinning: wait a minute
    --- Double Post Merged, May 22, 2018, Original Post Date: May 22, 2018 ---
    Code (Skript):
    1. on leftclick:
    2.     if gamemode of player is survival:
    3.         loop players in radius 3.5 around player:
    4.             set {_h} to true
    5.         if {_h} is true:
    6.             broadcast "&cYou miss player!"
    maybe this..
    but you need to put thre som conditions.. like world.. or if you want it for PvP make {pvp.joined::%player%} variable and check if is player conected
     
  7. uGim

    uGim Member

    Joined:
    Jan 19, 2018
    Messages:
    25
    Likes Received:
    0
    Well now if I hit the player it still says "you miss player!"
     
  8. MusicManSK

    MusicManSK Active Member

    Joined:
    Nov 30, 2017
    Messages:
    230
    Likes Received:
    11
    ye.. i.. ohh god.. -_-.. i forgot... sry
    try this:
    Code (Skript):
    1. on leftclick:
    2.     if clicked entity is set:
    3.         if gamemode of player is survival:
    4.             loop players in radius 3.5 around player:
    5.                 set {_h} to true
    6.             if {_h} is true:
    7.                 broadcast "&cYou miss player!"
    or this is better:
    Code (Skript):
    1. on damage:
    2.     if victim is player:
    3.         if attacker is player:
    4.             set {combat.hit::%attacker%} to victim
    5.             wait 2 ticks
    6.             delete {combat.hit::%attacker%}
    7.    
    8. on leftclick:
    9.     if gamemode of player is survival:
    10.         if {combat.hit::%player%} is not set:
    11.             loop players in radius 3.5 around player:
    12.                 set {_h} to true
    13.             if {_h} is true:
    14.                 broadcast "&cYou miss player!"
     
  9. Mr_Simba

    Mr_Simba King of the Pridelands
    Supporter

    Joined:
    Dec 9, 2016
    Messages:
    256
    Likes Received:
    56
    Medals:
    Yeah, there isn't exactly a general singular event you can use to do this without some sort of weird code. To properly detect if they hit a player you'll need to use a damage event but to detect any click you'll need a general left click event. A solution like @MusicManSK's second example in the last post is basically what you'd need -- a variable to let you know cross-event whether or not the player damaged with that same click.
     
  10. Lukhausen

    Lukhausen Active Member

    Joined:
    Mar 20, 2017
    Messages:
    145
    Likes Received:
    11
    you can use a target entity :emoji_slight_smile:

    Code (Skript):
    1. on leftclick:
    2.     if distance between target and player is smaller than 3.5:
    3.         broadcast "%target entity%"
     
Thread Status:
Not open for further replies.

Share This Page

Loading...