#how can i make a function that runs every time the player spawns

1 messages · Page 1 of 1 (latest)

coral lake
#

i have been trying to make a zombie origin for the origins mod and made the player catch on fire when under the sun
i wanted to add a safe period on spawn, but i have no idea how to make that condition

i can send a pic of the code if needed
actually, here it is

weak bayBOT
#

<@&1201956957406109788>

Someone will come and help soon!

💬 While you wait, take this time to provide more context and details.

🙇 If nobody has answered you by <t:1748005863:t>, feel free to use the Summon Helpers button to ping our helper team.

✅ Once your question has been resolved (or you no longer need it), please click Resolve Question or run /resolve

minor flare
#

you can make this grace period by checking the time_since_last_death statistic.

coral lake
#

👌

#

leme try real quick

minor flare
#

you have to add that scoreboard beforehand for the statistic to update that scoreboard automatically

coral lake
#

can you pls walk me trough this one?

#

i kinda suck

minor flare
#

first you have to add it in your load function.
scoreboard objectives add time_since_last_death

#

the name might be a bit different, i can't remember

#

idk how origin files are structured though

#

are conditions just predicates?

coral lake
#

i don't know what predicates means

#

but you can add your own stuff in tha code, it doesn't need to have the "origins:"

minor flare
#

predicates are just a bunch of conditions that can be referred to in a command, advancements, etc.. and they return either true or false

#

do you know what those files are in the conditions field?

coral lake
#

you mean in the picture i sent

#

ye

minor flare
#

if you could send the code of one of the files I can see what file type it is.

coral lake
minor flare
#

yeah, but that doesn't contain the origins:exposed_to_sun file

coral lake
#

i think that is just included in the mod tbh

#

i mean the original origins mod

#

do you really need that?

minor flare
#

I at least need to know if they are predicates or some kind of special origins condition check file

coral lake
#

alright

minor flare
#

if they are predicates, you can just add your own, if not, you have to make a weird and probably janky workaround (unless origin adds different stuff for that which idk)

coral lake
#

i think they should be predicates as you say, cuz in the interface their is an option for custom conditions

minor flare
#

You can then make a pretty simple value check predicate

coral lake
#

like this?

minor flare
#

not the id of the statistic, but the name you gave the objective

coral lake
#

ok

#

like THIS!!

#

i am big brain

#

now what

minor flare
#

in that field, you have to put this part scoreboard objectives add >>>grace_timer<<< time_since_last_death or whatever you called it. Not just any random name.

#

after that, you save the file and put the id to it in the list of conditions.

coral lake
#

so like
scoreboard objectives add >>>grace_timer<<< My_First_Ever_Thing

minor flare
#

no, the arrow were there to indicate the thing that I meant

coral lake
#

👌 understandable

minor flare
#

grace_time is the name in the example

coral lake
#

like this?
scoreboard objectives add My_First_Ever_Thing time_since_last_death

minor flare
#

yea

coral lake
#

now what?

coral lake
#

a

#

doing that now

#

question

#

what happens when the player first joins, where he hasn't ever died, so they don't have a time_since_last_death value?

#

and what happens when a player dies in a server, and then leaves? does the value keep counting?

#

also, what happens while the player is sitting in the death screen? does the value keep counting up?

minor flare
#
  • The value starts from 0 and constantly counts up. It just resets when you die.
  • It only counts up if the player is online
  • It only starts counting again when you pres respawn.
coral lake
#

majestic

#

testing it rn

#

wait, i'm stubid

#

i forgot to paste the new function file in the datapack

#

no

#

i just get the regular 3 secs or so of on spawn invulnerability

minor flare
#

hmm, maybe someone who knows origins can better help.

coral lake
#

you think i've done goofed up with the mins?

#

i am 1000% certain i just did something silly

minor flare
#

I something very silly

#

in the score filed you are supposed to ONLY put the name of the score

#

not the whole command that creates the scoreboard

coral lake
#

my custom one or the vanila

coral lake
#

👌 .

minor flare
#

also remove the part directly under that

coral lake
#

i feel like this is a lot better

coral lake
minor flare
#

looks correct now

coral lake
#

question
how does my custom value relate to the "time_since_last_death" value?

#

since it ain't writen anywere in the code, how does it connect

minor flare
#

it checks if value (your current score) is in the specified rang (1200 or more)

#

or what do you mean with custom value?

coral lake
#

i mean the "My_First_Ever_Thing" value
how is it linked to the player's "time_since_last_death"

minor flare
#

when you create that scoreboard it just reflects the statistics of the players

#

every player has their own score value in that scoreboard

#

My_First_Ever_Thing is just the name you gave the scoreboard with the type time_since_last_death

#

you can have multiple scoreboard with the same type and that's why you name them.

coral lake
#

how do i create a scoreboard?

#

i feel so dum

minor flare
#

Still with the same command in your load function -> scoreboard objectives add <scoreboard name> <scoreboard type>

coral lake
#

like how does that work

minor flare
#

do you now what a load function is?

coral lake
#

no

minor flare
#

there are two special function types in minecraft

  • tick: runs once every tick
  • load: runs every time you enter the world/start up the server or whne /reload is used
obsidian emberBOT
coral lake
#

do i just make an empty function with just the command?

minor flare
# obsidian ember

there is more to it than just a function file. I suggest you take a look at this. It is not very long and the relevant part is even shorter, so it really doesn't take that long.

coral lake
#

alright

#

i'm giving up and becoming an apple farmer

#

have a nice day and thank you for tolerating my incompetent ass

minor flare
#

?