Server keeps crashing with gsc script

Topic created ยท 5 Posts ยท 113 Views
  • Recently I made a server for me and my friends to play on. I tried making a script, hoping I could make some sort of pause function.

    The script works fine, although it tends to crash around round 21-22 on origins. (sometimes earlier)
    The error keeps disappearing when i alt+tab out of the game ๐Ÿ˜ž


    I therefore have some questions:

    1. Does the t6 zombie server dump a crash log? If yes, where?
    2. Is there anything wrong in my script?
    3. Do you think that crash might be unrelated to my script?

    My script:

    #include maps\mp\_utility;
    #include common_scripts\utility;
    #include maps\mp\gametypes_zm\_hud_util;
    #include maps\mp\gametypes_zm\_hud_message;
    #include maps/mp/zombies/_zm_score;
    
    init()
    {
        level.perk_purchase_limit = 9;
        level.ammoPrice = 5000;
        level.ammoPriceIncrease = 1500;
        level.ammoPriceLimit = 17000;
    
        player.enableCommands = false;
    
        level waittill("connected", player);
        self iprintln("^2" +self.name + "^7 , Plugin loaded!");
        player thread welcome();
        level thread onPlayerMessage();
    
    }
    
    welcome() {
        self endon("disconnect");
        self waittill("spawned_player");
        wait(7);
        self iprintln("^2" +self.name + "^7 er ret sej!");
    }
    
    
    onPlayerMessage() {
        while (true) {
            level waittill("say", player, message);
    
    
            if (message == "m" && !player.moneyReceived) {
                player.score += 20000;
                player.moneyReceived = true;
            }
    
            if (message == "quick") {
                if (!(500 <= player.score)) {
                    player tell("Prisen er: 500");
                    return;
                }
    
                player.score -= 500;
                player thread givePerk("specialty_quickrevive");
            }
    
            if (message == "ammo?") {
                player tell("Prisen er: " + level.ammoPrice);
            }
            if (message == "ammo" ) {
                if (!(level.ammoPrice <= player.score)) {
                    player tell("Prisen er: " + level.ammoPrice);
                    return;
                }
    
                player.score -= level.ammoPrice;
                if (level.ammoPrice < level.ammoPriceLimit ) {
                    level.ammoPrice += level.ammoPriceIncrease;
                }
    
                player GivePowerUp("full_ammo");
            }
    
            if (message == "p") {
                if (player.maxHealth <= 250) {
                    player tell("Auto-heal enabled");
                    player.toggleHealing = true;
                    player.maxHealthDefault = player.maxHealth;
    
                    level.cmPlayerMaxHealth = 6000;
                    player setMaxHealth(6000);
                    player thread keepAlive();    
                }
            }
            if (message == "o") {
                player.toggleHealing = false;
                player setMaxHealth(player.maxHealthDefault);
                player notify("stopHealing");
                player tell("Auto-heal disabled");
            }
    
            wait(2);
        }
    }
    
    
    keepAlive() {
        self endon("stopHealing");
        while(player.toggleHealing) {
            if (player.health < player.maxHealth)
                self tell("Health: " + self.health + " / " + self.maxHealth);
            
            self setNormalHealth(self.maxHealth);
    
            wait(1);
        }
    }
    
    
    GivePowerUp(powerup_name) {
        if (!isDefined(level.zombie_include_powerups) || (!(level.zombie_include_powerups.size > 0)))     
            self iprintln("Power Ups ^1Not Supported ^7On This Map");
        else
        {
            level.powerup_drop_count = 0;
            powerup = level maps/mp/zombies/_zm_powerups::specific_powerup_drop(powerup_name, self.origin);
            if (powerup_name == "teller_withdrawl")
                powerup.value = 1000;
            powerup thread maps/mp/zombies/_zm_powerups::powerup_timeout();
            player tell("Power up: " + powerup_name + " was given");
        }
    }
    
    givePerk(perk) {
        self endon("disconnect");
        self endon("death");
        level endon("game_ended");
        self endon("perk_abort_drinking");
        if (!(self hasperk(perk) || (self maps/mp/zombies/_zm_perks::has_perk_paused(perk))))
        {
            gun = self maps/mp/zombies/_zm_perks::perk_give_bottle_begin(perk);
            evt = self waittill_any_return("fake_death", "death", "player_downed", "weapon_change_complete", "_cancel");
            if (evt == "weapon_change_complete")
                self thread maps/mp/zombies/_zm_perks::wait_give_perk(perk, 1);
            self maps/mp/zombies/_zm_perks::perk_give_bottle_end(gun, perk);
            if (self maps/mp/zombies/_zm_laststand::player_is_in_laststand() || isDefined(self.intermission) && self.intermission)
                return;
            self notify("burp");
        }
    }
    
    
    
    
  • #include maps\mp\_utility;
    #include common_scripts\utility;
    #include maps\mp\gametypes_zm\_hud_util;
    #include maps\mp\gametypes_zm\_hud_message;
    #include maps/mp/zombies/_zm_score;
    
    init()
    {
        level.perk_purchase_limit = 9;
        level.ammoPrice = 5000;
        level.ammoPriceIncrease = 1500;
        level.ammoPriceLimit = 17000;
    
        player.enableCommands = false; // <- player. can't be used there. In this point player is not defined
    
        level waittill("connected", player); // Without any loop this work just for the first player who join
       // You can use player.enableCommands = false here, if needed
        self iprintln("^2" +self.name + "^7 , Plugin loaded!"); // self.name is not defined because the entity is called player... so i s player.name
        player thread welcome();
        level thread onPlayerMessage();
    
    }
    
    welcome() {
        self endon("disconnect");
        self waittill("spawned_player");
        wait(7);
        self iprintln("^2" +self.name + "^7 er ret sej!");
    }
    
    
    onPlayerMessage() {
        while (true) {
            level waittill("say", player, message);
    
    
            if (message == "m" && !player.moneyReceived) { // player.moneyReceived not defined, you have to define it somewhere
                player.score += 20000;
                player.moneyReceived = true;
            }
    
            if (message == "quick") {
                if (!(500 <= player.score)) {
                    player tell("Prisen er: 500");
                    return;
                }
    
                player.score -= 500;
                player thread givePerk("specialty_quickrevive");
            }
    
            if (message == "ammo?") {
                player tell("Prisen er: " + level.ammoPrice); // idk if tell is a function, use iprintln or iprinlnbold
            }
            if (message == "ammo" ) {
                if (!(level.ammoPrice <= player.score)) {
                    player tell("Prisen er: " + level.ammoPrice);
                    return; // This will make the lopp end, so if you call this command all should stop
                }
    
                player.score -= level.ammoPrice;
                if (level.ammoPrice < level.ammoPriceLimit ) {
                    level.ammoPrice += level.ammoPriceIncrease;
                }
    
                player GivePowerUp("full_ammo");
            }
    
            if (message == "p") {
                if (player.maxHealth <= 250) {
                    player tell("Auto-heal enabled");
                    player.toggleHealing = true; // player.toggleHealing if is not a default var is not defined
                    player.maxHealthDefault = player.maxHealth; // same
    
                    level.cmPlayerMaxHealth = 6000;
                    player setMaxHealth(6000);
                    player thread keepAlive(); // When you call a loop, inside the loop funciont player become self   
                }
            }
            if (message == "o") {
                player.toggleHealing = false;
                player setMaxHealth(player.maxHealthDefault);
                player notify("stopHealing");
                player tell("Auto-heal disabled");
            }
    
            wait(2);
        }
    }
    
    
    keepAlive() { // in here where there change player. with self.
        self endon("stopHealing");
        while(player.toggleHealing) {
            if (player.health < player.maxHealth)
                self tell("Health: " + self.health + " / " + self.maxHealth);
            
            self setNormalHealth(self.maxHealth);
    
            wait(1);
        }
    }
    
    
    GivePowerUp(powerup_name) {
        if (!isDefined(level.zombie_include_powerups) || (!(level.zombie_include_powerups.size > 0)))     
            self iprintln("Power Ups ^1Not Supported ^7On This Map");
        else
        {
            level.powerup_drop_count = 0;
            powerup = level maps/mp/zombies/_zm_powerups::specific_powerup_drop(powerup_name, self.origin);
            if (powerup_name == "teller_withdrawl")
                powerup.value = 1000;
            powerup thread maps/mp/zombies/_zm_powerups::powerup_timeout();
            player tell("Power up: " + powerup_name + " was given");
        }
    }
    
    givePerk(perk) {
        self endon("disconnect");
        self endon("death");
        level endon("game_ended");
        self endon("perk_abort_drinking");
        if (!(self hasperk(perk) || (self maps/mp/zombies/_zm_perks::has_perk_paused(perk))))
        {
            gun = self maps/mp/zombies/_zm_perks::perk_give_bottle_begin(perk);
            evt = self waittill_any_return("fake_death", "death", "player_downed", "weapon_change_complete", "_cancel");
            if (evt == "weapon_change_complete")
                self thread maps/mp/zombies/_zm_perks::wait_give_perk(perk, 1);
            self maps/mp/zombies/_zm_perks::perk_give_bottle_end(gun, perk);
            if (self maps/mp/zombies/_zm_laststand::player_is_in_laststand() || isDefined(self.intermission) && self.intermission)
                return;
            self notify("burp");
        }
    }
    

    I hope I have identified many of the errors that may be causing your crashes. @rfoldbirk

  • @Sorex said in Server keeps crashing with gsc script:

        // player.moneyReceived not defined, you have to define it somewhere
        if (message == "m" && !player.moneyReceived) { 
            player.score += 20000;
            player.moneyReceived = true;
        }
    

    Interestingly gsc considers something undefined to be true. So in this case it works out fine, but something to keep in mind for the future.

  • @birchy yes thats true. If his intention was to definite when i write m is not a problem if not is a problem ๐Ÿ™‚ . I hope he will understend and can fix by his own ๐Ÿ™‚

  • Thank you @birchy & @Sorex for your help! I'll be fixing all of the errors that you have pointed out and hopefully it will work ๐Ÿ˜„

Log in to reply