I am making a map that when someone finds a key (a squid spawn egg named key) and they spawn it, it will say the person who is closest to the squid has found the key. What I have so far is a repeating command block that says /execute @e[type=Squid,name=Key] ~ ~ ~ /testfor @p which testfor the player closest to the spawned squid named key. But I don't know how to make a command block say /say (player who is closest to the spawned squid) found the key. Hope this makes sense.
I don't need the squid to talk. But thank you. Say my username was paytonmoreno and when I spawned that squid the commandblock will find the squid and then testfor the closest person to that squid. Using /say or /tell, I want it to say paytonmoreno has found the key. hope this makes more sence.
It would be much easier to determine who picked the key up rather than testing for the closest player to the squid when they spawn it. That can cause issues since the player may spawn the squid slightly away from them and there may be another player within a closer range of the squid.
First, create a scoreboard objective named "key" or something. Then, set that scoreboard objective to 1 for any player that has the key present in their inventory:
/scoreboard players set @a key 1 {Inventory:[{id:"minecraft:spawn_egg",Count:1b,tag:{EntityTag:{id:"minecraft:squid"}}}]}
Then, run a /testfor command that tests if the squid exists, in which case it will execute the /tellraw command to announce that the player has found the key, using @p[score_key_min=1,score_key=1] as the selector. Finally, reset the key objective for all players so that it is reset for the next time you wish to use it. Hope this helps.
Yea. I was thinking testing for it in there inventory after I wrote this. Could you give me the command fully. I need it to testfor who got the squid named Their_2_Iron then place a block depending on the team they are on. There is also. 7 other squids named something different in the map. I need it to testfor all the squid with different names at the same time which I can do with different command blocks. So I got to testfor the name as well. Thank you
This should work; run this command on a clock (repeating command block):
/scoreboard players set @a key 1 {Inventory:[{id:"minecraft:spawn_egg",Count:1b,tag:{EntityTag:{id:"minecraft:squid",CustomName:"<insert_name_here>"}}}]}
Run these commands in succession (along a chain); the first command block is run on a clock (repeating command block), the second and third are chain command blocks set as "Conditional":
/testfor @e[type=squid,name=<insert_name_here>]
/tellraw @a <your tellraw command> (use @a[score_key_min=1,score_key=1] as the selector)
/scoreboard players set @a[score_key_min=1,score_key=1] key 0
For each key you have, simply set the scoreboard objective to a different value. For example; the first key will set and test for a key value of 1, the second key a value of 2, and so on. Then change the selector based on this value.
I am making a map that when someone finds a key (a squid spawn egg named key) and they spawn it, it will say the person who is closest to the squid has found the key. What I have so far is a repeating command block that says /execute @e[type=Squid,name=Key] ~ ~ ~ /testfor @p which testfor the player closest to the spawned squid named key. But I don't know how to make a command block say /say (player who is closest to the spawned squid) found the key. Hope this makes sense.
I don't need the squid to talk. But thank you. Say my username was paytonmoreno and when I spawned that squid the commandblock will find the squid and then testfor the closest person to that squid. Using /say or /tell, I want it to say paytonmoreno has found the key. hope this makes more sence.
It would be much easier to determine who picked the key up rather than testing for the closest player to the squid when they spawn it. That can cause issues since the player may spawn the squid slightly away from them and there may be another player within a closer range of the squid.
First, create a scoreboard objective named "key" or something. Then, set that scoreboard objective to 1 for any player that has the key present in their inventory:
Then, run a /testfor command that tests if the squid exists, in which case it will execute the /tellraw command to announce that the player has found the key, using @p[score_key_min=1,score_key=1] as the selector. Finally, reset the key objective for all players so that it is reset for the next time you wish to use it. Hope this helps.
Yea. I was thinking testing for it in there inventory after I wrote this. Could you give me the command fully. I need it to testfor who got the squid named Their_2_Iron then place a block depending on the team they are on. There is also. 7 other squids named something different in the map. I need it to testfor all the squid with different names at the same time which I can do with different command blocks. So I got to testfor the name as well. Thank you
This should work; run this command on a clock (repeating command block):
Run these commands in succession (along a chain); the first command block is run on a clock (repeating command block), the second and third are chain command blocks set as "Conditional":
For each key you have, simply set the scoreboard objective to a different value. For example; the first key will set and test for a key value of 1, the second key a value of 2, and so on. Then change the selector based on this value.