[Tutorial] Proper spawn protection

Status
Not open for further replies.
Newbie Spellweaver
Joined
May 2, 2013
Messages
96
Reaction score
141
bXkJYY9 - [Tutorial] Proper spawn protection - RaGEZONE Forums

Here's how I made it.

- Golden Aura
- Shield icon
- Can't shoot while in spawn protection
- Zombies do not attack
- Blocks grenade damage

Code marked in red is what you should add or change.

In WarZ.sln

UserProfile.h
Code:
    enum    {
      GAMEFLAG_NearPostBox = (1 << 0),
[COLOR=#FF0000]      GAMEFLAG_SpawnProtection = (1 << 1),[/COLOR]
    };

AI_Player.CPP
Code:
    {
        if(r3dGetTime() < m_MorhineShotTime && m_AuraType == AT_NONE)
            m_AuraType = AT_MORHINE;
        if(m_AuraType == AT_MORHINE && r3dGetTime() > m_MorhineShotTime)
            m_AuraType = AT_NONE;

[COLOR=#FF0000]        if(m_AuraType == AT_SPAWNPROTECTION)
            if(!(CurLoadout.GameFlags & wiCharDataFull::GAMEFLAG_SpawnProtection))
                m_AuraType = AT_NONE;
        if(CurLoadout.GameFlags & wiCharDataFull::GAMEFLAG_SpawnProtection)
            m_AuraType = AT_SPAWNPROTECTION;[/COLOR]
    }

AI_Player.CPP
Code:
            {
                float bloodAlpha = 1.0f-R3D_MIN(r3dGetTime()-lastTimeHit, 1.0f);
                hudMain->setBloodAlpha(bloodAlpha);
            }

            bAllowToUseWeapons = true;
[COLOR=#FF0000]            if((CurLoadout.GameFlags & wiCharDataFull::GAMEFLAG_NearPostBox) || (CurLoadout.GameFlags & wiCharDataFull::GAMEFLAG_SpawnProtection))
                bAllowToUseWeapons = false;[/COLOR]
            hudMain->showSafeZoneWarning(!bAllowToUseWeapons);

            hudMain->setVisibility(lifeProperties.getPlayerVisibility());
            hudMain->setHearing(lifeProperties.getPlayerHearRadius());

AI_Player.CPP
Code:
bool canDamageTarget(const GameObject* obj)
{
[COLOR=#FF0000]    if(obj->isObjType(OBJTYPE_Human) && !(((obj_Player*)obj)->CurLoadout.GameFlags & wiCharDataFull::GAMEFLAG_SpawnProtection))[/COLOR]
        return true;


In WarZ_Server.sln

obj_ServerPlayer.cpp
Code:
    // can't fire in safe zones
[COLOR=#FF0000]    if((loadout_->GameFlags & wiCharDataFull::GAMEFLAG_NearPostBox) || (loadout_->GameFlags & wiCharDataFull::GAMEFLAG_SpawnProtection) || profile_.ProfileData.isGod)[/COLOR]
    {
        return false;
    }
(the profile_.ProfileData.isGod is from my god mode tutorial, if you do not have that, remove that part)

obj_ServerPlayer.cpp
Code:
void obj_ServerPlayer::UpdateGameWorldFlags()
{
    loadout_->GameFlags = 0;

[COLOR=#FF0000]    if((((r3dGetTime() - startPlayTime_) <= 30.0f))) // 30 second spawn protection
        loadout_->GameFlags |= wiCharDataFull::GAMEFLAG_SpawnProtection;[/COLOR]
Change 30.0f to how long spawn protection you want.

ServerGameLogic.cpp
Code:
// state is grabbed from the dynamics.  [0] is from player in the air, [1] is target player in the air
bool ServerGameLogic::ApplyDamageToPlayer(GameObject* fromObj, obj_ServerPlayer* targetPlr, const r3dPoint3D& dmgPos, float damage, int bodyBone, int bodyPart, bool force_damage, STORE_CATEGORIES damageSource, int airState )
{
    r3d_assert(fromObj);
    r3d_assert(targetPlr);

    if(targetPlr->loadout_->Alive == 0 || targetPlr->profile_.ProfileData.isGod)
        return false;

    if(fromObj->isObjType(OBJTYPE_Human) && ((obj_ServerPlayer*)fromObj)->profile_.ProfileData.isGod)
        return false;
        
[COLOR=#FF0000]    // can't damage players in safe zones (postbox now act like that)
    if(((targetPlr->loadout_->GameFlags & wiCharDataFull::GAMEFLAG_NearPostBox) || (targetPlr->loadout_->GameFlags & wiCharDataFull::GAMEFLAG_SpawnProtection)) && !force_damage)
        return false;[/COLOR]
Same here, the isGod parts are from my god mode tutorial.

ServerGameLogic.cpp
Inside IMPL_PACKET_FUNC(ServerGameLogic, PKT_C2S_Temp_Damage)
Code:
    GameObject* target = GameWorld().GetNetworkObject(n.targetId);
    if(!target)
    {
        //r3dOutToLog("PKT_C2S_Temp_Damage: targetPlr is NULL\n");
        return;
    }

[COLOR=#FF0000]    obj_ServerPlayer* targetPlr = IsServerPlayer(target);
    if(targetPlr && ((targetPlr->profile_.ProfileData.isDevAccount && targetPlr->profile_.ProfileData.isGod) || (targetPlr->loadout_ && (targetPlr->loadout_->GameFlags & wiCharDataFull::GAMEFLAG_SpawnProtection))))
    {
        return;
    }[/COLOR]

    const WeaponConfig* wc = g_pWeaponArmory->getWeaponConfig(101310);
That protects the player from grenade damage. You might want to add || (targetPlr->loadout_->GameFlags & wiCharDataFull::GAMEFLAG_NearPostBox) in there too.

ServerGameLogic.cpp
Code:
bool ServerGameLogic::CanDamageThisObject(const GameObject* targetObj)
{
[COLOR=#FF0000]    obj_ServerPlayer* plr = (obj_ServerPlayer*)IsServerPlayer(targetObj);
    if(plr && ((plr->profile_.ProfileData.isDevAccount && plr->profile_.ProfileData.isGod) || (plr->loadout_->GameFlags & wiCharDataFull::GAMEFLAG_SpawnProtection)))
    {
        return false;
    }[/COLOR]

If you want zombies to ignore spawn protected players:
sobj_Zombie.cpp
Code:
bool obj_Zombie::IsPlayerDetectable(const obj_ServerPlayer* plr, float dist)
{
[COLOR=#FF0000]    if(plr->loadout_->Alive == 0 || plr->profile_.ProfileData.isGod || (plr->loadout_->GameFlags & wiCharDataFull::GAMEFLAG_SpawnProtection))[/COLOR]
        return false;
 
Last edited:
If you want the aura effect like this;
bXkJYY9 - [Tutorial] Proper spawn protection - RaGEZONE Forums


I made a error in the tutorial, that is fixed now and will give you this visible aura. :)

To make it, here;
Code:
		if(m_AuraType == AT_SPAWNPROTECTION)
			if(!(CurLoadout.GameFlags & wiCharDataFull::GAMEFLAG_SpawnProtection))
				m_AuraType = AT_NONE;
		else if(CurLoadout.GameFlags & wiCharDataFull::GAMEFLAG_SpawnProtection)
			m_AuraType = AT_SPAWNPROTECTION;
Change that to
Code:
		if(m_AuraType == AT_SPAWNPROTECTION)
			if(!(CurLoadout.GameFlags & wiCharDataFull::GAMEFLAG_SpawnProtection))
				m_AuraType = AT_NONE;
		if(CurLoadout.GameFlags & wiCharDataFull::GAMEFLAG_SpawnProtection)
			m_AuraType = AT_SPAWNPROTECTION;
 
There was a bug that could crash your server.

ServerGameLogic.cpp
Code:
bool ServerGameLogic::CanDamageThisObject(const GameObject* targetObj)
{
    obj_ServerPlayer* plr = (obj_ServerPlayer*)IsServerPlayer(targetObj);
    if(plr && [COLOR=#FF0000]([/COLOR](plr->profile_.ProfileData.isDevAccount && plr->profile_.ProfileData.isGod) || (plr->loadout_->GameFlags & wiCharDataFull::GAMEFLAG_SpawnProtection)[COLOR=#FF0000])[/COLOR])
    {
        return false;
    }
I had forgot a couple ()

Here is the fixed code, I have updated OP.
 
For the Aura you need to play in High / Ultra Graphic Settings or turn your Camera arround.

And for the Tutorial - No comment...
 
Status
Not open for further replies.
Back