self waittill("spawned_player"); not working properly

Topic created · 3 Posts · 78 Views
  • Hey guys,
    So I've a 'noobFriendly()' function in which I give the late coming player Juggernog and Money.

    It works when the player spawns. That's ok. The problem is this function is running even when spectating, pre-spawning.

    Can someone help me??

    init()
    {
    	level.perk_purchase_limit = 9;
    	level.get_player_weapon_limit = 3;
    	thread gscRestart();
            thread setPlayersToSpectator();
            level thread onPlayerConnect();
           for(;;)
           {
            level waittill("connected", player);
    		player thread [[level.givecustomcharacters]]();
          }
    }
    
    onPlayerConnect()
    {
        for(;;)
        {
            level waittill("connected", player);
            player thread onPlayerSpawned();
           	player thread noobFriendly();
           	self iprintln("^2Bem-vindo ao Zombies ^1Gangorra Aidetica!");
        }
    }
    
    onPlayerSpawned()
    {
        self endon("disconnect");
    	level endon("game_ended");
        for(;;)
        {
            self waittill("spawned_player");
    		// Will appear each time when the player spawn, that's just an exemple.
    		//self iprintln("^2Bem-vindo ao Zombies ^1Gangorra Aidetica!");
        }
    }
    
    noobFriendly()
    {
    	self endon("disconnect");
    	level endon("game_ended");
    	alreadySpawned = false; //to avoid rewarding when RE-spawning | not tested
    	for(;;)
    	{
    		self waittill("spawned_player");
    		wait 7;
    		if(level.round_number > 1 && !alreadySpawned)
    		{
    			alreadySpawned = true;
    			reward = level.round_number * 500;
    			self.score += reward;
    			self iPrintln("^7Voce recebeu ^1Juggernaut e ^2$" + reward + " ^7para nao ficar em desvantagem.");
    			self doGivePerk("specialty_armorvest");
    		}
    	}
    }
    
  • Can't help you without the full script.

  • @Xerxes

    This was the relevant part because this script has a lot of fixes such as tombstone and map restart, but I ended up fixing it by myself.

    In general here's what I did:

    player thread noobFriendly();
    to
    self thread noobFriendly();
    on onPlayerConnect() solved the most part of the problem.

    Also, moving the call of noobFriendly() from onPlayerConnect() to onPlayerSpawn()

    and removing the infinite loop on onPlayerSpawn() because for my script it's simply unnecessary.

    I'm a front-end dev with some years of back-end experience and still getting the hang of lua.

    We can happily close this thread

Log in to reply