Raised This Month: $ Target: $400
 0% 

Random Spawnpoints(using .nav-files)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
LeGone
Senior Member
Join Date: Dec 2006
Location: Germany
Old 10-13-2013 , 08:15   Random Spawnpoints(using .nav-files)
Reply With Quote #1

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
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 )
__________________
Want to control Entities? Spawn NPCs? Create Portals?
EntControl

Last edited by LeGone; 10-13-2013 at 13:03.
LeGone is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 10-13-2013 , 19:50   Re: Random Spawnpoints(using .nav-files)
Reply With Quote #2

Probably would be a good idea to run a tracehullfilter with mask solid to decide if the location is valid before spawning them.
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:32.


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