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.

Adding MySQL to script?

Discussion in 'Skript' started by Adrihun, Apr 4, 2017.

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

    Adrihun Member

    Joined:
    Feb 1, 2017
    Messages:
    368
    Likes Received:
    6
    Hi. Thanks for clicking on my post. I need help with Script + MySQL. I would like to add MySQL to this so whenever players go on Lobby-1 and change something it also changes in Lobby-2.

    Please if you know MySQL+Script, help me with this. Also, the creator of this script is no longer updating this script. He is now doing Java.

    Code (Skript):
    1. options:
    2.     #The world which Lobby Preferences effect is enabled
    3.     Pref.Enabled: world
    4.  
    5.     #Command prefix
    6.     Pref.Prefix: &3[&9Preferences&3]
    7.  
    8.     #GUI (chest) name
    9.     Pref.GUIname: Player Preferences
    10.  
    11.     #Hide Kick and Death message
    12.     Pref.KickMsgHide: true
    13.     Pref.DeathMsgHide: true
    14.  
    15.     #Customize the Join/Leave message
    16.     Pref.MsgJoin: &1[&dJoin/Leave&1] &7%event-player% has joined the server.
    17.     Pref.MsgLeave: &1[&dJoin/Leave&1] &7%event-player% has left the server.
    18.  
    19.     #Hide system default Join/Leave mesasge
    20.     Pref.HideSysJoin: true
    21.     Pref.HideSysLeave: true
    22.  
    23.     #Admin permission, to configure player's options via commands
    24.     Pref.AdminPerm: Pref.Admin
    25.  
    26.     #Restricted commands
    27.     Pref.NoPerm: &cYou don't have permission to perform this command.
    28.  
    29.     #Default walk speed and Boosted walk speed
    30.     Pref.Boosted: 20
    31.     Pref.BoostDefault: 0.2
    32.  
    33.     #Stacker not enabled message
    34.     Pref.SelfStacker: &e[&2Stacker&e] &cYour Stacker option is not enabled.
    35.     Pref.TargetStacker: &e[&2Stacker&e] &cTarget's Stacker option is not enabled.
    36.  
    37.     #The items in the GUI for you to enable/disable options
    38.     Pref.EnabledItem: dye:10
    39.     Pref.DisabledItem: dye:8
    40.  
    41. on inventory click:
    42.     if "%inventory name of player's current inventory%" is "{@Pref.GUIname}":
    43.         cancel event
    44.         if name of clicked item is "&aPlayer Visibility Enabled":
    45.             make event-player execute command "/pref visibility"
    46.         else if name of clicked item is "&cPlayer Visibility Disabled":
    47.             make event-player execute command "/pref visibility"
    48.          
    49.         if name of clicked item is "&aStacker Enabled":
    50.             make event-player execute command "/pref stacker"
    51.         else if name of clicked item is "&cStacker Disabled":
    52.             make event-player execute command "/pref stacker"
    53.          
    54.         if name of clicked item is "&aSpeed Boost Enabled":
    55.             make event-player execute command "/pref boost"
    56.         else if name of clicked item is "&cSpeed Boost Disabled":
    57.             make event-player execute command "/pref boost"
    58.          
    59.         if name of clicked item is "&aDouble Jump Enabled":
    60.             make event-player execute command "/pref jump"
    61.         else if name of clicked item is "&cDouble Jump Disabled":
    62.             make event-player execute command "/pref jump"
    63.          
    64.         if name of clicked item is "&aMessage Enabled":
    65.             make event-player execute command "/pref message"
    66.         else if name of clicked item is "&cMessage Disabled":
    67.             make event-player execute command "/pref message"
    68.          
    69.         if name of clicked item is "&c&lReset Preferences":
    70.             make event-player execute command "/pref reset"
    71.      
    72.         if name of clicked item is "&cExit":
    73.             close event-player's inventory
    74.  
    75. command /pref [<text>] [<text>] [<text>]:
    76.     aliases: /perference, /preferences
    77.     trigger:
    78.         if arg-1 is not set:
    79.             open chest with 6 rows named "{@Pref.GUIname}" to player
    80.             set slot 2 of player's current inventory to clock named "&aPlayer Visibility"
    81.             set slot 4 of player's current inventory to potion:8265 named "&aStacker" with no nbt
    82.             set slot 6 of player's current inventory to sugar named "&aSpeed Boost"
    83.             set slot 29 of player's current inventory to feather named "&aDouble Jump"
    84.             set slot 31 of player's current inventory to paper named "&aPlayer Join Leave Message"
    85.             set slot 49 of player's current inventory to arrow named "&cExit"
    86.             #--------------------#
    87.             #Visibility
    88.             #--------------------#
    89.             if {Pref.Visibility.%event-player%} is not set:
    90.                 set slot 11 of player's current inventory to {@Pref.EnabledItem} named "&aPlayer Visibility Enabled"
    91.             else:
    92.                 set slot 11 of player's current inventory to {@Pref.DisabledItem} named "&cPlayer Visibility Disabled"
    93.             #--------------------#
    94.             #Stacker
    95.             #--------------------#
    96.             if {Pref.Stacker.%event-player%} is not set:
    97.                 set slot 13 of player's current inventory to {@Pref.EnabledItem} named "&aStacker Enabled"
    98.             else:
    99.                 set slot 13 of player's current inventory to {@Pref.DisabledItem} named "&cStacker Disabled"
    100.             #--------------------#
    101.             #Boost
    102.             #*Default disable*
    103.             #--------------------#
    104.             if {Pref.Boost.%event-player%} is not set:
    105.                 set slot 15 of player's current inventory to {@Pref.DisabledItem} named "&cSpeed Boost Disabled"
    106.             else:
    107.                 set slot 15 of player's current inventory to {@Pref.EnabledItem} named "&aSpeed Boost Enabled"
    108.             #--------------------#
    109.             #Double Jump
    110.             #--------------------#
    111.             if {Pref.Jump.%event-player%} is not set:
    112.                 set slot 38 of player's current inventory to {@Pref.EnabledItem} named "&aDouble Jump Enabled"
    113.             else:
    114.                 set slot 38 of player's current inventory to {@Pref.DisabledItem} named "&cDouble Jump Disabled"
    115.             #--------------------#
    116.             #Join/Leave Message
    117.             #--------------------#
    118.             if {Pref.Message.%event-player%} is not set:
    119.                 set slot 40 of player's current inventory to {@Pref.EnabledItem} named "&aMessage Enabled"
    120.             else:
    121.                 set slot 40 of player's current inventory to {@Pref.DisabledItem} named "&cMessage Disabled"
    122.             #--------------------#
    123.             #Reset button
    124.             #--------------------#
    125.             set slot 53 of player's current inventory to dye:1 named "&c&lReset Preferences"
    126. #=============
    127. #format again after change
    128. #=============
    129.         if arg-1 is "visibility":
    130.             if arg-2 is not set:
    131.                 if {Pref.Visibility.%event-player%} is not set:
    132.                     set {Pref.Visibility.%event-player%} to true
    133.                     set slot 11 of event-player's current inventory to {@Pref.DisabledItem} named "&cPlayer Visibility Disabled"
    134.                     hide all players from event-player
    135.                 else:
    136.                     delete {Pref.Visibility.%event-player%}
    137.                     set slot 11 of event-player's current inventory to {@Pref.EnabledItem} named "&aPlayer Visibility Enabled"
    138.                     reveal all players from event-player
    139.             else if event-player has permission "{@Pref.AdminPerm}":
    140.                 if {Pref.Visibility.%arg-2%} is set:
    141.                     delete {Pref.Visibility.%arg-2%}
    142.                     message "{@Pref.Prefix} &eYou set %arg-2%'s &bPlayer Visibility &eto &aenable."                
    143.                 else:
    144.                     set {Pref.Visibility.%arg-2%} to true
    145.                     message "{@Pref.Prefix} &eYou set %arg-2%'s &bPlayer Visibility &eto &cdisable."
    146.             else:
    147.                 message "{@Pref.NoPerm}"
    148.         if arg-1 is "stacker":
    149.             if arg-2 is not set:
    150.                 if {Pref.Stacker.%event-player%} is not set:
    151.                     set {Pref.Stacker.%event-player%} to true
    152.                     set slot 13 of event-player's current inventory to {@Pref.DisabledItem} named "&cStacker Disabled"
    153.                 else:
    154.                     delete {Pref.Stacker.%event-player%}
    155.                     set slot 13 of event-player's current inventory to {@Pref.EnabledItem} named "&aStacker Enabled"
    156.             else if event-player has permission "{@Pref.AdminPerm}":
    157.                 if {Pref.Stacker.%arg-2%} is set:
    158.                     delete {Pref.Stacker.%arg-2%}
    159.                     message "{@Pref.Prefix} &eYou set %arg-2%'s &bStacker &eto &aenable."
    160.                 else:
    161.                     set {Pref.Stacker.%arg-2%} to true
    162.                     message "{@Pref.Prefix} &eYou set %arg-2%'s &bStacker &eto &cdisable."                
    163.             else:
    164.                 message "{@Pref.NoPerm}"
    165.         #default disable
    166.         if arg-1 is "boost":
    167.             if arg-2 is not set:
    168.                 if {Pref.Boost.%event-player%} is set:
    169.                     delete {Pref.Boost.%event-player%}
    170.                     set slot 15 of event-player's current inventory to {@Pref.DisabledItem} named "&cSpeed Boost Disabled"
    171.                     set the walk speed of event-player to 0.2
    172.                 else:
    173.                     set {Pref.Boost.%event-player%} to true
    174.                     set slot 15 of event-player's current inventory to {@Pref.EnabledItem} named "&aSpeed Boost Enabled"              
    175.                     set the player's walk speed to 20
    176.             else if event-player has permission "{@Pref.AdminPerm}":
    177.                 if {Pref.Boost.%arg-2%} is set:
    178.                     delete {Pref.Boost.%arg-2%}
    179.                     message "{@Pref.Prefix} &eYou set %arg-2%'s &bBoost &eto &cdisable."
    180.                     set {_Pref.temp} to arg-2 parsed as player
    181.                     set {_Pref.temp}'s walk speed to 0.2
    182.                 else:
    183.                     set {_Pref.temp} to arg-2 parsed as player
    184.                     set {_Pref.temp}'s walk speed to 20
    185.                     set {Pref.Boost.%arg-2%} to true
    186.                     message "{@Pref.Prefix} &eYou set %arg-2%'s &bBoost &eto &aenable."            
    187.             else:
    188.                 message "{@Pref.NoPerm}"
    189.         if arg-1 is "jump":
    190.             if arg-2 is not set:
    191.                 if {Pref.Jump.%event-player%} is not set:
    192.                     set {Pref.Jump.%event-player%} to true
    193.                     set slot 38 of event-player's current inventory to {@Pref.DisabledItem} named "&cDouble Jump Disabled"
    194.                 else:
    195.                     delete {Pref.Jump.%event-player%}
    196.                     set slot 38 of event-player's current inventory to {@Pref.EnabledItem} named "&aDouble Jump Enabled"                
    197.             else if event-player has permission "{@Pref.AdminPerm}":
    198.                 if {Pref.Jump.%arg-2%} is set:
    199.                     delete {Pref.Jump.%arg-2%}
    200.                     message "{@Pref.Prefix} &eYou set %arg-2%'s &bDouble Jump &eto &aenable."
    201.                 else:
    202.                     set {Pref.Jump.%arg-2%} to true
    203.                     message "{@Pref.Prefix} &eYou set %arg-2%'s &bDouble Jump &eto &cdisable."
    204.             else:
    205.                 message "{@Pref.NoPerm}"
    206.         if arg-1 is "message":
    207.             if arg-2 is not set:
    208.                 if {Pref.Message.%event-player%} is not set:
    209.                     set {Pref.Message.%event-player%} to true
    210.                     set slot 40 of event-player's current inventory to {@Pref.DisabledItem} named "&cMessage Disabled"
    211.                 else:
    212.                     delete {Pref.Message.%event-player%}
    213.                     set slot 40 of event-player's current inventory to {@Pref.EnabledItem} named "&aMessage Enabled"
    214.             else if event-player has permission "{@Pref.AdminPerm}":
    215.                 if {Pref.Message.%arg-2%} is set:
    216.                     delete {Pref.Message.%arg-2%}
    217.                     message "{@Pref.Prefix} &eYou set %arg-2%'s &bJoin/Leave Message &eto &aenable."              
    218.                 else:
    219.                     set {Pref.Message.%arg-2%} to true
    220.                     message "{@Pref.Prefix} &eYou set %arg-2%'s &bJoin/Leave Message &eto &cdisable."
    221.             else:
    222.                 message "{@Pref.NoPerm}"
    223.         if arg-1 is "reset":
    224.             delete {Pref.Visibility.%event-player%}
    225.             delete {Pref.Boost.%event-player%}
    226.             delete {Pref.Stacker.%event-player%}
    227.             delete {Pref.Jump.%event-player%}
    228.             delete {Pref.Message.%event-player%}
    229.             set the walk speed of event-player to {@Pref.BoostDefault}
    230.             close event-player's inventory
    231.             message "{@Pref.Prefix} &eYour Lobby Preferences menu has been reset."
    232.         if arg-1 is "help":
    233.             message "{@Pref.Prefix}&cAuthor: i998979"
    234.             message "&aCommands:"
    235.             message "&6[Player] can be ommited or replace with player's name."
    236.             message "    &6If it is specified, the commands will apply on that player."
    237.             message "    &6Otherwise, it will apply on your own."
    238.             message "&b/preferences /pref /preference: &9Open the Preferences GUI"
    239.             message "&b/pref visibility [Player]: &9Switch someone's Player Visibility option"
    240.             message "&b/pref stacker [Player]: &9Switch someone's Player Stacker option"
    241.             message "&b/pref boost [Player]: &9Switch someone's Boost option"
    242.             message "&b/pref jump [Player]: &9Switch someone's Double Jump option"
    243.             message "&b/pref message [Player]: &9Switch someone's Join/Leave Message option"
    244.             message "&b/pref reset [Player]: &9Reset someone's option to default"
    245.             message "&b/pref help [Player]: &9Show thie help page"
    246.          
    247. #--------------------#
    248. #Player visibility
    249. #--------------------#
    250. on join:
    251.     if event-player is in world "{@Pref.Enabled}":
    252.         if {Pref.Visibility.%event-player%} is not set:
    253.             reveal all players from event-player
    254.         else:
    255.             hide all players from event-player
    256. #--------------------#
    257. #Stacker
    258. #--------------------#
    259. on right click on player:
    260.     if event-player is in world "{@Pref.Enabled}":
    261.         if {Pref.Stacker.%clicked player%} is not set:
    262.             if {Pref.Stacker.%player%} is not set:
    263.                 make clicked player ride event-player
    264.             else:
    265.                 message "{@Pref.SelfStacker}" to event-player
    266.         else:
    267.             message "{@Pref.TargetStacker}" to event-player
    268. on left click:
    269.     if event-player is in world "{@Pref.Enabled}":
    270.         dismount passenger from event-player
    271.  
    272. #--------------------#
    273. #Speed Boost
    274. #--------------------#
    275. on join:
    276.     if event-player is in world "{@Pref.Enabled}":
    277.         if {Pref.Boost.%event-player%} is not set:
    278.             set the walk speed of event-player to {@Pref.BoostDefault}
    279.         else:
    280.             set the player's walk speed to {@Pref.Boosted}
    281.  
    282. #--------------------#
    283. #Join Leave message
    284. #--------------------#
    285. on join:
    286.     if event-player is in world "{@Pref.Enabled}":
    287.         if {@Pref.HideSysJoin} is true:
    288.             set join message to ""
    289.         loop all players:
    290.             if {Pref.Message.%loop-player%} is not set:
    291.                 if event-player is not loop-player:
    292.                     message "{@Pref.MsgJoin}" to loop-player
    293. on quit:
    294.     if event-player is in world "{@Pref.Enabled}":
    295.         if {@Pref.HideSysLeave} is true:
    296.             set leave message to ""
    297.         loop all players:
    298.             if {Pref.Message.%loop-player%} is not set:
    299.                 if event-player is not loop-player:
    300.                     message "{@Pref.MsgLeave}" to loop-player
    301.                  
    302. #--------------------#
    303. #Kick Death message hide
    304. #--------------------#
    305. on kick:
    306.     if event-player is in world "{@Pref.Enabled}":
    307.         if {@Pref.KickMsgHide} is true:
    308.             set kick message to ""
    309. on death:
    310.     if event-player is in world "{@Pref.Enabled}":
    311.         if {@Pref.DeathMsgHide} is true:
    312.             set death message to ""
    313.        
     
    #1 Adrihun, Apr 4, 2017
    Last edited: Apr 5, 2017
  2. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,177
    Likes Received:
    218
    Actually, this would be more easy if you're using the config sql option.
    Just define a prefix and change any variable the variables.
     
  3. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,177
    Likes Received:
    218
    Config sql? What do you mean?
    I enabled MySQL in Skript and downloaded the Skript SQL jar.

    Define a prefix? What do you mean?
    Sorry... I'm a noob. :emoji_frowning:
     
  4. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,177
    Likes Received:
    218
    Open your script config which is located in plugins\Skript\config.sk

    Look for this code:
    Code (Skript):
    1. MySQL example:
    2.         # A MySQL database example, with options unrelated to MySQL removed.
    3.        
    4.         type: disabled # change to line below to enable this database
    5.         # type: MySQL
    6.        
    7.         pattern: synced_.* # this pattern will save all variables that start with 'synced_' in this MySQL database.
    8.        
    9.         host: localhost
    10.         port: 3306
    11.         user: root
    12.         password: pass
    13.         database: skript
    14.        
    15.         monitor changes: true
    16.         monitor interval: 20 seconds
    Change to:
    Code (Skript):
    1. MySQL example:
    2.         # A MySQL database example, with options unrelated to MySQL removed.
    3.        
    4.         type: MySQL
    5.        
    6.         pattern: sql_.*
    7.        
    8.         host: YOURHOST
    9.         port: 3306
    10.         user: YOURUSER
    11.         password: YOURPASS
    12.         database: Skript
    13.        
    14.         monitor changes: true
    15.         monitor interval: 20 seconds
    Later, you have to change the names of the variables, for example:
    Code (Skript):
    1. {normalvariable::%player%}
    2. to
    3. {sql_.normalvariable::%player%}
     
  5. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,177
    Likes Received:
    218
    Okay, thanks it works now. I need help with your Eco script now!
    I changed your command a little bit:

    Code (Skript):
    1. command /moneyset [<offline player>] [<number>]:
    2.     permission: money.set
    3.     permission message: &cNo permission.
    4.     trigger:
    5.         set {_player} to "%player%"
    6.         arg 1 is set:
    7.             arg 2 is set:
    8.                 if arg 1 is online:
    9.                     if arg 1 is {_player}:
    10.                         send "&cYou can't change the amount of money you have."
    11.                         stop
    12.                 {@run_async} is "true":
    13.                     $ thread
    14.                 set {_message} to addCoins(arg 1, arg 2, 1)
    15.                 send "%{_message}%"
    16.             else:
    17.                 send "&cWrong usage."
    18.         else:
    19.             send "&cWrong usage."
    And it doesn't work. Can you please help me. Lol
     
  6. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,177
    Likes Received:
    218
    I don't know what is not working in your changes because i tested it and it's working, but i think you need to do this
    Code (Text):
    1. if "%arg 1%" is "%{_player}%"
    instead of
    Code (Text):
    1. if arg 1 is {_player}
     
  7. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,177
    Likes Received:
    218
    Code (Skript):
    1. command /moneyset [<offline player>] [<number>]:
    2.     permission: money.set
    3.     permission message: &cNo permission.
    4.     trigger:
    5.         if arg 1 is set:
    6.             if arg 2 is set:
    7.                 if arg 1 is online:
    8.                     if arg 1 is player:
    9.                         send "&cYou can't change the amount of money you have."
    10.                         stop
    11.                 if {@run_async} is "true":
    12.                     $ thread
    13.                 set {_message} to addCoins(arg 1, arg 2, 1)
    14.                 send "%{_message}%"
    15.             else:
    16.                 send "&cWrong usage."
    17.         else:
    18.             send "&cWrong usage."
     
    • Like Like x 1
  8. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,177
    Likes Received:
    218
    @YoshYz How do you add the message "Sorry but this player is offline" :emoji_slight_smile: Thats all i need ! lol
     
  9. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,177
    Likes Received:
    218
    Code (Text):
    1.  
    2. command /moneyset [<offline player>] [<number>]:
    3.     permission: money.set
    4.     permission message: &cNo permission.
    5.     trigger:
    6.         arg 1 is set:
    7.             arg 2 is set:
    8.                 if arg 1 is online:
    9.                     if arg 1 is player:
    10.                         send "&cYou can't change the amount of money you have."
    11.                         stop
    12.                 else:
    13.                     send "%arg-1% is not online"
    14.                 {@run_async} is "true":
    15.                     $ thread
    16.                 set {_message} to addCoins(arg 1, arg 2, 1)
    17.                 send "%{_message}%"
    18.             else:
    19.                 send "&cWrong usage."
    20.         else:
    21.             send "&cWrong usage."
    22.  
     
  10. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,177
    Likes Received:
    218
    thanks
     
  11. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,177
    Likes Received:
    218
    You're welcome
     
Thread Status:
Not open for further replies.

Share This Page

Loading...