Jump to content
Gizda

SafeZone Script

Recommended Posts

Hello friends. I am not good at writing scripts in this game, but there are some concepts in it. I ask for any help in the implementation of a separate zone on the server where the damage does not pass - the safe zone. In another forum thread, philippj proposed the idea of a script (I’ll post it below), but in this form the script does not work. Maybe someone has thoughts on the decision of this.Thank you in advance!

 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

Better so:

vector pos = player.GetPosition();    
 float distance = vector.Distance( safezone_center, pos );
 if (distance <= radius)

{...

and it is not working. Disabled in patch 0.63: 

player.SetAllowDamage( false );

 

Share this post


Link to post
Share on other sites

I haven't tried it but FallingSheep shared the following SafeZone script over at OpenDayZ.

https://opendayz.net/threads/safezones.22383/

Quote

Name: Safezones

Description: creates a safezone where players are invincible

Credits: Da0ne

Original Repository: https://github.com/Da0ne/DZMods/

Stripped out from the admin tools, this is the safezone only portion (ill break all the admin tools down in to single how to for ease)

edit init.c as per below

add this at very top


#include "$CurrentDir:\\mpmissions\\dayzoffline.chernarusplus\\scripts\\safezonemission.c"

change


Mission CreateCustomMission(string path)
	{
	    return new CustomMission();
	}

to


Mission CreateCustomMission(string path)
	{
	    return new safezonemission();
	}

create a new folder in mpmissions called Scripts

create a new file called safezones.c and paste the below into it and save inside the Scripts folder


//Credits: Da0ne
	//https://github.com/Da0ne/DZMods/
	vector SAFEZONE_LOACTION = "7500 0 7500"; //Map coords (position of the safe zone)
	float  SAFEZONE_RADIUS   = 500; //In meter
	string ENTRY_MESSAGE     = "Welcome to The SafeZone! Godmode ENABLED!";
	string EXIT_MESSAGE      = "You Have Left The SafeZone! Godmode DISABLED!";
	 
	//Runs every tick (Stat time tick!) IMPORANT: Does reduce about 120 FPS when server is High-Full Pop!
	void SafeZoneHandle(PlayerBase player)
	{
	    float distance;
	    string ZoneCheck, GUID;
	    GUID = player.GetIdentity().GetPlainId(); //Steam 64
	    Param1<string> Msgparam;
	 
	    distance = vector.Distance(player.GetPosition(),SAFEZONE_LOACTION);
	    if (distance <= SAFEZONE_RADIUS) //Player Inside Zone
	    {
	        g_Game.GetProfileString("SafeZoneStatus"+ GUID, ZoneCheck);
	        if (ZoneCheck == "true") //Already in zone
	        {
	            return;
	        }
	        else
	        {
	            g_Game.SetProfileString("SafeZoneStatus"+ GUID, "true");
	            Msgparam = new Param1<string>( ENTRY_MESSAGE );
	            GetGame().RPCSingleParam(player, ERPCs.RPC_USER_ACTION_MESSAGE, Msgparam, true, player.GetIdentity());
	        }
	    }
	    else if (distance > SAFEZONE_RADIUS) //Player Outside of Zone
	    {
	        g_Game.GetProfileString("SafeZoneStatus"+ GUID, ZoneCheck);
	        if (ZoneCheck == "false")
	        {
	            return;
	        }
	        else
	        {
	            g_Game.SetProfileString("SafeZoneStatus"+ GUID, "false");
	            Msgparam = new Param1<string>( EXIT_MESSAGE );
	            GetGame().RPCSingleParam(player, ERPCs.RPC_USER_ACTION_MESSAGE, Msgparam, true, player.GetIdentity());
	        }
	    }
	}

create another  new file called safezonemission.c and paste the below into it and save inside the Scripts folder


//Credits: Da0ne
	//https://github.com/Da0ne/DZMods/
	class safezonemission : MissionServer
	{
	/////////////////////////////////////////
	    // Called within class as extentions NOT class mainscope DO NOT DEFINE CLASS IN FILE!
	    #include "$CurrentDir:\\mpmissions\\dayzoffline.chernarusplus\\Scripts\Safezones.c"
	    bool m_SafeZone = true; // safezone on (true) or off (false)
	 
	    override void TickScheduler(float timeslice)
	    {
	        GetGame().GetWorld().GetPlayerList(m_Players);
	        if( m_Players.Count() == 0 ) return;
	        for(int i = 0; i < SCHEDULER_PLAYERS_PER_TICK; i++)
	        {
	            if(m_currentPlayer >= m_Players.Count() )
	            {
	                m_currentPlayer = 0;
	            }
	 
	            PlayerBase currentPlayer = PlayerBase.Cast(m_Players.Get(m_currentPlayer));
	            if (m_SafeZone) { SafeZoneHandle(currentPlayer); } //Check if player is near safezone
	            currentPlayer.OnTick();
	            m_currentPlayer++;
	        }
	    }
	/////////////////////////////////////////
	 
	    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)
	    {
	 
	        EntityAI itemEnt;
	        ItemBase itemBs;
	     
	        itemEnt = player.GetInventory().CreateInInventory("Rag");
	        itemBs = ItemBase.Cast(itemEnt);
	        itemBs.SetQuantity(4);
	        SetRandomHealth(itemEnt);
	 
	        itemEnt = player.GetInventory().CreateInInventory("RoadFlare");
	        itemBs = ItemBase.Cast(itemEnt);
	     
	    } 
	};

 

Edited by smasht

Share this post


Link to post
Share on other sites
Quote

so below is a test MULTI zone version (upto 10 but can easily add more) which i slapped together very roughly (may not work feel free to test fix etc 

follow the above instructions

replace safezones.c with the below code


Code:
//change for each safe zone
vector SAFEZONE_LOACTION1 = "7500 0 7500"; //Map coords (position of the safe zone)
vector SAFEZONE_LOACTION2 = "7500 0 7500"; //Map coords (position of the safe zone)
vector SAFEZONE_LOACTION3 = "7500 0 7500"; //Map coords (position of the safe zone)
vector SAFEZONE_LOACTION4 = "7500 0 7500"; //Map coords (position of the safe zone)
vector SAFEZONE_LOACTION5 = "7500 0 7500"; //Map coords (position of the safe zone)
vector SAFEZONE_LOACTION6 = "7500 0 7500"; //Map coords (position of the safe zone)
vector SAFEZONE_LOACTION7 = "7500 0 7500"; //Map coords (position of the safe zone)
vector SAFEZONE_LOACTION8 = "7500 0 7500"; //Map coords (position of the safe zone)
vector SAFEZONE_LOACTION9 = "7500 0 7500"; //Map coords (position of the safe zone)
vector SAFEZONE_LOACTION10 = "7500 0 7500"; //Map coords (position of the safe zone)

float  SAFEZONE_RADIUS   = 500; //In meter
string ENTRY_MESSAGE     = "Welcome to The SafeZone! Godmode ENABLED!";
string EXIT_MESSAGE      = "You Have Left The SafeZone! Godmode DISABLED!";

//Runs every tick (Stat time tick!) IMPORANT: Does reduce about 120 FPS when server is High-Full Pop!
void SafeZoneHandle(PlayerBase player)
{
    float distance;
    string ZoneCheck, GUID;
    GUID = player.GetIdentity().GetPlainId(); //Steam 64
    Param1<string> Msgparam;

    distance1 = vector.Distance(player.GetPosition(),SAFEZONE_LOACTION1);
    distance2 = vector.Distance(player.GetPosition(),SAFEZONE_LOACTION2);
    distance3 = vector.Distance(player.GetPosition(),SAFEZONE_LOACTION3);
    distance4 = vector.Distance(player.GetPosition(),SAFEZONE_LOACTION4);
    distance5 = vector.Distance(player.GetPosition(),SAFEZONE_LOACTION5);
    distance6 = vector.Distance(player.GetPosition(),SAFEZONE_LOACTION6);
    distance7 = vector.Distance(player.GetPosition(),SAFEZONE_LOACTION7);
    distance8 = vector.Distance(player.GetPosition(),SAFEZONE_LOACTION8);
    distance9 = vector.Distance(player.GetPosition(),SAFEZONE_LOACTION9);
    distance10 = vector.Distance(player.GetPosition(),SAFEZONE_LOACTION10);
    multizone(distance1);
    multizone(distance2);
    multizone(distance3);
    multizone(distance4);
    multizone(distance5);
    multizone(distance6);
    multizone(distance7);
    multizone(distance8);
    multizone(distance9);
    multizone(distance10);
}

void multizone(distance)
{
    if (distance <= SAFEZONE_RADIUS) //Player Inside Zone
    {
        g_Game.GetProfileString("SafeZoneStatus"+ GUID, ZoneCheck);
        if (ZoneCheck == "true") //Already in zone
        {
            return;
        }
        else
        {
            g_Game.SetProfileString("SafeZoneStatus"+ GUID, "true");
            Msgparam = new Param1<string>( ENTRY_MESSAGE );
            GetGame().RPCSingleParam(player, ERPCs.RPC_USER_ACTION_MESSAGE, Msgparam, true, player.GetIdentity());
        }
    }
    else if (distance > SAFEZONE_RADIUS) //Player Outside of Zone
    {
        g_Game.GetProfileString("SafeZoneStatus"+ GUID, ZoneCheck);
        if (ZoneCheck == "false")
        {
            return;
        }
        else
        {
            g_Game.SetProfileString("SafeZoneStatus"+ GUID, "false");
            Msgparam = new Param1<string>( EXIT_MESSAGE );
            GetGame().RPCSingleParam(player, ERPCs.RPC_USER_ACTION_MESSAGE, Msgparam, true, player.GetIdentity());
        }
    }
}

 

 

Edited by smasht

Share this post


Link to post
Share on other sites

Head shots will still kill you in the zone as this script just boosts your health by the amount of damage caused, you still bleed and your gear still gets ruined

 

Share this post


Link to post
Share on other sites

Does this multizone SafeZone script not work?

Looking for a working multizone Safezone script to run server side only.

Share this post


Link to post
Share on other sites

Having an issue with this part, tells me it expects ";" or ")" not "}" any ideas to get this multizone script working?


From here down I get the error I mentioned
                             |
void multizone(distance)     |
{  <-------------------------|                                
    if (distance <= SAFEZONE_RADIUS) //Player Inside Zone
    {
        g_Game.GetProfileString("SafeZoneStatus"+ GUID, ZoneCheck);
        if (ZoneCheck == "true") //Already in zone
        {
            return;
        }
        else
        {
            g_Game.SetProfileString("SafeZoneStatus"+ GUID, "true");
            Msgparam = new Param1<string>( ENTRY_MESSAGE );
            GetGame().RPCSingleParam(player, ERPCs.RPC_USER_ACTION_MESSAGE, Msgparam, true, player.GetIdentity());
        }
    }
    else if (distance > SAFEZONE_RADIUS) //Player Outside of Zone
    {
        g_Game.GetProfileString("SafeZoneStatus"+ GUID, ZoneCheck);
        if (ZoneCheck == "false")
        {
            return;
        }
        else
        {
            g_Game.SetProfileString("SafeZoneStatus"+ GUID, "false");
            Msgparam = new Param1<string>( EXIT_MESSAGE );
            GetGame().RPCSingleParam(player, ERPCs.RPC_USER_ACTION_MESSAGE, Msgparam, true, player.GetIdentity());
        }
    }
}

Safezones seem to work, however the notifications part doesnt.

Unless someone has a revised version to have multiple safezones using just one script?

 

Share this post


Link to post
Share on other sites

BUMP

Surely Somebody has a solution that is working? 🔰 Its not a good modding community if people dont share am I right? 😒😯 We arn't all frogs sitting in a pond being tight ass's 🐸 . 🤣😑

Edited by ICEMAN-FMCS

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

×