AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   Random Spawnpoints(using .nav-files) (https://forums.alliedmods.net/showthread.php?t=228063)

LeGone 10-13-2013 08:15

Random Spawnpoints(using .nav-files)
 
The first time Iīve heard about parsing the bot navigation (https://forums.alliedmods.net/showth...ght=navigation) I thought about spawning random NPCs on random .nav hiding spots. After successfully implemented pimpinjuiceīs code, itīs now possible to use the entcontrol-extension to find random hiding spots. This may also be used to find random player-spawn-points.
A few .nav-files (de_dust, de_dust2, cs_assault, cs_office, ...) are packed into the .vpk-file. Entcontrol will automatically extract these from the vpk-file into the /maps/-folder.

I donīt have the time to support more than the entcontrol plugin and extension, so here is the little buggy code. Someone should find a more flexible way to do this and implement it somewhere :D
The command "sm_teletoranpos" could be recoded to make a similar function like /stuck for zombie-servers.

Code:

/*
    ------------------------------------------------------------------------------------------
    EntControl::NativeSamples::RandomPlayerSpawnPlaces
    by Raffael 'LeGone' Holz
   
    This sample demonstrates the ability, to spawn players on random spawnplaces
    using the nav-mesh. There is no need to create extra-playerstarts this way.
    ------------------------------------------------------------------------------------------
*/

#include <sourcemod>
#include <sdktools>
#include <entcontrol>

new bool:navMeshLoaded = false;

public OnPluginStart()
{
    HookEvent("player_spawn", OnPlayerSpawn);
    RegAdminCmd("sm_teletoranpos", Command_TeleportToRandomPos, ADMFLAG_GENERIC);
}

public OnEventShutdown()
{
    UnhookEvent("player_spawn", OnPlayerSpawn);
}

/*
    ------------------------------------------------------------------------------------------
    OnMapStart
    Store all the positions once. Only if there is a valid navmesh.
    ------------------------------------------------------------------------------------------
*/
public OnMapStart()
{
    // Load the nav-mesh of the current map
    if (EC_Nav_Load())
    {
        // Cache positions
        if (EC_Nav_CachePositions())
        {
            // Positions stored
            navMeshLoaded = true;
        }
        else
        {
            PrintToServer("Unable to cache positions!");
        }
    }
    else
    {
        PrintToServer("No Navigation loaded! .nav could not be found.");
    }
}

public OnMapEnd()
{
    navMeshLoaded = false;
}

/*
    ------------------------------------------------------------------------------------------
    OnPlayerSpawn
    Teleport player to a "random" spawn position after has been spawned
    ------------------------------------------------------------------------------------------
*/
public Action:OnPlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
{
    new client = GetClientOfUserId(GetEventInt(event, "userid"));

    TeleToRandomPosition(client);
   
    return (Plugin_Continue);
}

public TeleToRandomPosition(client)
{
    new Float:position[3];
    if (navMeshLoaded && EC_Nav_GetNextHidingSpot(position))
    {
        position[2] += 10.0;
       
        TeleportEntity(client, position, NULL_VECTOR, Float:{10.0, 10.0, 10.0});
       
        new checksum = RoundToFloor(position[0] + position[1] + position[2]);
       
        new Handle:data;
        CreateDataTimer(0.1, CheckStuckTimer, data, TIMER_FLAG_NO_MAPCHANGE);
        WritePackCell(data, client);
        WritePackCell(data, checksum);
    }
}

public Action:CheckStuckTimer(Handle:Timer, Handle:data)
{
    new Float:position[3];
   
    ResetPack(data);
    new client = ReadPackCell(data);
    new checksum = ReadPackCell(data);

    GetEntPropVector(client, Prop_Send, "m_vecOrigin", position);
   
    new checksumNow = RoundToFloor(position[0] + position[1] + position[2]);
   
    checksumNow = checksum-checksumNow;
   
    if (checksumNow > -1 && checksumNow < 1)
        TeleToRandomPosition(client);
   
    return (Plugin_Stop);
}

/*
    ------------------------------------------------------------------------------------------
    COMMAND_TELEPORTTORANDOMPOS
    THis function will spawn a zombie on the players-aim-position
    ------------------------------------------------------------------------------------------
*/
public Action:Command_TeleportToRandomPos(client, args)
{
    TeleToRandomPosition(client);

    return (Plugin_Handled);
}

Here is the thread to the entcontrol-extension
The code above is running on my cs:s-testserver (legone.name, yes there is no need for :27015 :P)

friagram 10-13-2013 19:50

Re: Random Spawnpoints(using .nav-files)
 
Probably would be a good idea to run a tracehullfilter with mask solid to decide if the location is valid before spawning them.


All times are GMT -4. The time now is 18:29.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.