Child Player can Dismount

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

dodi2020

Member
Jan 9, 2023
1
0
1
So i have this skript, and it works fine for the most part, but when a "child" player activates the "on dismount:" section even if said player is aged 5 or lower they can still properly dismount, even though i have "cancel event" and "stop" set in the if function that detects the player's age


code_language.skript:
options:
  maxAge: 60
  addon_prefix: ohol
  deathBypassPermission: ohol.bypassdeath

  defaultFamilyColor: "&f"
  evePermission: ohol.eve
  bornPermission: ohol.born

  minScale: 0.2
  adultScale: 1.0
  adulthoodAge: 21

  childHoldableAge: 10

on right click on player:
  if player is sneaking:
    set {_parent} to player
    set {_child} to clicked player

    if {_child} is not a player:
      stop
    if {_parent} is {_child}:
      stop

    set {_parentUUIDText} to "%uuid of {_parent}%"
    set {_childUUIDText} to "%uuid of {_child}%"

    set {_childAge} to {age::%{_childUUIDText}%}
    if {_childAge} is not set:
      set {_childAge} to 1
    set {_holdableAgeText} to "{@childHoldableAge}"
    if {_childAge} > {@childHoldableAge}:
      send "&cYou can only pick up children aged %{_holdableAgeText}% or younger!" to {_parent}
      stop

    set {_childParentUUID} to {parent::%{_childUUIDText}%}
    if {_childParentUUID} is not set:
      send "&cYou are not the parent of %{_child}'s name%." to {_parent}
      stop
    if {_childParentUUID} != {_parentUUIDText}:
      send "&cYou are not the parent of %{_child}'s name%." to {_parent}
      stop

    if {holding_child::%{_parentUUIDText}%} is set:
      send "&cYou are already holding a child. Drop them first!" to {_parent}
      stop

    if {is_being_held::%{_childUUIDText}%} is set:
      send "&c%{_child}'s name% is already being held by someone." to {_parent}
      stop

    make {_child} ride {_parent}
    set {holding_child::%{_parentUUIDText}%} to {_childUUIDText}
    set {is_being_held::%{_childUUIDText}%} to {_parentUUIDText}

    send "&aYou picked up &e%{_child}'s name%&a." to {_parent}
    send "&a%{_parent}'s name% &ahas picked you up!" to {_child}

function drop_held_child(p: player, c: player):
    set {_parentUUIDText} to "%uuid of {_p}%"
    set {_childUUIDText} to "%uuid of {_c}%"

    delete {holding_child::%{_parentUUIDText}%}
    delete {is_being_held::%{_childUUIDText}%}

    if {_c} is riding {_p}:
        make {_c} dismount vehicle

    send "&aYou dropped &e%{_c}'s name%&a." to {_p}
    send "&a%{_p}'s name% &ahas dropped you." to {_c}

    teleport {_c} to location of {_c}

on dismount:
  set {_childEntity} to event-entity
  set {_parentEntity} to event-vehicle

  if {_childEntity} is not a player:
    stop
  if {_parentEntity} is not a player:
    stop

  set {_child} to {_childEntity}
  set {_parent} to {_parentEntity}

  set {_childUUIDText} to "%uuid of {_child}%"
  set {_childAge} to {age::%{_childUUIDText}%} ? 1

  if {_childAge} <= 5:
    set {_parentUUIDText} to "%uuid of {_parent}%"
    if {is_being_held::%{_childUUIDText}%} is set:
      if {is_being_held::%{_childUUIDText}%} = {_parentUUIDText}:
        cancel event
        send "&cYou are too young to get down!" to {_child}
        stop

  set {_childUUIDText} to "%uuid of {_child}%"
  set {_parentUUIDText} to "%uuid of {_parent}%"

  if {is_being_held::%{_childUUIDText}%} is set:
    if {is_being_held::%{_childUUIDText}%} = {_parentUUIDText}:
      drop_held_child({_parent}, {_child})

on left click:
  if player is sneaking:
    if player's tool is air:
      set {_parent} to player
      set {_parentUUIDText} to "%uuid of {_parent}%"

      if {holding_child::%{_parentUUIDText}%} is set:
        set {_childUUIDText} to {holding_child::%{_parentUUIDText}%}
        set {_child} to "%{_childUUIDText}%" parsed as offline player

        if {_child} is online:
          drop_held_child({_parent}, {_child})
        else:
          delete {holding_child::%{_parentUUIDText}%}
          send "&aYou stopped holding offline child &e%{_child}'s name%&a." to {_parent}

command /renamechild:
  permission: ohol.born
  permission message: "&cYou must be born into a family to rename a child."
  trigger:
    set {_parent} to player
    set {_parentUUIDText} to "%uuid of {_parent}%"

    if {holding_child::%{_parentUUIDText}%} is not set:
      send "&cYou are not holding a child to rename." to {_parent}
      stop

    set {_childUUIDText} to {holding_child::%{_parentUUIDText}%}
    set {_child} to "%{_childUUIDText}%" parsed as offline player

    if {_child} is not riding {_parent}:
      send "&cIt seems you are not actually holding that child. Try picking them up again." to {_parent}
      delete {holding_child::%{_parentUUIDText}%}
      delete {is_being_held::%{_childUUIDText}%}
      stop

    if {renamed_count::%{_childUUIDText}%} >= 1:
      send "&c%{_child}'s name% has already been renamed once." to {_parent}
      stop

    set {rename_session_child_uuid::%{_parentUUIDText}%} to {_childUUIDText}

    send "&aPlease type the new name for your child in chat. (1-16 characters, plaintext)" to {_parent}
    send "&cType 'cancel' to stop renaming." to {_parent}

on chat:
  set {_player} to player
  set {_playerUUIDText} to "%uuid of {_player}%"

  if {rename_session_child_uuid::%{_playerUUIDText}%} is set:
    cancel event

    set {_input} to message

    if {_input} is "cancel":
      send "&cChild renaming session cancelled." to {_player}
      delete {rename_session_child_uuid::%{_playerUUIDText}%}
      stop

    set {_childUUIDText} to {rename_session_child_uuid::%{_playerUUIDText}%}
    set {_child} to "%{_childUUIDText}%" parsed as offline player

    if {_child} is not set:
      send "&cError: The child you were renaming could not be found." to {_player}
      delete {rename_session_child_uuid::%{_playerUUIDText}%}
      stop

    set {_newName} to {_input}

    if {_newName} is "" or length of uncolored {_newName} > 16:
      send "&cRename failed: Name invalid (1-16 characters, plaintext). Please try again." to {_player}
      send "&aPlease type the new name for your child in chat. (1-16 characters, plaintext)" to {_player}
      send "&cType 'cancel' to stop renaming." to {_player}
      stop

    set {_oldChildName} to {_child}'s name

    set {given_name::%{_childUUIDText}%} to {_newName}

    set {_childFamilyName} to {familyname::%{_childUUIDText}%} ? "Unknown Family"
    set {_childFamilyColor} to {familycolor::%{_childUUIDText}%} ? {@defaultFamilyColor}

    set display name of {_child} to "%{_childFamilyColor}%%{_childFamilyName}% %{_newName}%&f"

    set {renamed_count::%{_childUUIDText}%} to ({renamed_count::%{_childUUIDText}%} ? 0) + 1

    send "&aYou have renamed &e%{_oldChildName}% &ato &6%{_newName}%&a." to {_player}
    if {_child} is online:
      send "&aYour name has been changed to &e%{_newName}%&a by &e%{_player}'s name%&a." to {_child}

      send colored "&aYour new full name is: %display name of {_child}%" to {_child}

    delete {rename_session_child_uuid::%{_playerUUIDText}%}