Sign in to follow this  
={FMJ}=Smiley

Script Change - Help

Recommended Posts

Hi All,

This is all a learning curve of course but I have a second welcome script that works fine. But the message comes after every spawn and I only want it on connection. There is more to the script but the main part is here I think.

init()
{
    level thread onPlayerConnect();
}
onPlayerConnect()
{
    for( ;; )
    {
        level waittill( "connecting", player );
        player thread onPlayerSpawned();
    }
}
onPlayerSpawned()
{
    for( ;; )
    {
        self waittill( "spawned_player" );
wait 5;
        thread welcomeText(self,"","=FMJ=FullMetalJacket",getRandomColor());
wait 20;
        thread welcomeText(self,"","Visit Our Home Page @fmjcod4.com",getRandomColor());
    }
}

 

I tried playing a bit with it but then it never worked at all and so it is back to how it was for now. The whole script is attached. Any ideas how to change it please? I tried moving the welcomme text to the above section but guess I am doing it wrong. Thanks as always.

Smiley.

welcome2.gsc

Share this post


Link to post
Share on other sites

You have a never-ending loop constantly waiting for the player to spawn. Also, you need the player (self) to thread the function so that level doesn't.

Your old code.

onPlayerSpawned()
{
	//No reason for this to be in a loop below.
    for( ;; )
    {
        self waittill( "spawned_player" );
		wait 5;
        thread welcomeText(self,"","=FMJ=FullMetalJacket",getRandomColor());
		wait 20;
        thread welcomeText(self,"","Visit Our Home Page @fmjcod4.com",getRandomColor());
    }
}

This doesn't need to be in a loop at all, if you want it to only display after the first spawn remove the loop.

I would also added a endon disconnect so it doesn't throw errors if a player connects then leaves. And added the self thread.

 

onPlayerSpawned()
{
	self endon("disconnect");
	self waittill( "spawned_player" );
	wait 5;
	self thread welcomeText(self,"","=FMJ=FullMetalJacket",getRandomColor());
	wait 20;
	self thread welcomeText(self,"","Visit Our Home Page @fmjcod4.com",getRandomColor());
}

 

Also, what I will tell you is that the function names at the begging of the script (onPlayerConnect, onPlayerSpawned) are confusing and I had this same issue when copying other people's scripts at the beginning of my scripting career. I renamed them to actually mean what they are doing.

 

I renamed them and fixed your script.

main()
{
    level onPlayerConnecting();
}
 
onPlayerConnecting()
{
    self endon("intermission");
   
    while(1)
    {
        self waittill("connected", player);
       
        player thread onPlayerConnected();
    }
}
 
onPlayerConnected()
{
    self endon("intermission");

    self endon("disconnect");

	self waittill("spawned_player");
    
    self thread onPlayerSpawn();
}

onPlayerSpawn()
{
    	wait 5;
        self thread welcomeText(self,"","=FMJ=FullMetalJacket",getRandomColor());
		wait 20;
        self thread welcomeText(self,"","Visit Our Home Page @fmjcod4.com",getRandomColor());
}

 

Everything in the onPlayerSpawn() function will happen as soon as the player spawns for the first time.

Edited by Airitech
  • Like 1

Share this post


Link to post
Share on other sites

@Airitech 

Thanks a lot for your help and the detailed explanation. Very much appreciated. Script works fine.👌

A long way to go for me scripting wise but good to keep the brain matter ticking away. 🙂 

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this