Jump to content
lex__1

Safe time

Recommended Posts

We are a team of entry-level enthusiasts, lacking scripting skills. Need your help.
We want to create and configure a private server with a tough scenario of survival in the complex (aggressive) and changeable nature of the post-apocalypse. But there is one unpleasant moment. When a server or client restarts (crashes), the player has almost no time to react to events around while the character is loading. We need a script that will give the character a safe time of 2-3 minutes from the moment of entering the server. It should be like (if you know the safe zone scenario), how the character leaves the safe zone - a time counter occurs when the character is still protected from the threat.
How can this be implemented?
I apologize for my English, if something is not correctly translated.

Edited by lex__1

Share this post


Link to post
Share on other sites

This code works technically, but it won't show a countdown timer like it does when you leave a trader, but that's for someone else to figure out.
Just put it in your servers init.c, at the bottom of the class CustomMission. The client doesn't have to do anything.
All you have to do is to set how many minutes you want the user to have god mode (won't take damage). It's set to 2 minutes by default.
10 seconds before the god mode is removed the user will get a warning.

I haven't bug tested the code much so I have no idea how well it works with other mods or modifications in effect.
I'm no expert at coding, so I'm sure it can be done prettier, but this is what I can give you.

class CustomMission: MissionServer
{




	// All the standard code goes here.







	// Code for god mode upon spawning starts here. Only paste this code into init.c
	override void InvokeOnConnect(PlayerBase player, PlayerIdentity identity)
	{
		super.InvokeOnConnect(player, identity);
		player.SetAllowDamage(false);

		// Set in minutes for how long you want the player to have god mode upon spawning into the game. Don't edit anything else unless you know what you are doing.
		int godModeTimer = 2;
		
		int godModeTimerMS = godModeTimer * 60000;
		
		string message = "You now have god mode for " + godModeTimer + " minutes.";
		GetGame().GetCallQueue(CALL_CATEGORY_GAMEPLAY).CallLater(DisplayMessage, 10000, false, player, message);
		
		GetGame().GetCallQueue(CALL_CATEGORY_GAMEPLAY).CallLater(RemoveGodMode, godModeTimerMS, false, player);
		
		int warningTime = godModeTimerMS - 10000;
		message = "Your god mode will be removed in 10 seconds.";
		GetGame().GetCallQueue(CALL_CATEGORY_GAMEPLAY).CallLater(DisplayMessage, warningTime, false, player, message);
	}
	
	void RemoveGodMode(PlayerBase player)
	{
		player.SetAllowDamage(true);
		DisplayMessage(player, "Your god mode has been removed.");
	}
	
	void DisplayMessage(PlayerBase player, string message)
	{
		Param1<string> m_MessageParam = new Param1<string>(message);
		GetGame().RPCSingleParam(player, ERPCs.RPC_USER_ACTION_MESSAGE, m_MessageParam, true, player.GetIdentity());
	}
	// Code for god mode upon spawning ends here. Don't paste anything else into init.c.

};

 

Edited by NoBeansForMe
  • Thanks 1

Share this post


Link to post
Share on other sites
19 hours ago, NoBeansForMe said:

This code works technically, but it won't show a countdown timer like it does when you leave a trader, but that's for someone else to figure out.
Just put it in your servers init.c, at the bottom of the class CustomMission. The client doesn't have to do anything.
All you have to do is to set how many minutes you want the user to have god mode (won't take damage). It's set to 2 minutes by default.
10 seconds before the god mode is removed the user will get a warning.

I haven't bug tested the code much so I have no idea how well it works with other mods or modifications in effect.
I'm no expert at coding, so I'm sure it can be done prettier, but this is what I can give you. 

 

Thank you very much, I will try your option

Share this post


Link to post
Share on other sites
On 5/19/2020 at 10:04 PM, NoBeansForMe said:

All you have to do is to set how many minutes you want the user to have god mode (won't take damage). It's set to 2 minutes by default.
10 seconds before the god mode is removed the user will get a warning.

Thank you for your help. It works very well and does its job. We tried different times for a timeout, left the ego for 30 seconds. This time is enough to navigate the situation after loading the screen.

  • Beans 1

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×