Solved My quest skript doesn't give a quest sometimes and it also sometimes gives more than 1 quest

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

PureNuggets

Member
Jun 25, 2021
17
0
1
16
So as the title says. My quest skript that I've been tryna fix for around 2 days gives more than 1 quest sometimes and it's pretty dumb. Heres the skript.

Code:
function tokenReward(p: player):
  chance of 50%:
    send "&eYou have completed a quest and have gotten 1 Quest Token" to {_p}
    give {_p} sunflower named "&eQuest Token" with lore "&bUse This Token To Redeem Rewards"
  chance of 35%:
    send "&eYou have completed a quest and have gotten 2 Quest Tokens" to {_p}
    give {_p} 2 sunflower named "&eQuest Token" with lore "&bUse This Token To Redeem Rewards"
  chance of 15%:
    send "&eYou have completed a quest and have gotten 3 Quest Tokens" to {_p}
    give {_p} 3 sunflower named "&eQuest Token" with lore "&bUse This Token To Redeem Rewards"

function play1hQuest(p: player):
  send "&eYou have gotten the quest:" to {_p}
  wait 1 second
  send "" to {_p}
  send "&ePlay for 1 hour" to {_p}
  set {quests::%{_p}%'s uuid::play1hQuest} to 1

function play45Quest(p: player):
  send "&eYou have gotten the quest:" to {_p}
  wait 1 second
  send "" to {_p}
  send "&ePlay for 45 minutes" to {_p}
  set {quests::%{_p}%'s uuid::play45Quest} to 1

function play30Quest(p: player):
  send "&eYou have gotten the quest:" to {_p}
  wait 1 second
  send "" to {_p}
  send "&ePlay for 30 minutes" to {_p}
  set {quests::%{_p}%'s uuid::play30Quest} to 1

function cobble256Quest(p: player):
  send "&eYou have gotten the quest:" to {_p}
  wait 1 second
  send "" to {_p}
  send "&eMine 256 Cobblestone" to {_p}
  set {quests::%{_p}%'s uuid::cobble256Quest} to 1

function cobble192Quest(p: player):
  send "&eYou have gotten the quest:" to {_p}
  wait 1 second
  send "" to {_p}
  send "&eMine 192 Cobblestone" to {_p}
  set {quests::%{_p}%'s uuid::cobble192Quest} to 1

function breadQuest(p: player):
  send "&eYou have gotten the quest:" to {_p}
  wait 1 second
  send "" to {_p}
  send "&eCraft 48 Bread" to {_p}
  send "&eP.S... You can't shift click craft as it will only count as 1 item crafted!" to {_p}
  set {quests::%{_p}%'s uuid::breadQuest} to 1

function sugarQuest(p: player):
  send "&eYou have gotten the quest:" to {_p}
  wait 1 second
  send "" to {_p}
  send "&eCraft 2 Stacks Of Sugar" to {_p}
  send "&eP.S... You can't shift click craft as it will only count as 1 item crafted!" to {_p}
  set {quests::%{_p}%'s uuid::sugarQuest} to 1
 
function fish30Quest(p: player):
  send "&eYou have gotten the quest:" to {_p}
  wait 1 second
  send "" to {_p}
  send "&eFish 30 Items" to {_p}
  set {quests::%{_p}%'s uuid::fish30Quest} to 1

function fish25Quest(p: player):
  send "&eYou have gotten the quest:" to {_p}
  wait 1 second
  send "" to {_p}
  send "&eFish 25 Items" to {_p}
  set {quests::%{_p}%'s uuid::fish25Quest} to 1

function walk1500Quest(p: player):
  send "&eYou have gotten the quest:" to {_p}
  wait 1 second
  send "" to {_p}
  send "&eWalk 1500 Blocks" to {_p}
  set {quests::%{_p}%'s uuid::walk1500Quest} to 1

function walk1000Quest(p: player):
  send "&eYou have gotten the quest:" to {_p}
  wait 1 second
  send "" to {_p}
  send "&eWalk 1000 Blocks" to {_p}
  set {quests::%{_p}%'s uuid::walk1kQuest} to 1

function place200Quest(p: player):
  send "&eYou have gotten the quest:" to {_p}
  wait 1 second
  send "" to {_p}
  send "&ePlace 200 Blocks" to {_p}
  set {quests::%{_p}%'s uuid::place200Quest} to 1

function place150Quest(p: player):
  send "&eYou have gotten the quest:" to {_p}
  wait 1 second
  send "" to {_p}
  send "&ePlace 150 Blocks" to {_p}
  set {quests::%{_p}%'s uuid::place150Quest} to 1

function break200Quest(p: player):
  send "&eYou have gotten the quest:" to {_p}
  wait 1 second
  send "" to {_p}
  send "&eBreak 200 Blocks" to {_p}
  set {quests::%{_p}%'s uuid::break200Quest} to 1

function break150Quest(p: player):
  send "&eYou have gotten the quest:" to {_p}
  wait 1 second
  send "" to {_p}
  send "&eBreak 150 Blocks" to {_p}
  set {quests::%{_p}%'s uuid::break150Quest} to 1

function endermanQuest(p: player):
  send "&eYou have gotten the quest:" to {_p}
  wait 1 second
  send "" to {_p}
  send "&eKill 40 Zombies" to {_p}
  set {quests::%{_p}%'s uuid::endermanQuest} to 1

function spiderQuest(p: player):
  send "&eYou have gotten the quest:" to {_p}
  wait 1 second
  send "" to {_p}
  send "&eKill 50 Spiders" to {_p}
  set {quests::%{_p}%'s uuid::spiderQuest} to 1

function creeperQuest(p: player):
  send "&eYou have gotten the quest:" to {_p}
  wait 1 second
  send "" to {_p}
  send "&eKill 50 Creepers" to {_p}
  set {quests::%{_p}%'s uuid::creeperQuest} to 1

function skeletonQuest(p: player):
  send "&eYou have gotten the quest:" to {_p}
  wait 1 second
  send "" to {_p}
  send "&eKill 50 Skeletons" to {_p}
  set {quests::%{_p}%'s uuid::skeletonQuest} to 1

function zombieQuest(p: player):
  send "&eYou have gotten the quest:" to {_p}
  wait 1 second
  send "" to {_p}
  send "&eKill 50 Zombies" to {_p}
  set {quests::%{_p}%'s uuid::zombieQuest} to 1
 

function loadQuests():
  loop all offline players:
    delete {quests::%loop-offlineplayer%'s uuid::*}
  broadcast "&eQuests By &e&lPureNuggets!"

 

function getQuest(p: player):
  if {quests::%{_p}%'s uuid::*} is set:
    send "&cYou already have a ongoing quest!" to {_p}
  else:
    send "" to {_p}
    send "&eRolling you a random quest!" to {_p}
    send "" to {_p}
    wait 3 seconds
    chance of 5%: #Kill 50 Zombies
      zombieQuest({_p})
    chance of 5%: #Kill 50 Skeletons
      skeletonQuest({_p})
    chance of 5%: #Kill 50 Creepers
      creeperQuest({_p})
    chance of 5%: #Kill 50 Spiders
      spiderQuest({_p})
    chance of 5%: #Kill 40 Endermen
      endermanQuest({_p})
    chance of 5%: #Break 150 Blocks
      break150Quest({_p})
    chance of 5%: #Break 200 Blocks
      break200Quest({_p})
    chance of 5%: #Place 150 Blocks
      place150Quest({_p})
    chance of 5%: #Place 200 Blocks
      place200Quest({_p})
    chance of 5%: #Walk 1k Blocks
      walk1000Quest({_p})
    chance of 5%: #Walk 1.5k Blocks
      walk1500Quest({_p})
    chance of 5%: #Fish 25 Items
      fish25Quest({_p})
    chance of 5%: #Fish 30 Items
      fish30Quest({_p})
    chance of 5%: #Craft 128 Sugar
      sugarQuest({_p})
    chance of 5%: #Craft 48 Bread
      breadQuest({_p})
    chance of 5%: #Break 192 Cobble
      cobble192Quest({_p})
    chance of 5%: #Break 256 Cobble
      cobble256Quest({_p})
    chance of 5%: #Play For 30 Minutes
      play30Quest({_p})
    chance of 5%: #Play For 45 Minutes
      play45Quest({_p})
    chance of 5%: #Play For 1 Hour
      play1hQuest({_p})
     

command /quest:
  cooldown: 1 day
  trigger:
    getQuest(player)
   
command /loadquests:
  permission: quests.load
  trigger:
    loadQuests()
   
on load:
  loadQuests()
   
on death:
  if victim is zombie:
    if {quests::%attacker%'s uuid::zombieQuest} is set:
      add 1 to {quests::%attacker%'s uuid::zombieQuest}
      send "&eYou have killed %{quests::%attacker%'s uuid::zombieQuest} - 1%&e/50 Zombies!" to attacker
      if {quests::%attacker%'s uuid::zombieQuest} > 50:
        send "&eYou have completed the following quest:" to attacker
        send "" to attacker
        send "&eKill 50 Zombies" to attacker
        delete {quests::%attacker%'s uuid::zombieQuest}
        tokenReward(attacker)
  if victim is skeleton:
    if {quests::%attacker%'s uuid::skeletonQuest} is set:
      add 1 to {quests::%attacker%'s uuid::skeletonQuest}
      send "&eYou have killed %{quests::%attacker%'s uuid::skeletonQuest} - 1%&e/50 Skeletons!" to attacker
      if {quests::%attacker%'s uuid::skeletonQuest} > 50:
        send "&eYou have completed the following quest:" to attacker
        send "" to attacker
        send "&eKill 50 Skeletons" to attacker
        delete {quests::%attacker%'s uuid::skeletonQuest}
        tokenReward(attacker)
  if victim is creeper:
    if {quests::%attacker%'s uuid::creeperQuest} is set:
      add 1 to {quests::%attacker%'s uuid::creeperQuest}
      send "&eYou have killed %{quests::%attacker%'s uuid::creeperQuest} - 1%&e/50 Creepers!" to attacker
      if {quests::%attacker%'s uuid::creeperQuest} > 50:
        send "&eYou have completed the following quest:" to attacker
        send "" to attacker
        send "&eKill 50 Creepers" to attacker
        delete {quests::%attacker%'s uuid::creeperQuest}
        tokenReward(attacker)
  if victim is spider:
    if {quests::%attacker%'s uuid::spiderQuest} is set:
      add 1 to {quests::%attacker%'s uuid::spiderQuest}
      send "&eYou have killed %{quests::%attacker%'s uuid::spiderQuest} - 1%&e/50 Spiders!" to attacker
      if {quests::%attacker%'s uuid::spiderQuest} > 50:
        send "&eYou have completed the following quest:" to attacker
        send "" to attacker
        send "&eKill 50 Spiders" to attacker
        delete {quests::%attacker%'s uuid::spiderQuest}
        tokenReward(attacker)
  if victim is enderman:
    if {quests::%attacker%'s uuid::endermanQuest} is set:
      add 1 to {quests::%attacker%'s uuid::endermanQuest}
      send "&eYou have killed %{quests::%attacker%'s uuid::endermanQuest} - 1%&e/50 Endermen!" to attacker
      if {quests::%attacker%'s uuid::endermanQuest} > 50:
        send "&eYou have completed the following quest:" to attacker
        send "" to attacker
        send "&eKill 50 Endermen" to attacker
        delete {quests::%attacker%'s uuid::endermanQuest}
        tokenReward(attacker)

on break:
  if {quests::%player%'s uuid::break150Quest} is set:
    add 1 to {quests::%player%'s uuid::break150Quest}
    send "&eYou have broken %{quests::%player%'s uuid::break150Quest} - 1%&e/150 Blocks" to player
    if {quests::%player%'s uuid::break150Quest} > 150:
      send "&eYou have completed the following quest:" to player
      send "" to player
      send "&eBreak 150 Blocks" to player
      delete {quests::%player%'s uuid::break150Quest}
      tokenReward(player)
  if {quests::%player%'s uuid::break200Quest} is set:
    add 1 to {quests::%player%'s uuid::break200Quest}
    send "&eYou have broken %{quests::%player%'s uuid::break150Quest} - 1%&e/200 Blocks" to player
    if {quests::%player%'s uuid::break200Quest} > 200:
      send "&eYou have completed the following quest:" to player
      send "" to player
      send "&eBreak 200 Blocks" to player
      delete {quests::%player%'s uuid::break200Quest}
      tokenReward(player)
  if {quests::%player%'s uuid::cobble192Quest} is set:
    if event-block is stone or cobblestone:
      add 1 to {quests::%player%'s uuid::cobble192Quest}
      send "&eYou have broken %{quests::%player%'s uuid::cobble192Quest} - 1%&e/192 Cobblestone" to player
      if {quests::%player%'s uuid::cobble192Quest} > 192:
        send "&eYou have completed the following quest:" to player
        send "" to player
        send "&eBreak 192 Cobblestone" to player
        delete {quests::%player%'s uuid::cobble192Quest}
        tokenReward(player)
  if {quests::%player%'s uuid::cobble256Quest} is set:
    if event-block is stone or cobblestone:
      add 1 to {quests::%player%'s uuid::cobble256Quest}
      send "&eYou have broken %{quests::%player%'s uuid::cobble256Quest} - 1%&e/256 Cobblestone" to player
      if {quests::%player%'s uuid::cobble256Quest} > 256:
        send "&eYou have completed the following quest:" to player
        send "" to player
        send "&eBreak 256 Cobblestone" to player
        delete {quests::%player%'s uuid::cobble256Quest}
        tokenReward(player)
 
on place:
  if {quests::%player%'s uuid::place150Quest} is set:
    add 1 to {quests::%player%'s uuid::place150Quest}
    send "&eYou have placed %{quests::%player%'s uuid::place150Quest} - 1%&e/150 Blocks" to player
    if {quests::%player%'s uuid::place150Quest} > 150:
      send "&eYou have completed the following quest:" to player
      send "" to player
      send "&ePlace 150 Blocks" to player
      delete {quests::%player%'s uuid::place150Quest}
      tokenReward(player)
  if {quests::%player%'s uuid::place200Quest} is set:
    add 1 to {quests::%player%'s uuid::place200Quest}
    send "&eYou have placed %{quests::%player%'s uuid::place200Quest} - 1%&e/200 Blocks" to player
    if {quests::%player%'s uuid::place200Quest} > 200:
      send "&eYou have completed the following quest:" to player
      send "" to player
      send "&ePlace 200 Blocks" to player
      delete {quests::%player%'s uuid::place200Quest}
      tokenReward(player)

on fish:
  fish state is CAUGHT_FISH:
    if {quests::%player%'s uuid::fish25Quest} is set:
      add 1 to {quests::%player%'s uuid::fish25Quest}
      send "&eYou have fished %{quests::%player%'s uuid::fish25Quest} - 1%/25 Times"
      if {quests::%player%'s uuid::fish25Quest} > 25:
        send "&eYou have completed the following quest:" to player
        send "" to player
        send "&eFish 25 Items" to player
        delete {quests::%player%'s uuid::fish25Quest}
        tokenReward(player)
    if {quests::%player%'s uuid::fish30Quest} is set:
      add 1 to {quests::%player%'s uuid::fish30Quest}
      send "&eYou have fished %{quests::%player%'s uuid::fish30Quest} - 1%/30 Times"
      if {quests::%player%'s uuid::fish30Quest} > 30:
        send "&eYou have completed the following quest:" to player
        send "" to player
        send "&eFish 30 Items" to player
        delete {quests::%player%'s uuid::fish30Quest}
        tokenReward(player)
     
every 1 minute:
  loop all players:
    if {quests::%loop-player%'s uuid::play30Quest} is set:
      add 1 to {quests::%loop-player%'s uuid::play30Quest}
      if {quests::%loop-player%'s uuid::play30Quest} > 30:
        send "&eYou have completed the following quest:" to loop-player
        send "" to loop-player
        send "&ePlay For 30 Minutes" to loop-player
        delete {quests::%loop-player%'s uuid::play30Quest}
        tokenReward(loop-player)
    if {quests::%loop-player%'s uuid::play45Quest} is set:
      add 1 to {quests::%loop-player%'s uuid::play45Quest}
      if {quests::%loop-player%'s uuid::play45Quest} > 45:
        send "&eYou have completed the following quest:" to loop-player
        send "" to loop-player
        send "&ePlay For 45 Minutes" to loop-player
        delete {quests::%loop-player%'s uuid::play45Quest}
        tokenReward(loop-player)
    if {quests::%loop-player%'s uuid::play1hQuest} is set:
      add 1 to {quests::%loop-player%'s uuid::play1hQuest}
      if {quests::%loop-player%'s uuid::play1hQuest} > 60:
        send "&eYou have completed the following quest:" to loop-player
        send "" to loop-player
        send "&ePlay For 1 Hour" to loop-player
        delete {quests::%loop-player%'s uuid::play1hQuest}
        tokenReward(loop-player)

on any move:
  if {quests::%player%'s uuid::walk1kQuest} is set:
    add 1 to {quests::%player%'s uuid::walk1kQuest}
    if {quests::%player%'s uuid::walk1kQuest} > 1000:
      send "&eYou have completed the following quest:" to player
      send "" to player
      send "&eWalk 1000 Blocks" to player
      delete {quests::%player%'s uuid::walk1kQuest}
      tokenReward(player)
  if {quests::%player%'s uuid::walk1500Quest} is set:
    add 1 to {quests::%player%'s uuid::walk1500Quest}
    if {quests::%player%'s uuid::walk1500Quest} > 1000:
      send "&eYou have completed the following quest:" to player
      send "" to player
      send "&eWalk 1500 Blocks" to player
      delete {quests::%player%'s uuid::walk1500Quest}
      tokenReward(player)

on craft:
  if event-item is sugar:
    if {quests::%player%'s uuid::sugarQuest} is set:
      add 1 to {quests::%player%'s uuid::sugarQuest}
      send "&eYou have crafted %{quests::%player%'s uuid::sugarQuest} - 1%&e/128 sugar"
      if {quests::%player%'s uuid::sugarQuest} > 128:
        send "&eYou have completed the following quest:" to player
        send "" to player
        send "&eCraft 128 Sugar" to player
        delete {quests::%player%'s uuid::sugarQuest}
        tokenReward(player)
  if event-item is bread:
    if {quests::%player%'s uuid::breadQuest} is set:
      add 1 to {quests::%player%'s uuid::breadQuest}
      send "&eYou have crafted %{quests::%player%'s uuid::sugarQuest} - 1%&e/48 bread"
      if {quests::%player%'s uuid::sugarQuest} > 48:
        send "&eYou have completed the following quest:" to player
        send "" to player
        send "&eCraft 48 Bread" to player
        delete {quests::%player%'s uuid::breadQuest}
        tokenReward(player)

the part that rolls the quest is this part:

Code:
function getQuest(p: player):
  if {quests::%{_p}%'s uuid::*} is set:
    send "&cYou already have a ongoing quest!" to {_p}
  else:
    send "" to {_p}
    send "&eRolling you a random quest!" to {_p}
    send "" to {_p}
    wait 3 seconds
    chance of 5%: #Kill 50 Zombies
      zombieQuest({_p})
    chance of 5%: #Kill 50 Skeletons
      skeletonQuest({_p})
    chance of 5%: #Kill 50 Creepers
      creeperQuest({_p})
    chance of 5%: #Kill 50 Spiders
      spiderQuest({_p})
    chance of 5%: #Kill 40 Endermen
      endermanQuest({_p})
    chance of 5%: #Break 150 Blocks
      break150Quest({_p})
    chance of 5%: #Break 200 Blocks
      break200Quest({_p})
    chance of 5%: #Place 150 Blocks
      place150Quest({_p})
    chance of 5%: #Place 200 Blocks
      place200Quest({_p})
    chance of 5%: #Walk 1k Blocks
      walk1000Quest({_p})
    chance of 5%: #Walk 1.5k Blocks
      walk1500Quest({_p})
    chance of 5%: #Fish 25 Items
      fish25Quest({_p})
    chance of 5%: #Fish 30 Items
      fish30Quest({_p})
    chance of 5%: #Craft 128 Sugar
      sugarQuest({_p})
    chance of 5%: #Craft 48 Bread
      breadQuest({_p})
    chance of 5%: #Break 192 Cobble
      cobble192Quest({_p})
    chance of 5%: #Break 256 Cobble
      cobble256Quest({_p})
    chance of 5%: #Play For 30 Minutes
      play30Quest({_p})
    chance of 5%: #Play For 45 Minutes
      play45Quest({_p})
    chance of 5%: #Play For 1 Hour
      play1hQuest({_p})
      

command /quest:
  cooldown: 1 day
  trigger:
    getQuest(player)
 
The problem lies with the "chance of" event

"chance of" is unreliable, because each individual "chance of 5%" is calculated on it's own, not as a part of a whole 100%. So they all have a 5% chance which is why sometimes you get 0 and other times 2.

I recommend random integer
set {_random} to a random integer betweeen 1 and ...something you want
 
  • Like
Reactions: PureNuggets
The problem lies with the "chance of" event

"chance of" is unreliable, because each individual "chance of 5%" is calculated on it's own, not as a part of a whole 100%. So they all have a 5% chance which is why sometimes you get 0 and other times 2.

I recommend random integer
set {_random} to a random integer betweeen 1 and ...something you want
so how would i make the random integer then run one of the functions? would i do "if {_random} = 1"?
 
You could do:
Code:
set {_int} to a random integer between 1 and 5
if {_int} is 1:
    send "option1"
else if {_int} is 2:
    send "option2"
else if {_int} is 3:
    send "option3"
else if {_int} is 4:
    send "option4"
else if {_int} is 5:
    send "option5"
 
  • Like
Reactions: PureNuggets
There also MAY be a syntax for "chance of" that allows for multiple to chain together to make up 100% (AKA what you were trying to code originally). I've been away from skript for a while and I tried doing some research to find it, but couldn't.

EDIT: NVM there is NO SYNTAX for this. "if you use multiple chance of % expressions in a row then the chances in the expressions after the first one get screwed up since you have to consider the probability that the previous chance expressions aren't successful"

Also: if you want some things to have higher chances, then use if and else if with multiple integers based on how common you want it to be
 
  • Like
Reactions: PureNuggets
Status
Not open for further replies.