[RELEASE] Safezones

FallingSheep

OpenDayZ Lord!
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
Code:
#include "$CurrentDir:\\mpmissions\\dayzoffline.chernarusplus\\scripts\\safezonemission.c"
change
Code:
Mission CreateCustomMission(string path)
{
    return new CustomMission();
}
to
Code:
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
Code:
//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
Code:
//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);
      
    }  
}

im working on making it be able to support more than 1 zone (should be very easy to do )
 
Last edited:
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 :p

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());
        }
    }
}
 
Can anyone help with this error?
Code:
Can't compile mission init script'!

$CurrentDir://mpmissions//dayzoffline.chernarusplus//scripts//safezonemission.c(4): Opened scope at the end of file, missing '}' ?
 
Can anyone help with this error?
Code:
Can't compile mission init script'!

$CurrentDir://mpmissions//dayzoffline.chernarusplus//scripts//safezonemission.c(4): Opened scope at the end of file, missing '}' ?
remove the ; from the last line so it ends with the }
i think thats the issue
 
Good spotting! weird it compiles for some with it and not others! ive updated post with fix

Tried this but still getting


Can't compile mission init script'!

$CurrentDir://mpmissions//dayzoffline.chernarusplus//scripts//safezonemission.c(4): Opened scope at the end of file, missing '}' ?
 
I noticed you use distance that has a square root in it right? you could do the calculations without that couldn't you and just get the squared magnitude, wouldn't that improve performance right? IDK I'm new to this

from this:
distance1 = vector.Distance(player.GetPosition(),SAFEZONE_LOACTION1);


to something like this:
position = player.GetPosition();
x = position.x - SAFEZONE_LOACTION1.x;
z = position.z - SAFEZONE_LOACTION1.z;
squareDistance1 = (x * x + z * z);

if (squareDistance1 < radius) // player is in safe zone

because the default vector.Distance() method would have a square root in it which is resource intensive right?
 
Last edited:
Can't compile mission init script'!

$CurrentDir://mpmissions//dayzoffline.chernarusplus//scripts//safezonemission.c(4): Opened scope at the end of file, missing '}' ?

anyone can help this issue ?
 
remove the ; at the end of the script it was an oversight when the script was posted
guessing at the minute yours ends with }; instead of }
 
remove the ; at the end of the script it was an oversight when the script was posted
guessing at the minute yours ends with }; instead of }

That is not the issue mate, already replied to this suggestion and it still stops server from loading giving same message!
 
I noticed you use distance that has a square root in it right? you could do the calculations without that couldn't you and just get the squared magnitude, wouldn't that improve performance right? IDK I'm new to this

from this:
distance1 = vector.Distance(player.GetPosition(),SAFEZONE_LOACTION1);


to something like this:
position = player.GetPosition();
x = position.x - SAFEZONE_LOACTION1.x;
z = position.z - SAFEZONE_LOACTION1.z;
squareDistance1 = (x * x + z * z);

if (squareDistance1 < radius) // player is in safe zone

because the default vector.Distance() method would have a square root in it which is resource intensive right?
not my script, and now daOne is releaseing on steam workshop, you can try there for his updated versions, but it needs players to download a client mod

this appears to be broken now if i can ill update to work on current version but i highly recommend using daones steam version
 
Hello, I was able to fix the error scripts//safezonemission.c(4): Opened scope at the end of file, missing '}' ? ...but not work :(

MODS activated: TRADER (safe zones), BBP, others..
V:1.03

1-init.c
Code:
//Loadout pruebas
//null = [] execVM "scripts\loadout.sqf";

//Extra safe zones
#include "$CurrentDir:\\mpmissions\\dayz.chernarusplus\\scripts\\safezonemission.c"



//BBP Cement Mixers -Begin-
void SpawnObject( string type, vector position, vector orientation )
{
    auto obj = GetGame().CreateObject( type, position );
    obj.SetPosition( position );
    obj.SetOrientation( orientation );
    //Force collision update
    vector roll = obj.GetOrientation();
    roll [ 2 ] = roll [ 2 ] - 1;
    obj.SetOrientation( roll );
    roll [ 2 ] = roll [ 2 ] + 1;
    obj.SetOrientation( roll );
}
//BBP Cement Mixers -End-

void main()
{
    //BBP Cement Mixers -Begin-
    SpawnObject("BBP_Cement_Mixer", "10054.915039 5.998347 1824.814575", "140.320999 0.000000 0.000000");                //ELEKTRO
    SpawnObject("BBP_Cement_Mixer", "8025.974121 14.320039 3112.555664", "-134.317001 0.000000 -0.000001");                //CHERNO
    SpawnObject("BBP_Cement_Mixer", "2259.967285 185.386688 5228.343262", "31.421862 0.000000 0.000000");                //ZELNO
    SpawnObject("BBP_Cement_Mixer", "13320.810547 9.184664 6120.320313", "0.488000 0.002672 1.681928");                    //SOLNICHY
    SpawnObject("BBP_Cement_Mixer", "11916.333008 28.763134 14286.380859", "105.104500 0.000000 0.000000");                //NOVO
    SpawnObject("BBP_Cement_Mixer", "8005.100098 129.204407 12594.500000", "-12.629600 -0.734632 0.240260");            //UNKNOWN
    SpawnObject("BBP_Cement_Mixer", "5216.392578 340.970093 9886.897461", "-109.342987 -0.042234 0.007777");            //NWAF1
    SpawnObject("BBP_Cement_Mixer", "2943.952881 220.784470 12637.526367", "-158.010208 0.018145 -0.044932");            //UNKNOWN
    //BBP Cement Mixers -End-

    //INIT WEATHER BEFORE ECONOMY INIT------------------------
    Weather weather = g_Game.GetWeather();

    weather.MissionWeather(false);    // false = use weather controller from Weather.c

    weather.GetOvercast().Set( Math.RandomFloatInclusive(0.4, 0.6), 1, 0);
    weather.GetRain().Set( 0, 0, 1);
    weather.GetFog().Set( Math.RandomFloatInclusive(0.05, 0.1), 1, 0);

    //INIT ECONOMY--------------------------------------
    Hive ce = CreateHive();
    if ( ce )
        ce.InitOffline();

    //DATE RESET AFTER ECONOMY INIT-------------------------
    int year, month, day, hour, minute;
    int reset_month = 9, reset_day = 20;
    GetGame().GetWorld().GetDate(year, month, day, hour, minute);

    if ((month == reset_month) && (day < reset_day))
    {
        GetGame().GetWorld().SetDate(year, reset_month, reset_day, hour, minute);
    }
    else
    {
        if ((month == reset_month + 1) && (day > reset_day))
        {
            GetGame().GetWorld().SetDate(year, reset_month, reset_day, hour, minute);
        }
        else
        {
            if ((month < reset_month) || (month > reset_month + 1))
            {
                GetGame().GetWorld().SetDate(year, reset_month, reset_day, hour, minute);
            }
        }
    }
}

class CustomMission: MissionServer
{   
    void SetRandomHealth(EntityAI itemEnt)
    {
        if ( itemEnt )
        {
            int rndHlt = Math.RandomInt(55,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
//        playerEnt = GetGame().CreatePlayer(identity, characterName, GetEssFunctions(pos), 0, "NONE");// <-- ESS
        Class.CastTo(m_player, playerEnt);
        
        GetGame().SelectPlayer(identity, m_player);
        
        return m_player;
    }
    
    override void StartingEquipSetup(PlayerBase player, bool clothesChosen)
    {
        EntityAI itemTop;
        EntityAI itemEnt;
        ItemBase itemBs;
        float rand;
        
        itemTop = player.FindAttachmentBySlotName("Body");
        
        if ( itemTop )
        {
            itemEnt = itemTop.GetInventory().CreateInInventory("Rag");
            if ( Class.CastTo(itemBs, itemEnt ) )
                itemBs.SetQuantity(4);

            SetRandomHealth(itemEnt);
            
            itemEnt = itemTop.GetInventory().CreateInInventory("RoadFlare");
            itemEnt = itemTop.GetInventory().CreateInInventory("CombatKnife");
            
            SetRandomHealth(itemEnt);
            
            itemEnt = player.GetInventory().CreateInInventory("AssaultBag_Green");
            itemBs = ItemBase.Cast(itemEnt);
            
            rand = Math.RandomFloatInclusive(0.0, 1.0);
            if ( rand < 0.35 )
                itemEnt = player.GetInventory().CreateInInventory("Apple");
            else if ( rand > 0.65 )
                itemEnt = player.GetInventory().CreateInInventory("Pear");
            else
                itemEnt = player.GetInventory().CreateInInventory("Plum");
        
            SetRandomHealth(itemEnt);
        }
    }
};

// extra safezones
Mission CreateCustomMission(string path)
{
    return new safezonemission();
}
 
// Mission CreateCustomMission(string path)
//{
//    return new CustomMission();
//}

2-safezones.c

Code:
//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 == "true")
        {
            return;
        }
        else
        {
            g_Game.SetProfileString("SafeZoneStatus"+ GUID, "true");
            Msgparam = new Param1<string>( EXIT_MESSAGE );
            GetGame().RPCSingleParam(player, ERPCs.RPC_USER_ACTION_MESSAGE, Msgparam, true, player.GetIdentity());
        }
    }
}

3-safezonemission.c

Code:
//Credits: Da0ne
//https://github.com/Da0ne/DZMods/

#include "$CurrentDir:\\mpmissions\\dayz.chernarusplus\\Scripts\Safezones.c" // cambie de lugar

class safezonemission : MissionServer
{
    /////////////////////////////////////////
    // Called within class as extentions NOT class mainscope DO NOT DEFINE CLASS IN FILE!

    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++;
        }
    }
}

// extra safezones
//Mission CreateCustomMission(string path)
//{
//    return new safezonemission();
//}
 
Last edited:
Back
Top