Check if clicked player exists

  • 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!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Status
Not open for further replies.

uGim

Member
Jan 19, 2018
25
0
0
22
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_language.skript:
on leftclick:
    if clicked entity is a player:
        broadcast "it works"

For some reason this doesn't work and I have tried things like this:

code_language.skript:
on leftclick:
    set {_entity} to "%clicked player%"
    broadcast "%{_entity}%"

on leftclick:
    set {_entity} to "%clicked entity%"
    broadcast "%{_entity}%"

It always says that {_entity} is <none> no matter what or who I leftclick.
 
hmm.. you can use
code_language.skript:
on leftclick on player
but skript logs error:
A leftclick on an entity is an attack and thus not covered by the 'click' event, but the 'damage' event.
so for rightclick:
code_language.skript:
on rightclick on player
and for leftclick:
code_language.skript:
on damage
you can add condition:
code_language.skript:
on damage:
    attacker is player
    victim is player
 
Last edited:
This is not what I am looking for. As I said, I want it to tell if I am clicking on player or not.
 
its that :emoji_grinning:
code_language.skript:
#"I want it to tell if I am clicking on player or not."
on damage:
    if attacker is player:
        if victim is player:
            broadcast "You clicked on player: %victim%" #YES
        else:
            broadcast "You clicked on entity: %victim%" #NO
 
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.
 
ohhh oke :emoji_grinning: wait a minute
[doublepost=1527013804,1527013356][/doublepost]
code_language.skript:
on leftclick:
    if gamemode of player is survival:
        loop players in radius 3.5 around player:
            set {_h} to true
        if {_h} is true:
            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
 
ye.. i.. ohh god.. -_-.. i forgot... sry
try this:
code_language.skript:
on leftclick:
    if clicked entity is set:
        if gamemode of player is survival:
            loop players in radius 3.5 around player:
                set {_h} to true
            if {_h} is true:
                broadcast "&cYou miss player!"
or this is better:
code_language.skript:
on damage:
    if victim is player:
        if attacker is player:
            set {combat.hit::%attacker%} to victim
            wait 2 ticks
            delete {combat.hit::%attacker%}
    
on leftclick:
    if gamemode of player is survival:
        if {combat.hit::%player%} is not set:
            loop players in radius 3.5 around player:
                set {_h} to true
            if {_h} is true:
                broadcast "&cYou miss player!"
 
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.
 
you can use a target entity :emoji_slight_smile:

code_language.skript:
on leftclick:
    if distance between target and player is smaller than 3.5:
        broadcast "%target entity%"
 
Status
Not open for further replies.