[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:

FallingSheep

OpenDayZ Lord!
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 '}' ?
 
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 ?
 

sy8282

New Member
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 }
 

FallingSheep

OpenDayZ Lord!
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
 
Top