Automatically detecting items.

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

    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.
Feb 25, 2017
21
1
0
So i currently have a mobcoin skript, where when monsters die they can drop coins to be redeemed for items. However, currently I have it so that when you gain mobcoins you need to do a command to redeem them. I want to make it so that as soon as it enters your inventory you gain 1 mobcoin to your balance.

code_language.skript:
#   
#                            W E L C O M E   T O   
#
#                                  MOBCOINS
#
#                C R E A T E D   B Y :   EXPLOSIVE
#
#    (! Please don't edit the settings below unless you know what you are doing !)
Options:
    
#Name of the GUI that opens when the command is run.
  GUIName: <cyan><bold>MobCoins
#Message sent when a player tries to view the plugin list.
  pluginMessage: <lime>I'm sorry, we protect our plug-ins from being shown for safety purposes. For more information on plug-ins, contact the owner or any administrators.
#Message sent when a player tries to use a disabled bukkit command.
  bukkitMessage: <lime>I'm sorry, we protect our bukkit commands for safety purposes. For more information on bukkit commands, contact the owner or any administrators.

  P: &8&m---*---&8(&f&l!&8) &b&lMobCoins &8(&f&l!&8)&8&m---*---
  UP: &8&m---*---&8(&f&l!&8)&8&m---------&8(&f&l!&8)&8&m---*---
  Perm: coins.permission

  Prefix: &8[&a&lNight&7&lVision&8]
  Prefix3: &8[&a&lWater&7&lBreathing&8]
  JoinMessage: &7Toggle night vision with /nv!
  EnableMessage: &7Night vision has been enabled. Do /nv to toggle!
  DisableMessage: &7Night vision has been disabled. Do /nv to toggle!
  EnableMessage3: &7Water breathing has been enabled. Do /water to toggle!
  DisableMessage3: &7Water breathing has been disabled. Do /water to toggle!
  NoPermission: &cNo Permission!

      
#End of configuration!

script options:
    $ use permissions

variables:
    {coins.%player%} = 0
    {nightvision.mode.%player%} = "False"
    
command /coins [<text>] [<player>] [<number>]:
    trigger:
        if arg 1 is not set:
            send "{@P}"
            send "&7&oYour coins balance is:"
            send ""
            send "&bCoins &3» &f%{coins.%player%}%"
        if arg 1 is "help":
            if player has permission "{@Perm}":
                send "{@P}"
                send "&7&oHere you can view the commands!"
                send ""
                send "&b/coins give (player) (number)"
                send "&b/coins view (player)"
                send "&b/coins remove (player) (number)"
                send "&b/coins reset (player)"
                send "&b/coins shop"
                send "&b/coins transfer"               
                send "{@UP}"               
        if arg 1 is "give":
            if player has permission "{@Perm}":
                send "{@P}"
                send "&7&oPlease give an &aIGN &7and a &aNumber!"
                send ""
                send "{@UP}"
            if arg 2 is set:   
                if player has permission "{@Perm}":
                    send "{@P}"
                    send "&7&oPlease give a &anumber!"
                    send ""
                    send "{@UP}"   
                if arg 3 is set:
                    if player has permission "{@Perm}":
                        add number arg to {coins.%arg-2%}
                        send "{@P}"
                        send "&7&oSuccess you have given a player coins!"
                        send ""
                        send "&a%arg-2% &7has been given &a%number arg%"
                        send "{@UP}"                   
                        send "{@P}" to arg-2
                        send "&7&oYou have been given coins" to arg-2
                        send "" to arg-2
                        send "&a%player% &7has given you &a%number arg% &7coins" to arg-2
                        send "{@UP}" to arg-2                       
            if player does not have permission "{@Perm}":
                send "&8(&c&l!&8)  &cYou don't have permission to run this command."
        if arg 1 is "view":
            send "{@P}"
            send "&7&oPlease give a &aname!"
            send ""
            send "{@UP}"
            if arg 2 is set:
                send "{@P}"
                send "&7&oHere you can see &a%arg-2% &7coins"
                send ""
                send "&bCoins &3» &f%{coins.%arg-2%}%"
        if arg 1 is "remove":
            if player has permission "{@Perm}":
                send "{@P}"
                send "&7&oPlease give an &aIGN &7and a &aNumber!"
                send ""
                send "{@UP}"               
            if arg 2 is set:   
                if player has permission "{@Perm}":
                    send "{@P}"
                    send "&7&oPlease give a &anumber!"
                    send ""
                    send "{@UP}"
                if arg 3 is set:
                    if player has permission "{@Perm}":
                        remove number arg from {coins.%arg-2%}
                        send "{@P}"
                        send "&7&oSuccess you have removed coins from a player!"
                        send ""
                        send "&a%arg-2% &7has lost &a%number arg%"
                        send "{@UP}"                   
                        send "{@P}" to arg-2
                        send "&7&oCoins have been taken from your account!" to arg-2
                        send "" to arg-2
                        send "&a%player% &7has taken &a%number arg% &7coins. &7Your balance is now &a%{coins.%arg-2%}%" to arg-2
                        send "{@UP}" to arg-2                       
            if player does not have permission "{@Perm}":
                send "&8(&c&l!&8)  &cYou don't have permission to run this command."   
        if arg 1 is "reset":       
            if player has permission "{@Perm}":
                send "{@P}"
                send "&7&oPlease give an &aIGN!"
                send ""
                send "{@UP}"
            if arg 2 is set:   
                if player has permission "{@Perm}":
                    send "{@P}"
                    send "&7&oPlease give a &anumber!"
                    send ""
                    send "{@UP}"               
                if arg 3 is set:
                    if player has permission "{@Perm}":
                        set {coins.%arg-2%} to 0
                        send "{@P}"
                        send "&7&oSuccess you have reset a players coin balance!"
                        send ""
                        send "&a%arg-2% &7has had their coins reset!"
                        send "{@UP}"
                        send "{@P}" to arg-2
                        send "&7&oYour coins balance has been reset!" to arg-2
                        send "" to arg-2
                        send "&a%player% &7has reset your balance!" to arg-2
                        send "{@UP}" to arg-2
                    
                    
        if arg 1 is "shop":       
            send "{@P}"
            send "&7&oOpening Shop!"
            send ""
            open chest with 1 row named "{@GUIName}" to player
            wait a tick
            format slot 0 of player with 64 of tnt named "<gold><bold>TnT <gold>- 120mc" to close then run [make player execute command "/tntcoins"]
            format slot 1 of player with 64 of obsidian named "<gold><bold>Obsidian <gold>- 40mc" to close then run [make player execute command "/obsidiancoins"]
            format slot 2 of player with 1 of creeper spawn egg named "<gold><bold>Creeper Egg <gold>- 300mc" to close then run [make player execute command "/creepercoins"]
            format slot 3 of player with 1 of enchanted golden apple named "<gold><bold>Super Golden Apple <gold>- 150mc" to close then run [make player execute command "/gapcoins"]
            format slot 4 of player with 1 of hopper named "<gold><bold>Hopper <gold>- 70mc" to close then run [make player execute command "/hoppercoins"]
            format slot 5 of player with 1 of book and quill named "<gold><bold>/nick <gold>- 1000mc" to close then run [make player execute command "/nickcoins"]
            format slot 6 of player with 1 of steak named "<gold><bold>/feed <gold>- 1500mc" to close then run [make player execute command "/feedcoins"]
            format slot 7 of player with 1 of water bottle named "<gold><bold>/nv <gold>- 2000mc" to close then run [make player execute command "/nightcoins"]
            format slot 8 of player with 1 of nether star named "<gold><bold>Demi-God Rank <gold>- 20,000mc" to close then run [make player execute command "/rankcoins"]       
            send ""
            send "{@UP}"   

        if arg 1 is "transfer":
            set {_mobcoins} to number of sunflower named "<gold>MobCoin" in player's inventory
            add {_mobcoins} to {coins.%player%}
            remove {_mobcoins} of sunflower named "<gold>MobCoin" from player's inventory
            send "&6You just got &c%{_mobcoins}% Coins!"
                

                        
                    
#Send Message Command
command /sendmessage <player> <text>:
  description: Send a message to the specified player.
  usage: /sendmessage <player> <message>
  executable by: console
  aliases: /sendmsg
  trigger:
    send arg 2 to arg 1       

    
    
command /tntcoins:
  permission: "coins.tnt"
  trigger:
    if {coins.%player%} is greater than 120:
      remove 120 from {coins.%player%}
      add 64 tnt to player's inventory

    else:
      send "&6You do not have enough mobcoins, please try again later!"
        
command /obsidiancoins:
  permission: "coins.obsidian"
  trigger:
    if {coins.%player%} is greater than 40:
      remove 40 from {coins.%player%}
      add 64 obsidian to player's inventory

    else:
      send "&6You do not have enough mobcoins, please try again later!"

command /creepercoins:
  permission: "coins.creeper"
  trigger:
    if {coins.%player%} is greater than 300:
      remove 300 from {coins.%player%}
      add 1 creeper spawn egg to player's inventory

    else:
      send "&6You do not have enough mobcoins, please try again later!"
      
command /gapcoins:
  permission: "coins.gap"
  trigger:
    if {coins.%player%} is greater than 150:
      remove 150 from {coins.%player%}
      add 1 enchanted golden apple to player's inventory

    else:
      send "&6You do not have enough mobcoins, please try again later!"

command /hoppercoins:
  permission: "coins.hopper"
  trigger:
    if {coins.%player%} is greater than 70:
      remove 70 from {coins.%player%}
      add 1 hopper to player's inventory

    else:
      send "&6You do not have enough mobcoins, please try again later!"   
      
command /nickcoins:
  permission: "coins.nick"
  trigger:
    if {coins.%player%} is greater than 1000:
      remove 1000 from {coins.%player%}
      add "essentials.nick" to player's permissions
      send "&6You can now do /nick!"           

    else:
      send "&6You do not have enough mobcoins, please try again later!"         
      
command /feedcoins:
  permission: "coins.feed"
  trigger:
    if {coins.%player%} is greater than 1500:
      remove 1500 from {coins.%player%}
      add "essentials.feed" to player's permissions
      send "&6You can now do /feed!"           

    else:
      send "&6You do not have enough mobcoins, please try again later!"     

command /nightcoins:
  permission: "coins.night"
  trigger:
    if {coins.%player%} is greater than 2000:
      remove 2000 from {coins.%player%}
      add "nightvision.enable" to player's permissions
      send "&6You can now do /nightvision!"           

    else:
      send "&6You do not have enough mobcoins, please try again later!"     
      
command /rankcoins:
  permission: "coins.rank"
  trigger:
    if {coins.%player%} is greater than 20000:
      remove 20000 from {coins.%player%}
      execute console command "/mangadd %player% Demi-God"
      send "&6You are now Demi-God!"           

    else:
      send "&6You do not have enough mobcoins, please try again later!"     
      

on death of zombie:
    chance of 20%:
        drop 1 sunflower named "<gold>MobCoin" at victim
on death of creeper:
    chance of 20%:
        drop 1 sunflower named "<gold>MobCoin" at victim
on death of Blaze:
    chance of 20%:
        drop 1 sunflower named "<gold>MobCoin" at victim
on death of CaveSpider:
    chance of 20%:
        drop 1 sunflower named "<gold>MobCoin" at victim
on death of enderman:
    chance of 20%:
        drop 1 sunflower named "<gold>MobCoin" at victim
on death of SilverFish:
    chance of 20%:
        drop 1 sunflower named "<gold>MobCoin" at victim
on death of Skeleton:
    chance of 20%:
        drop 1 sunflower named "<gold>MobCoin" at victim
on death of Slime:
    chance of 20%:
        drop 1 sunflower named "<gold>MobCoin" at victim
on death of Spider:
    chance of 20%:
        drop 1 sunflower named "<gold>MobCoin" at victim
on death of Witch:
    chance of 20%:
        drop 1 sunflower named "<gold>MobCoin" at victim
on death of Wither:
    chance of 20%:
        drop 1 sunflower named "<gold>MobCoin" at victim
on death of Zombie Pigmen:
    chance of 20%:
        drop 1 sunflower named "<gold>MobCoin" at victim



on death of Chicken:
    chance of 20%:
        drop 1 sunflower named "<gold>MobCoin" at victim
on death of Cow:
    chance of 20%:
        drop 1 sunflower named "<gold>MobCoin" at victim
on death of Horse:
    chance of 20%:
        drop 1 sunflower named "<gold>MobCoin" at victim
on death of Mooshroom:
    chance of 20%:
        drop 1 sunflower named "<gold>MobCoin" at victim
on death of Ocelot:
    chance of 20%:
        drop 1 sunflower named "<gold>MobCoin" at victim
on death of Pig:
    chance of 20%:
        drop 1 sunflower named "<gold>MobCoin" at victim
on death of sheep:
    chance of 20%:
        drop 1 sunflower named "<gold>MobCoin" at victim
on death of SnowGolem:
    chance of 20%:
        drop 1 sunflower named "<gold>MobCoin" at victim
on death of Squid:
    chance of 20%:
        drop 1 sunflower named "<gold>MobCoin" at victim
on death of Villager:
    chance of 20%:
        drop 1 sunflower named "<gold>MobCoin" at victim
on death of Wolf:
    chance of 20%:
        drop 1 sunflower named "<gold>MobCoin" at victim
 
code_language.skript:
on pick up of sunflower:
    #add 1 mobcoin to player code

Also, just a suggestion, but instead of checking for the death of each mob individually you could just do something like this so you only need the drop coin code once.

code_language.skript:
on death:
    if victim is a zombie or creeper or pig... and so on:
        #drop coin code
 
I warn you against using just the name for the coin. Use lore for that, it's much more safe as it's impossible to the player modify it.
 
You can add metadata from Skellett to use a more safer system for detecting coins.
code_language.skript:
drop sunflower named "&6Coin" at {_loc}
set metadata "Coin" of last dropped item to true

on pickup of sunflower:
    if metadata "Coin" of event-entity is true:
        #add 1 to coins
The event-entity might be event-item in that case you would need to set the metadata of the itemstack when dropping rather than the dropped entity.
 
Status
Not open for further replies.