Jump to content
Gizda

Scripting

Recommended Posts

maybe someone knows the script to create a safe zone like in arma 3?

Share this post


Link to post
Share on other sites

@smasht simple safezones are possible, however without fancy texts & stuff

It is possible by getting the players position, checking if the player is within your safezone and disabling/enabling their damageable state in OnTick, dunno how this will impact performance.

Example

player.SetAllowDamage(true/false); // Activate/deactive damage

player.GetPosition(); // Player position (X,Y,[Z]) ||

// Checking if x, y coords in square || Replace this with dynamic version for best practice reasons
bool IsInSafezone(float x, float y) {
	float min_x = 0.0, max_x = 0.0, min_y = 0.0, max_y = 0.0; // Replace this with actual coordinates
	if(x > min_x && x < max_x && y > min_y && y < max_y) return true;
    return false;
}

 

Edited by philippj
  • Beans 1

Share this post


Link to post
Share on other sites

Could you elaborate a little, which file should I add this too as I Am willing to test it out been waiting for safezones for 5years

Share this post


Link to post
Share on other sites

I wont provide a full code solution because i dont want to spread untested code.

I have not looked into the exact result of GetPosition thus the code needs to be changed accordingly . Also you have to define your safezone coordinates.

Possible solution (if the GetPosition thingy is adjusted):

init.c (Add to "CustomMission" (if default) or your adaption of "MissionServer")

bool IsInSafezone(float x, float y) {
	float min_x = 0.0, max_x = 0.0, min_y = 0.0, max_y = 0.0; // Replace this with actual coordinates
	if(x > min_x && x < max_x && y > min_y && y < max_y) return true;
    return false;
}

override void OnUpdate(float timeslice)
	{
		UpdateDummyScheduler();
		TickScheduler(timeslice);
		UpdateLogoutPlayers();	
		ref array<Man> players = new array<Man>;
		GetGame().GetPlayers( players );
			
		for ( int i = 0; i < players.Count(); i++ )
		{
			PlayerBase player;
			Class.CastTo(player, players.Get(i));
            float x, y, z = player.GetPosition(); // NOT WORKING
			if(IsInSafezone(x, y) {
                  player.SetAllowDamage(false);                           
            } else {
                  player.SetAllowDamage(true);                          
            }
		}
	}

 

  • Like 1
  • Beans 1

Share this post


Link to post
Share on other sites

To follow this up: Radial zones

bool IsInRadialZone(float x, float y, float center_x, float center_y, float radius) {
    // keep distance squared because squaring is cheaper then sqrt
	float distance_squared = Math.Pow(center_x-x, 2) + Math.Pow(center_y-y, 2);
	return (distance_squared < Math.Pow(radius, 2));
}

 

Also GetPosition returns a vector so 

vector pos = player.GetPosition();
float x = pos[0];
float y = pos[1];

should do the trick

  • Like 1

Share this post


Link to post
Share on other sites
33 minutes ago, philippj said:

To follow this up: Radial zones


bool IsInRadialZone(float x, float y, float center_x, float center_y, float radius) {
    // keep distance squared because squaring is cheaper then sqrt
	float distance_squared = Math.Pow(center_x-x, 2) + Math.Pow(center_y-y, 2);
	return (distance_squared < Math.Pow(radius, 2));
}

 

Also GetPosition returns a vector so 


vector pos = player.GetPosition();
float x = pos[0];
float y = pos[1];

should do the trick

Many thanks for the response and help! I have not quite figured out how to use this script for the test. If possible, explain in more detail where to insert this code.

Share this post


Link to post
Share on other sites
1 hour ago, philippj said:

Also GetPosition returns a vector so 


vector pos = player.GetPosition();
float x = pos[0];
float y = pos[1];

should do the trick

when you turn on the debugging monitor, it monitors your position in real time, maybe this is something you can use for code?

Share this post


Link to post
Share on other sites

Place this inside "CustomMission", change your safezone coordinates and you have a rudimentary safezone. It really isnt great but it works.

    bool IsInRadialZone(float x, float y, float center_x, float center_y, float radius) {
        // keep distance squared because squaring is cheaper then sqrt
        float distance_squared = Math.Pow(center_x-x, 2) + Math.Pow(center_y-y, 2);
        return (distance_squared < Math.Pow(radius, 2));
    }
    
    override void OnUpdate(float timeslice)
    {
        UpdateDummyScheduler();
        TickScheduler(timeslice);
        UpdateLogoutPlayers();    
        ref array<Man> players = new array<Man>;
        GetGame().GetPlayers( players );
            
        float safezone_center_x = 0.0;
        float safezone_center_y = 0.0;
        float safezone_radius = 0.0;
          
        for ( int i = 0; i < players.Count(); i++ )
        {
            
            PlayerBase player;
            Class.CastTo(player, players.Get(i));
            vector pos = player.GetPosition();
            if(IsInRadialZone(pos[0], pos[2], safezone_center_x, safezone_center_y, safezone_radius)) {
                player.SetAllowDamage( false );
            } else { player.SetAllowDamage( true ); }
        }
    }
  • Like 1

Share this post


Link to post
Share on other sites
8 minutes ago, philippj said:

...

Very cool! Soon check and write down how it works! one question: "float safezone_radius = 0.0;" value in meters from the center?

Share this post


Link to post
Share on other sites
Just now, Gizda said:

Very cool! Soon check and write down how it works! one question: "float safezone_radius = 0.0;" value in meters from the center?

yes

Share this post


Link to post
Share on other sites

void main()
{

	Hive ce = CreateHive();
	if ( ce )
		ce.InitOffline();

	Weather weather = g_Game.GetWeather();

	weather.GetOvercast().SetLimits( 0.0 , 1.0 );
	weather.GetRain().SetLimits( 0.0 , 1.0 );
	weather.GetFog().SetLimits( 0.0 , 0.25 );

	weather.GetOvercast().SetForecastChangeLimits( 0.0, 0.2 );
	weather.GetRain().SetForecastChangeLimits( 0.0, 0.1 );
	weather.GetFog().SetForecastChangeLimits( 0.15, 0.45 );

	weather.GetOvercast().SetForecastTimeLimits( 1800 , 1800 );
	weather.GetRain().SetForecastTimeLimits( 600 , 600 );
	weather.GetFog().SetForecastTimeLimits( 1800 , 1800 );

	weather.GetOvercast().Set( Math.RandomFloatInclusive(0.0, 0.3), 0, 0);
	weather.GetRain().Set( Math.RandomFloatInclusive(0.0, 0.2), 0, 0);
	weather.GetFog().Set( Math.RandomFloatInclusive(0.0, 0.1), 0, 0);
	
	weather.SetWindMaximumSpeed(15);
	weather.SetWindFunctionParams(0.1, 0.3, 50);
}

class CustomMission: MissionServer
{	
	void SetRandomHealth(EntityAI itemEnt)
	{
		int rndHlt = Math.RandomInt(40,100);
		itemEnt.SetHealth("","",rndHlt);
	}

	override PlayerBase CreateCharacter(PlayerIdentity identity, vector pos, ParamsReadContext ctx, string characterName)
	{
		Entity playerEnt;
		playerEnt = GetGame().CreatePlayer(identity, characterName, pos, 0, "NONE");//Creates random player
		Class.CastTo(m_player, playerEnt);
		
		GetGame().SelectPlayer(identity, m_player);
		
		return m_player;
	}
	
	override void StartingEquipSetup(PlayerBase player, bool clothesChosen)
	{
/*
		player.RemoveAllItems();

		EntityAI item = player.GetInventory().CreateInInventory(topsArray.GetRandomElement());
		EntityAI item2 = player.GetInventory().CreateInInventory(pantsArray.GetRandomElement());
		EntityAI item3 = player.GetInventory().CreateInInventory(shoesArray.GetRandomElement());
*/
		EntityAI itemEnt;
		ItemBase itemBs;
		
		itemEnt = player.GetInventory().CreateInInventory("Rag");
		itemBs = ItemBase.Cast(itemEnt);
		itemBs.SetQuantity(4);
		SetRandomHealth(itemEnt);

		itemEnt = player.GetInventory().CreateInInventory("AliceBag_Black");
		itemBs = ItemBase.Cast(itemEnt);
		
		
		//itemEnt = player.GetInventory().CreateInInventory("PortableGasLamp");
		itemBs = ItemBase.Cast(itemEnt);
		
		
		
	}
};
  
Mission CreateCustomMission(string path)
{
	return new CustomMission(bool IsInRadialZone(float x, float y, float center_x, float center_y, float radius) {
        // keep distance squared because squaring is cheaper then sqrt
        float distance_squared = Math.Pow(center_x-x, 2) + Math.Pow(center_y-y, 2);
        return (distance_squared < Math.Pow(radius, 2));
    };
    
    override void OnUpdate(float timeslice)
    {
        UpdateDummyScheduler();
        TickScheduler(timeslice);
        UpdateLogoutPlayers();    
        ref array<Man> players = new array<Man>;
        GetGame().GetPlayers( players );
            
        float safezone_center_x = 8150.0;
        float safezone_center_y =9100.0;
        float safezone_radius = 100.0;
          
        for ( int i = 0; i < players.Count(); i++ )
        {
            
            PlayerBase player;
            Class.CastTo(player, players.Get(i));
            vector pos = player.GetPosition();
            if(IsInRadialZone(pos[0], pos[2], safezone_center_x, safezone_center_y, safezone_radius)) {
                player.SetAllowDamage( false );
            } else { player.SetAllowDamage( true ); }
        }
    });
	 
};

compile error: mpmissions\dayzOffline.chernarusplus\init.c(81): Broken expression (missing `;`?)

Share this post


Link to post
Share on other sites

got the server to launch with the code but players still take damage set the safezone co-ordinates from the stat monitor and izurvive not sure what im doing wrong

Share this post


Link to post
Share on other sites
11 minutes ago, Sy8282 said:

got the server to launch with the code but players still take damage set the safezone co-ordinates from the stat monitor and izurvive not sure what im doing wrong

lay out your file will be dealt with.

Share this post


Link to post
Share on other sites

I'm gonna try this with the south-east island just for fun!

 

aaah doesn't work :(

Edited by kaspar rave

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

×