Solved How to define data to a projectile?. [Weapons skript]

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

krainser

Member
Jan 27, 2017
60
3
3
35
Argentina
Skript Version: 2.2dev23
Skript Author: Bensku
Minecraft Version: 1.10.2
---
Full Code:
I saw this code in another help post. [ https://forums.skunity.com/threads/particle-trail.2646/#post-6204 ]
code_language.skript:
on entity shoot:
    if event-entity is a player:
        #Arrow projectile:
 
        #Make it so bows will only shoot snowballs :P
 
        broadcast "%shot arrow%"
        spawn snowball at location above player
        #Skript doesn't have a proper way to define an entity. So I'm using this spawning method workaround.
 
        #I might make an effect to define a projectile and create data on top of that projectile, Like name etc.
 
        set shot projectile to last spawned snowball
        push shot projectile in direction of player at speed (arrow speed + 0.25)
        broadcast "%shot projectile%"
I would like to define data to a proyectile (Name of the shooter and damage or a number) so, in a "on damage" event it'll check for the data of the proyectile.
But i looked in the docs and forums, doesnt seems to be posible. Any ideas?

Other Useful Info:
I can add any addons, that isnt a problem.

Addons using :
skRayFall 1.9.7 , SkQuery 1.10 , TuSKe 1.7.4

Have you tried searching the docs? Yes
Have you tried searching the forums? Yes
What other methods have you tried to fix it?
I tryied with this code
Java:
on right click using stone hoe:
    if the name of player's tool is coloured "&7Pistol":
        shoot snowball at speed 40
on right click using a gold hoe:
    if the name of player's tool is coloured "&7Sniper":
        shoot snowball at speed 70
on damage:
    projectile is a snowball
    if the name of shooter's tool is coloured "&7Pistol":
        damage victim by 1 heart
    if the name of shooter's tool is coloured "&7Sniper":
        damage victim by 3 hearts
But, is vulnerable. A player can shoot with a pistol and change to a sniper before the projectile hits the victim, and the damage event will check the Sniper instead of the pistol :/


**SOLVED**
I use the TagAPI [https://forums.skunity.com/resources/tagapi.89/] from Mr_Simba, and SkStuff. Here is my test code that already works!
code_language.skript:
command /gun:
    trigger:
        give a stone hoe named coloured "&7Pistol" to player
        give a gold hoe named coloured "&7Sniper" to player

on right click using stone hoe:
    if the name of player's tool is coloured "&7Pistol":
        spawn snowball at player's head  #Note that the color is &c
        push last spawned snowball in direction of player at speed 1
        setKeyValueTag(last spawned snowball, "pistol", "%player%")
        set {_m} to getKeyValueTag(last spawned snowball, "pistol")
        send "&cFired: %{_m}%"
        
on right click using a gold hoe:
    if the name of player's tool is coloured "&7Sniper":
        spawn snowball at player's head  #Note that the color is &c
        push last spawned snowball in direction of player at speed 1
        setKeyValueTag(last spawned snowball, "sniper", "%player%")
        set {_m} to getKeyValueTag(last spawned snowball, "sniper")
        send "&2Fired: %{_m}%"
on damage:
    projectile exists
    if hasKeyValueTag(projectile, "pistol") is true:
        set {_player} to getKeyValueTag(last spawned snowball, "pistol") parsed as a player
        set the shooter to {_player}
        broadcast "&c->%shooter%"
        stop
    if hasKeyValueTag(projectile, "sniper") is true:
        set {_player} to getKeyValueTag(last spawned snowball, "sniper") parsed as a player
        set the shooter to {_player}
        broadcast "&2->%shooter%"
        stop
 
Last edited:
"I would like to define data to a proyectile (Name of the shooter and damage or a number) so, in a "on damage" event it'll check for the data of the proyectile."

You mean
code_language.skript:
%damage% & %shooter%
 
"I would like to define data to a proyectile (Name of the shooter and damage or a number) so, in a "on damage" event it'll check for the data of the proyectile."

You mean
code_language.skript:
%damage% & %shooter%
Yest, that's right, but i would like to save that data on the projectile. Or make the projectile unique in some way
 
code_language.skript:
on right click using stone hoe:
    if the name of player's tool is coloured "&7Pistol":
        shoot snowball coloured named "&c%player%" at speed 40   #Note that the color is &c
on right click using a gold hoe:
    if the name of player's tool is coloured "&7Sniper":
        shoot snowball coloured named "&2%player%" at speed 70   #Note that the color is &2
on damage:
    projectile is a snowball
    if the name of the projectile is coloured "&c%shooter%":     #Note that the color is &c
        damage victim by 1 heart
    if the name of the projectile is coloured "&2%shooter%":     #Note that the color is &2
        damage victim by 3 hearts
 
Use metadata from Skellett or something similar like my TagAPI to tag the projectile then check its tag afterwards.
You are the best lion in the world.
[doublepost=1491759979,1491706140][/doublepost]Hi, i have some problems in the death by snowball.. The damage is deal with "damage player by 2 hearts" so, in the "on death" event doesnt read the player's as the attacker, because the damage was deal by Skript. Anyway to set the attacker to the shooter? :/ Thanks.
 
code_language.skript:
on damage:
    projectile is a snowball
    if the name of the projectile is coloured "&c%shooter%":     #Note that the color is &c
        set {gunshot::%victim%} to "%attacker%"
        damage victim by 1 heart
    if the name of the projectile is coloured "&2%shooter%":     #Note that the color is &2
        set {gunshot::%victim%} to "%attacker%"
        damage victim by 3 hearts
       
on death of player:
    if {gunshot::%event-entity%} is set:
        message "Killer: %{gunshot::%event-entity%}%"
        delete {gunshot::%event-entity%}
 
This can probably be made much simpler, try just this and see if it works:

code_language.skript:
on right click using stone hoe:
    if player's tool's name is "&7Pistol":
        shoot snowball from player at speed 40
        setKeyValueTag(last shot snowball, "Damage", "1")
on right click using a gold hoe:
    if player's tool's name is "&7Sniper":
        shoot snowball from player at speed 70
        setKeyValueTag(last shot snowball, "Damage", "3")
on damage:
    projectile is a snowball
    hasKeyValueTag(projectile, "Damage") is true
    set damage to "%getKeyValueTag(projectile, ""Damage"")%" parsed as an integer
 
Status
Not open for further replies.