#First script

1 messages · Page 1 of 1 (latest)

ashen frigate
#

I am still working on my first script but can't get it to work. i redid the thing multiple times. Butt I am still getting errors.

The script is supposed to limit playtime. everyday the players get an amout of additional time to play. Players should be able to save up to 50 hours.

Can someone please help me fix this error and any other that pop up? That would be really appreciated!

strong pewterBOT
#

Paste version of server.txt, playtime2.js from @ashen frigate

lime badgeBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

signal turret
#
if(event.player.persistentData.playtime >= event.player.persistentData.allowedtotalplaytime) {
    callback.server.runCommand("/kick " + player.getName().getString() + " Time to take a break!")
}
if(event.player.persistentData.playtime >= event.player.persistentData.allowedtotalplaytime) {
    callback.server.runCommand("/kick " + event.player.getName().getString() + " Time to take a break!")
}

Please exchange that first, we look further if a error occurs. ^^

Note: simple add event. bevor player.getName()

ashen frigate
#

I changed that, thank you for the help

#

Now there are no errors after /reload

#

But i am getting an error when trying /playtime

signal turret
#

Yep I already know about that. I tested your code a bit.
The problem is neither 'Serer' nor 'Player' is defined, my application is with Player so first delete:

Server.runCommand...

And then write... while also exchanging every event.player with player.

let player = ctx.source.entity.asKJS();
#

Something like

let player = ctx.source.entity.asKJS();
player.tell("you have " + String(Math.floor(((player.persistentData.allowedtotalplaytime - player.persistentData.playtime) / 1200)) + " minutes remaining"));
return 1;
ashen frigate
#

That seems to work, thank you once again.

#

I doubt this is the end of my troubles, but i am going to test it on my server with friends now.

#

Can I dm you if any problems occur?

signal turret
#

Yes you can DM me. But before I already tested a bit and got some troubles.
You need to set playtime to 0 when someone logs out, just add that to log out event.

#

Or you can make a timer/command for that to ensure that they can't just rejoin after being kicked once

ashen frigate
#

the playtime not going to 0 is by design because the totalallowedplaytime of a player also doesn't reset either. I did this because i found it a hassle to calculate the allowedplaytime for a player who has been offline for a while, because dailyplaytime can change and should not effect days that have already past.

#

and as for the can't rejoin after kick, I thought I already took car of that.

#

How do i get one of those fancy code boxes in discord?

signal turret
ashen frigate
#
event.server.schedule(1, event.player, function (callback) {
        if(event.player.persistentData.online == 0) {
            //if the player disconnected, stop this loop.
            return
        }
        if(event.player.persistentData.playtime >= event.player.persistentData.allowedtotalplaytime) {
            callback.server.runCommand("/kick " + event.player.getName().getString() + " Time to take a break!")
        }
        callback.reschedule(MINUTE)
    })
#

I thought this bit checked every minute whether the person has exceeded their total allowed playtime

#

and kick them if they did

#

and the first time it checks is one tick after login

signal turret
#

Yes it kicks them when the playtime extends the allowed playtime but the playtime never degreases and they can't come back on the server

ashen frigate
#

but event.player.persistentData.allowedtotalplaytime does increase

#
onEvent('level.tick', event => {
    tracker += 1
    if(tracker >= 1728000){
        totalallowedplaytime += dailyplaytime
    }
})
#

and

#

event.player.persistentData.allowedtotalplaytime = totalallowedplaytime * 72000

#

is done before the check happens in onEvent('player.logged_in', event => {

signal turret
#

Oh I didn't know for what you made them it was for that.

ashen frigate
#

i forgot to reset tracker to 0 tho

#
onEvent('level.tick', event => {
    tracker += 1
    if(tracker >= 1728000){
        totalallowedplaytime += dailyplaytime
        tracker = 0
    }
})
#

else the player gets more playtime every tick after 24 hours

signal turret
ashen frigate
#

thats a good idea

#

I will do that and I will test it on my server

signal turret
ashen frigate
#

sure lol

#

thx for the help, i will close this one now. If I run into any more isseus I will DM you.

signal turret
#

Yep then good luck testing. ^^