Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[Tutorial] The player disconnects and back to the nearest spawn

Custom Title Activated
Loyal Member
Joined
May 18, 2006
Messages
1,425
Reaction score
119
not work for DNC 2014

Code:
void ServerGameLogic::GetStartSpawnPosition(const wiCharDataFull& loadout, r3dPoint3D* pos, float* dir, DWORD peerId)
{
	// If not assigned a map, not assigned a new map, or this is a new character
	if(loadout.GameMapId == 0 || loadout.GameMapId != ginfo_.mapId || loadout.Alive == 3)
	{
		GetSpawnPositionNewPlayer(loadout.GamePos, pos, dir);
		pos->x += u_GetRandom(10, 120);
		pos->z += u_GetRandom(10, 120);
		return;
	}

	// Alive and logging back in game
	if(loadout.GameMapId && (loadout.GameMapId == ginfo_.mapId) && loadout.Alive == 1)
	{
		*pos = loadout.GamePos;
		*dir = loadout.GameDir;
		loadout.GamePos;
		return;
	}

	[COLOR="#FF0000"]// Early Revive Spawn at location of Death
	if(loadout.GameMapId && loadout.Alive == 2)
	{
		*pos = loadout.GamePos;
		*dir = loadout.GameDir;
		loadout.GamePos;
		return;[/COLOR]
	}

	r3d_assert(false && "GetStartSpawnPosition");
}
 
Experienced Elementalist
Joined
May 4, 2013
Messages
269
Reaction score
129
And how to make random spawn over a map and not the nearest or ette death spawn to avoid spawn kill ?

Thanks

Change:

Code:
[COLOR=#333333]// If not assigned a map, not assigned a new map, or this is a new character
[/COLOR]  if(loadout.GameMapId == 0 || loadout.GameMapId != ginfo_.mapId || loadout.Alive == 3)
    {
        GetSpawnPositionNewPlayer(loadout.GamePos, pos, dir);
        pos->x += u_GetRandom(10, 120);
        pos->z += u_GetRandom(10, 120);
        return; 
[COLOR=#333333]    }[/COLOR]

For:

Code:
[COLOR=#333333]// If not assigned a map, not assigned a new map, or this is a new character[/COLOR]    
if(loadout.GameMapId == 0 || loadout.GameMapId != ginfo_.mapId || loadout.Alive == 2 || loadout.Alive == 3)
    {
        GetSpawnPositionNewPlayer(loadout.GamePos, pos, dir);
        pos->x += u_GetRandom(10, 120);
        pos->z += u_GetRandom(10, 120);
        return; 
[COLOR=#333333]   }[/COLOR]
 
Experienced Elementalist
Joined
May 4, 2013
Messages
269
Reaction score
129
Use ths function:

Code:
// if no map assigned yet, or new map, or newly created character (alive == 3)    
if(loadout.GameMapId == 0 || loadout.GameMapId != ginfo_.mapId || loadout.Alive == 3 || loadout.GameServerId == 4)
        {
            GetSpawnPositionNewPlayer(loadout.GamePos, pos, dir);
            // move spawn pos at radius
            //pos->x += u_GetRandom(10, 120);
            //pos->z += u_GetRandom(10, 120);
            protect = 1;
            r3dOutToLog("new spawn at position %f %f %f\n", pos->x, pos->y, pos->z);
            return;
        }

Where GameServerId = PermGameX-1, for example (I guess):

PermGame2 = 1, PermGame3 = 2, and so on...
 
Elite Diviner
Joined
Apr 3, 2013
Messages
476
Reaction score
204
This Works for Every Source i mean i Tested it in all Sources that dont have Safe respawn

How To use it on a V3 Source That dont have Safe respawn

Look For

Code:
[COLOR=#008800][B]if[/B][/COLOR][COLOR=#000000](loadout.GameMapId && (loadout.GameMapId == ginfo_.mapId) && loadout.Alive == [/COLOR][COLOR=#0000DD][B]1[/B][/COLOR][COLOR=#000000])[/COLOR]    {
        needsSpawnProtection = [COLOR=#003388][B]false[/B][/COLOR];
        PxRaycastHit hit;
        PxSceneQueryFilterData [COLOR=#003377]filter[/COLOR]([COLOR=#CC0000][B]PxFilterData[/B][/COLOR](COLLIDABLE_STATIC_MASK,[COLOR=#0000DD][B]0[/B][/COLOR],[COLOR=#0000DD][B]0[/B][/COLOR],[COLOR=#0000DD][B]0[/B][/COLOR]), [COLOR=#CC0000][B]PxSceneQueryFilterFlags[/B][/COLOR](PxSceneQueryFilterFlag::eSTATIC|PxSceneQueryFilterFlag::eDYNAMIC));
        [COLOR=#008800][B]bool[/B][/COLOR] hitResult = g_pPhysicsWorld->[COLOR=#CC0000][B]raycastSingle[/B][/COLOR]([COLOR=#CC0000][B]PxVec3[/B][/COLOR](loadout[COLOR=#003377].GamePos[/COLOR][COLOR=#003377].x[/COLOR], loadout[COLOR=#003377].GamePos[/COLOR][COLOR=#003377].y[/COLOR] + [COLOR=#0000DD][B]0.5f[/B][/COLOR], loadout[COLOR=#003377].GamePos[/COLOR][COLOR=#003377].z[/COLOR]), [COLOR=#CC0000][B]PxVec3[/B][/COLOR]([COLOR=#0000DD][B]0[/B][/COLOR], -[COLOR=#0000DD][B]1[/B][/COLOR], [COLOR=#0000DD][B]0[/B][/COLOR]), [COLOR=#0000DD][B]500.0f[/B][/COLOR], [COLOR=#CC0000][B]PxSceneQueryFlags[/B][/COLOR](PxSceneQueryFlag::eIMPACT), hit, filter);
        r3dPoint3D posForWater = loadout[COLOR=#003377].GamePos[/COLOR];
        [COLOR=#008800][B]if[/B][/COLOR]( hitResult )
            posForWater = [COLOR=#CC0000][B]r3dPoint3D[/B][/COLOR](hit[COLOR=#003377].impact[/COLOR][COLOR=#003377].x[/COLOR], hit[COLOR=#003377].impact[/COLOR][COLOR=#003377].y[/COLOR], hit[COLOR=#003377].impact[/COLOR][COLOR=#003377].z[/COLOR]); [COLOR=#888888]// This is the ground position underwater.[/COLOR]

        [COLOR=#008800][B]float[/B][/COLOR] waterDepth = [COLOR=#CC0000][B]getWaterDepthAtPos[/B][/COLOR](posForWater);

        [COLOR=#888888]//r3dOutToLog("!!! WaterCheck Hit: %d, Depth: %.3f, Impact: %.3f, %.3f, %.3f\n", (int)hitResult, waterDepth, posForWater.x, posForWater.y, posForWater.z);[/COLOR]

        const [COLOR=#008800][B]float[/B][/COLOR] allowedDepth = [COLOR=#0000DD][B]1.5f[/B][/COLOR];
        [COLOR=#008800][B]if[/B][/COLOR](waterDepth > allowedDepth) [COLOR=#888888]// too deep, start swimming[/COLOR]
        {
            *pos = [COLOR=#CC0000][B]r3dPoint3D[/B][/COLOR](posForWater[COLOR=#003377].x[/COLOR], posForWater[COLOR=#003377].y[/COLOR] + (waterDepth - allowedDepth), posForWater[COLOR=#003377].z[/COLOR]); [COLOR=#888888]// adjust to water, in case player logged out while swimming[/COLOR]
        }
        [COLOR=#008800][B]else[/B][/COLOR]
        {
            *pos = [COLOR=#CC0000][B]AdjustPositionToFloor[/B][/COLOR](loadout[COLOR=#003377].GamePos[/COLOR]); [COLOR=#888888]// adjust to floor, in case if player logged out while being on top of other player or anything like that[/COLOR]
        }
        *dir = loadout[COLOR=#003377].GameDir[/COLOR];
        [COLOR=#888888]//r3dOutToLog("alive at position %.3f %.3f %.3f\n", pos->x, pos->y, pos->z);[/COLOR]
        [COLOR=#008800][B]return[/B][/COLOR]; [COLOR=#000000] }
[/COLOR]

Replace With or make it sure it looks like this

Code:
    [COLOR=#888888]/*if(loadout.GameMapId && (loadout.GameMapId == ginfo_.mapId) && loadout.Alive == 1)
    {
        needsSpawnProtection = false;
        PxRaycastHit hit;
        PxSceneQueryFilterData filter(PxFilterData(COLLIDABLE_STATIC_MASK,0,0,0), PxSceneQueryFilterFlags(PxSceneQueryFilterFlag::eSTATIC|PxSceneQueryFilterFlag::eDYNAMIC));
        bool hitResult = g_pPhysicsWorld->raycastSingle(PxVec3(loadout.GamePos.x, loadout.GamePos.y + 0.5f, loadout.GamePos.z), PxVec3(0, -1, 0), 500.0f, PxSceneQueryFlags(PxSceneQueryFlag::eIMPACT), hit, filter);
        r3dPoint3D posForWater = loadout.GamePos;
        if( hitResult )
            posForWater = r3dPoint3D(hit.impact.x, hit.impact.y, hit.impact.z); // This is the ground position underwater.

        float waterDepth = getWaterDepthAtPos(posForWater);

        //r3dOutToLog("!!! WaterCheck Hit: %d, Depth: %.3f, Impact: %.3f, %.3f, %.3f\n", (int)hitResult, waterDepth, posForWater.x, posForWater.y, posForWater.z);

        const float allowedDepth = 1.5f;
        if(waterDepth > allowedDepth) // too deep, start swimming
        {
            *pos = r3dPoint3D(posForWater.x, posForWater.y + (waterDepth - allowedDepth), posForWater.z); // adjust to water, in case player logged out while swimming
        }
        else
        {
            *pos = AdjustPositionToFloor(loadout.GamePos); // adjust to floor, in case if player logged out while being on top of other player or anything like that
        }
        *dir = loadout.GameDir;
        //r3dOutToLog("alive at position %.3f %.3f %.3f\n", pos->x, pos->y, pos->z);
        return;
    }*/[/COLOR]

and look For

Code:
    [COLOR=#008800][B]if[/B][/COLOR](loadout.GameMapId && loadout.Alive == [COLOR=#0000DD][B]2[/B][/COLOR])
    {
        needsSpawnProtection = [COLOR=#003388][B]true[/B][/COLOR];
        [COLOR=#CC0000][B]GetSpawnPositionAfterDeath2[/B][/COLOR](loadout[COLOR=#003377].GamePos[/COLOR], pos, dir);
        [COLOR=#888888]// move spawn pos at radius[/COLOR]
        pos->x += [COLOR=#CC0000][B]u_GetRandom[/B][/COLOR](-_glm_SpawnRadius, _glm_SpawnRadius);
        pos->z += [COLOR=#CC0000][B]u_GetRandom[/B][/COLOR](-_glm_SpawnRadius, _glm_SpawnRadius);
        [COLOR=#888888]//r3dOutToLog("revived at position %f %f %f\n", pos->x, pos->y, pos->z);[/COLOR]
        [COLOR=#008800][B]return[/B][/COLOR];
    }

Replace with or make it sure it looks like this

Code:
    [COLOR=#008800][B]if[/B][/COLOR](loadout.GameMapId && loadout.Alive == [COLOR=#0000DD][B]1[/B][/COLOR] || loadout.Alive == [COLOR=#0000DD][B]2[/B][/COLOR])
    {
        needsSpawnProtection = [COLOR=#003388][B]true[/B][/COLOR];
        [COLOR=#CC0000][B]GetSpawnPositionAfterDeath2[/B][/COLOR](loadout[COLOR=#003377].GamePos[/COLOR], pos, dir);
        [COLOR=#888888]// move spawn pos at radius[/COLOR]
        pos->x += [COLOR=#CC0000][B]u_GetRandom[/B][/COLOR](-_glm_SpawnRadius, _glm_SpawnRadius);
        pos->z += [COLOR=#CC0000][B]u_GetRandom[/B][/COLOR](-_glm_SpawnRadius, _glm_SpawnRadius);
        [COLOR=#888888]//r3dOutToLog("revived at position %f %f %f\n", pos->x, pos->y, pos->z);[/COLOR]
        [COLOR=#008800][B]return[/B][/COLOR];
    }

This Works to 100% on UntouchedV3 and WarZ:Hardcore V3 and some other V3 Sources if this Post helped u pls Leave a like : )

And Here is my Pastie so u guys can see it better Formated
 
Last edited:
Back
Top