Coding Questions And Answers

This thread is purely for coding questions (aka “how to code…”). I created a separate topic so that I can respond to tasks faster and also, this topic will be useful in that the section of the forum dedicated to Creative + will not be littered with the same type of questions: the answers to them will most likely already be provided here (in the event that you find a question similar to yours here).

Please do not ask the same / almost identical questions, the questions themselves must be clearly and precisely formulated so that there are no misunderstandings. Before writing a code question, think about what exactly you want from the code and what function this code should perform. I ask about this due to the fact that many themselves do not fully understand what kind of code they want.

Also, please do not flood with questions, that is, your question should preferably be one, not divided into several consecutive answers. This is optional, but I personally think that it will be much more convenient for me and for you.

The complexity of the code is not important, the question can be both banal and incredibly complex - I will answer any. In the event that the user did NOT receive an answer to the question posed (I was offline and could not answer) - I have nothing against other coders answering the question. You should not answer the same question several times (unless you have a better solution than the previous one).

PS: If your code didn’t work or function properly then do not create a new thread nagging about it. Instead, wait for me to come in-game and fix it for you.

6 Likes

i would love to know how to make the players not able to regenerate there health

1 Like

To cancel regeneration, you can try like this:
Chain 1 : Player event join >> If variable Exists [NOT] {Dynamic variable %function_already_running%} >> Set variable increment {Dynamic variable %function_already_running%}(Number variable = 1) >> Call function “a”

Chain 2: Player event join >> If variable exists [NOT] {Dynamic variable %player%joined_first_time} >> Set variable increment [+=] {Dynamic variable %player%joined_first_time}(Number variable = 1) >> Set variable = {Dynamic variable %player%current_hp1}(Game value current health)

Chain 3: Function “a” >> Select object (All players) >> Player action damage (Number variable = 0.01) >> Game action wait {Number variable = 1} >> Call function “a”

Chain 4: Player event takes damage >> Player action health (Number variable = 0.01) >> Set variable = {Dynamic variable = %player%current_hp2}(Game value current health) >> If variable compare numbers {Dynamic variable %player%current_hp2} > [Greater than] {Dynamic variable %player%current_hp1} >> Player action set health (Dynamic variable %player%current_hp1) >> Else >> Set variable = {Dynamic variable %player%current_hp1}(Dynamic variable %player%current_hp2)

Notes:
Dynamic variable %player%current_hp1, %player%joined_first_time needs to be saved. To save it simply press right-click + shift the dynamic variable.
To get “If variable exists [NOT]” like above use the “Not arrow” which can be found inside the gold ingot named “Coding Utilities”. After that right click the sign to change it to [NOT].

3 Likes

How to make so the entity always looking at the player. Like a turret.

1 Like

This question is pretty difficult but the most simple way is to use trigonometry functions. First, we need to calculate the vector direction/angles to change the entity’s yaw by subtracting the x2 with x1, y2 with y1. After that divide it by eachother and use taylor series to calculate the inverse tangent function of it. Then spawn the snowball using the vector formula to spawn in front of its face and launch it to the player’s location.

2 Likes

How to check if an entity interacts with an object, like an algorithm.

Set up a recursive function with the speed of 0.002< seconds. Check if there block(s) at location from the fireballs (x+1), (x-1), (z+1), (z-1) using set location values. If there is then call a different function and the entity has successfully interacted with a certain object. Or if you wanna check if an entity interacts with a different entity then simply assign its location to a dynamic variable and check if there are any entities near that variable/location.

2 Likes

How to compute the sine and cosine of a value

Divide theta by 180 to convert it to radian then multiply by n(pi). After that simply use taylor series. This method uses basic operations and does not require any looping like the CORDIC algorithm.

2 Likes

how to code custom scoreboard? Like other good games that have the number is colored and have lines

Scoreboard? You gotta specify what you wanted it to show.

2 Likes

ugh lemme take a pic from some1 game’s scb

Like this one:
scb

Chain 1: Player event join → If variable exists [NOT] {Dynamic variable %function_already_running%} → Set variable increment += {Dynamic variable %function_already_running% += 0} → Game action starts loop “sb”

Chain 2: Loop (sb) → Select object player name equals (%selected%) → Game action delete scoreboard (%selected%sb_status) → Game action create scoreboard (%selected%sb_status) → Game action create new string (Name = %selected%sb_status; Text = %selected% (username); Score: 1) → Player action show scoreboard (%selected%sb)

I’m not gonna waste my time writing the entire essay depicting how to code the entirety of it. To make it like 6.35M shown above divide the current balance by 1mil and round it by 1 → 3 decimal(s) then use the output variable results and put it inside the text/string slot to create a new string.

2 Likes

use combine text to make the score have colors?

Yes, combine the text and the dynamic variable/game value and use the output variable as the result.

1 Like

Make a guide on how to code @pay (player name ) (amount)
And also on how to use phase number to extract number from our msg

Chain 1: Player event chat → If variable contains (Game value chat message, @pay) → If variable not equals (%player%truncating != 1)-> Set variable = (%player%truncating = 1) → Set variable truncate text (%player%truncate_variable, Game value chat message, position#0 → position#5)

Chain 2: Player event join → If variable exists [NOT] (function_triggered) → Set variable increment += (function_triggered += 0) → Call function (recursive truncating function)

Chain 3: Function (recursive truncating function) → Select object all player(s) → Player action damage (0.001>) → Game action wait (1 tick) → Call function (recursive truncating function)

Chain 4: Player event take damage → If variable = (%player%truncating = 1) → If variable = (%player%truncating_posstart != 1) → Set variable = (%player%truncating_posstart = 1) → Set variable retrieve string length (%player%string_length, %player%truncate_variable) → Set variable truncate text (%player%truncate_variable, Game value chat message, position#1, position#[%player%string_length]) → Set variable = (%player%text_truncating = 1) → Set variable combine text (%player%name, %player%name and %player%truncate_variable] → else → call function (a)

Chain 5: Function (a) → If variable equals (%player%text_truncating = 1) → Set variable increment += (%player%position1 += 1), (%player%postion2 += 1) → Set variable truncate text (%player%truncate_variable, Game value chat message, position1[%player%position1], position2[%player%position2]) → Call function (b) → Else → If variable equals (%player%text_truncating = 2) → Call function (c)

Chain 6: Function (b) → If variable equals (%player%truncate_variable != &r) → Set variable combine text (%player%name = %player%name and %player%truncate_variable] → Else → Set variable equals (%player%text_truncating = 2)

Chain 7: Function (c) → Set variable increment += (%player%position1 += 1), (%player%postion2 += 1) → Set variable truncate text (%player%truncate_variable, Game value chat message, position1[%player%position1], position2[%player%position2]) → If variable compare number (%player%position2 >= 15) → Set variable combine text (%player%balance_to_be_sent = %player%balance_to_be_sent, %player%truncate_variable) → Else → Set variable truncate text (%player%truncate_variable, Game value chat message, position#0, position2[%player%position2 - 1]) → Set variable combine text (%player%balance_to_be_sent = %player%balance_to_be_sent, %player%truncate_variable) → Set variable parse number (%player%balance_to_be_sent, %player%balance_to_be_sent) → Set variable = (%player%truncating = 0) → Select object player name equals = (%player%name) → Set variable sum + (%selected%balance = %default%balance_to_be_sent + %selected%balance)

2 Likes

How to check how many players are there in a certain region and also how to check how many entities are there in the world?

Function (a) → Select object player(s) near region → Set variable increment += (total_players_in_the_region += 1)

About entities, use this:

Function (a) → Select object entity(s) near region → Set variable increment += (total_entities_in_the_region += 1)

Since mineland world is a cube-shape you gotta loop through every entity by assigning to each of them a different ID number then make a recursive function and increase it then select it and check if its x y z coordinate location is greater than X1 Y1 Z1 and smaller than X2 Y2 Z2 (adjacent angles).

2 Likes