Salagata

Fishing 2,

Oct 31st, 2025 (edited)
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.65 KB | Source Code | 0 0
  1. {if:{argslen}|=|0|then:{attach:https://cdn.discordapp.com/attachments/1124758334805909509/1433680765123563594/image.png?ex=690592c2&is=69044142&hm=ca1fd851ee5b3a0e7e9f063a11e818bbb955ba305a3b1883777caadff93509ab&}
  2. Inspired in `.tag fishing` by <@1056191069206876161> {embedjson:{"title":"Welcome to Fishing!","image":{"url":"attachment://image.png"},"description":"## Commands\n`{prefix}tag {tagname} fish` - fish a fish and adds it to the bucket.\n`{prefix}tag {tagname} check` - checks your fishes in the bucket (the table).\n`{prefix}tag {tagname} sell` - sells the whole bucket.\n`{prefix}tag {tagname} wallet` - checks the wallet.\n-# more commands documented soon.","color":"50175"}}|else:
  3. {note:Define the library}
  4.  
  5. {note::fish.bucket: The user's bucket, @user, up to 200, one more and the first above will be thrown away @type {csv}
  6. @columns type, weight, price
  7. @column type {string} - The fish
  8. @column weight {number} - The weight in Kg
  9. @column price {number} - The price of the fish}
  10.  
  11. {note::fish.wallet: The user's money, @user, saved in a wallet @type number}
  12.  
  13. {note::fish.bucket.held: The amount of fishes in the user's bucket, user#fish.bucket, @type number, @getter}
  14. {set:fish.bucket.held|{ignore:
  15. {length:{replace:.+(,).+,.+,.+,.+(?:\n?)|$1|{getuser:fish.bucket}}}
  16. }}
  17.  
  18. {note::fish.TABLE: The CSV table of all possible fishes @type {csv}
  19. @columns type, emoji, minkg, maxkg, price
  20. @column type {string} - The fish
  21. @column emoji {number} - Just an emoji
  22. @column minkg {number} - The minimun weight (in kg) used to calculate the weight
  23. @column maxkg {number} - The maximun weight (in kg) used to calculate the weight
  24. @column price {number} - The price of the fish per kilogram}
  25. {set:fish.TABLE|salmon,🐟,2.5,9.1,7.99
  26. bass,🐟,0.5,13.5,10.99}
  27.  
  28.  
  29. {note::fish.fish(): Returns an array with the fish chosen from the table, size in Kg, and price, @uses {math}
  30. @returns [chosen,kg,price] - An array with the fish chosen, weight and price}
  31. {set:fish.fish()|{ignore:
  32. {note:Choosing a random fish from the table}
  33.  
  34. {set:fish.fish.chosen|{eval:{bracketleft}choose:{traversejson:0|["{replace:\r\n|\u007c|{replace:(.+),.+,.+,.+,.+|$1|{get:fish.TABLE}}}"]}{bracketright}}}
  35. {note:Calculating Size and Price with the math library}
  36.  
  37. {evalsilent:{replace:{get:fish.fish.chosen},(.+),(.+),(.+),(.+)|in:{get:fish.TABLE}|with:{ignore:{set:fish.fish.kg|{math:K = round($2 + ($3-$2) * round(random(),10),2)}} {set:fish.fish.price|{math:round(K*$4,2)}}}}}
  38. {note:Return value}
  39. {set:retx|[{jsonify:{get:fish.fish.chosen}},{get:fish.fish.kg},{get:fish.fish.price}]}
  40. {delete:fish.fish.chosen} {delete:fish.fish.kg} {delete:fish.fish.price}
  41. }}
  42.  
  43. {note::fish.calculateBucketPrice() calculate the price of all fishes in the bucket + the wallet, user#fish.bucket user#fish.wallet, @uses {math}}
  44. {set:fish.calculateBucketPrice()|{ignore:
  45. {set:retx|{math:round({replace:\r\n|+|{replace:.+,.+,(.+)|$1|{getuser:fish.bucket}}}+{getuser:fish.wallet|0},2)}}
  46. }}
  47.  
  48. {note::fish.addToBucket(type,kg,price): After fishing, adds the fish to the botton of the user's bucket, user#fish.bucket
  49. @param {string} type - Type of fish caught
  50. @param {number} kg - The weight of the fish
  51. @param {number} price - The price
  52. }
  53. {set:fish.addToBucket()|{ignore:
  54. {set:fish.addToBucket.newBucket|{getuser:fish.bucket}
  55. {get:fish.addToBucket(type)},{get:fish.addToBucket(kg)},{get:fish.addToBucket(price)}}
  56. {if:{eval:{get:fish.bucket.held}}|>|200|then:{note:Max capacity of the bucket reached}
  57. {set:fish.addToBucket.safeBucket|{replace:\n|!|{get:fish.addToBucket.newBucket}}}
  58. {set:fish.addToBucket.newBucket|{replace:!|
  59. |{substring:{substring:|{indexof:!|{get:fish.addToBucket.safeBucket}}}|1}}}
  60. }
  61. {setuser:fish.bucket|{get:fish.addToBucket.newBucket}}
  62. {delete:fish.addToBucket.newBucket} {delete:fish.addToBucket.safeBucket}
  63. {delete:fish.addToBucket(type)} {delete:fish.addToBucket(kg)} {delete:fish.addToBucket(price)}
  64. }}
  65.  
  66.  
  67. {note:Define the operations}
  68.  
  69. {note::.tag {tagname} fish
  70. Fish a fish
  71. @displays {embed}}
  72. {if:{arg:0}|=|fish|then:
  73.  
  74. {eval:{get:fish.fish()}}
  75.  
  76. {set:fish.addToBucket(type)|{traversejson:0|{get:retx}}}
  77. {set:fish.addToBucket(kg)|{traversejson:1|{get:retx}}}
  78. {set:fish.addToBucket(price)|{traversejson:2|{get:retx}}}
  79.  
  80. {embedjson:{"author":{"name":"{usertag}","icon_url":"{avatar}"},"title":"You got a catch!","color":50175,"description":"wakasagihime caught a {traversejson:0|{get:retx}} ({traversejson:1|{get:retx}} kg) for {traversejson:2|{get:retx}} :dollar:","footer":{"text":"Wakasagihime helps you Fishing!","icon_url":"https://cdn.discordapp.com/attachments/1124758334805909509/1381080863726633071/google-images.png?ex=687af349&is=6879a1c9&hm=223ccb3f3bc1490e71ea6721d1c516ac8b9d6349419370b6e64dd86bcdbf2064&"}}}
  81.  
  82. {eval:{get:fish.addToBucket()}}
  83. }
  84.  
  85. {note::.tag {tagname} check
  86. Checks the fishes in the bucket,
  87. @displays {csv} user#fish.bucket
  88. @columns type, weight, price
  89. @column type {string} - The fish
  90. @column weight {number} - The weight in Kg
  91. @column price {number} - The price of the fish}
  92. }
  93. {if:{arg:0}|=|check|then:
  94. {note::@todo prettier display}
  95. {getuser:fish.bucket}
  96. }
  97.  
  98. {note::.tag {tagname} wallet
  99. Checks the wallet
  100. @displays {number} user#fish.wallet}
  101. {if:{arg:0}|=|wallet|then:
  102. {getuser:fish.wallet|0}
  103. }
  104.  
  105. {note::.tag {tagname} sell
  106. Sells all the fishes, then, adds the money to the wallet}
  107. {if:{arg:0}|=|sell|then:
  108.  
  109. {eval:{get:fish.calculateBucketPrice()}}
  110. {setuser:fish.wallet|{get:retx}}
  111. {setuser:fish.bucket|}
  112. }
  113.  
  114. {note::.tag {tagname} debug
  115. @debug @testcode
  116. @restricted
  117. @owneronly
  118. }
  119. {if:{arg:0}|=|debug|then:{if:{id}|=|1005205558497906839|then:
  120. {eval:{substring:{args}|{indexof:{arg:1}|{args}}}}
  121. |else: {exit: :warning: You don't have enough permissions to do this}}}
  122.  
  123.  
Advertisement
Add Comment
Please, Sign In to add comment