AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Suggestions / Requests (https://forums.alliedmods.net/forumdisplay.php?f=12)
-   -   Spawn Generator (https://forums.alliedmods.net/showthread.php?t=174612)

Xalus 12-22-2011 19:29

Spawn Generator
 
I made this version for my Call Of Duty mw2 Mod,

I don't know if its a good way,
but if U think its usefull,
Have fun with it.

PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <hamsandwich>

#define PLUGIN "Spawn generator"
#define VERSION "1.0"
#define AUTHOR "Xalus"

#define MAX_SPAWNS 100

new SpawnscSpawns
new Float:originSpawn[MAX_SPAWNS][3]
new 
iMaxPlayers

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
// Cvar's
    
cSpawns    register_cvar("spawngenerator_spawns""2");
    
    
// Player Killed
    
RegisterHam(Ham_Spawn"player""Ham_PlayerSpawn"1);
    
RegisterHam(Ham_Killed"player""Ham_PlayerKilled");
    
    
// Others
    
iMaxPlayers get_maxplayers()
}
public 
Ham_PlayerSpawn(id) {
    if(
is_user_alive(id) && Spawns >= get_pcvar_num(cSpawns)) {
        
client_print(0print_chat"Finding a nice spot for you")
        
        new 
randomSpawn 
        
        GetNewRandomSpawn
:
        
        
randomSpawn random(Spawns)
        if(!
is_player_close(randomSpawn))
            
engfunc(EngFunc_SetOriginidoriginSpawn[randomSpawn])
        else 
            goto 
GetNewRandomSpawn
    
}
}
public 
Ham_PlayerKilled(idiAttacker) {
    if(
id != iAttacker
    
&& Spawns MAX_SPAWNS) {
        
pev(idpev_originoriginSpawn[Spawns])

        if( !
is_user_stuck(idoriginSpawn[Spawns])
        && 
engfunc(EngFunc_PointContentsoriginSpawn[Spawns]) == CONTENTS_EMPTY
        
&& !is_spawn_close(Spawns) ) {
            
Spawns++
                
            if(
Spawns == get_pcvar_num(cSpawns))
                
client_print(0print_center"Random spawns activated!")
        }
    }
}
stock is_user_stuck(const idFloat:Origin[3]) {
    static 
tr
    engfunc
(EngFunc_TraceHullOriginOriginIGNORE_MONSTERSpev(idpev_flags) & FL_DUCKING HULL_HEAD HULL_HUMANidtr)
    
    if( (!
get_tr2(trTR_StartSolid) && !get_tr2(trTR_AllSolid) && get_tr2(trTR_InOpen)) || (pev(id,pev_solid) & SOLID_NOT))
        return 
0

    
return 1
}
stock is_spawn_close(const spawnID) {
    for(new 
0Spawnsi++) 
        if(
get_distance_f(originSpawn[spawnID], originSpawn[i]) < 350.0)
            return 
1
    
return 0
}
stock is_player_close(const spawnID) {
    new 
Float:playerOrigin[3]
    for(new 
1<= iMaxPlayersi++) {
        if(!
is_user_alive(i))
            continue
        
        
pev(ipev_originplayerOrigin)
        
        if(
get_distance_f(originSpawn[spawnID], playerOrigin) < 10.0)
            return 
1
    
}
    return 
0
}



The system:

- When a player die, it will save his origins (If hes not stuck), and when the cvar (spawngenerator_spawns) is reached, it will spawn players on those origins.
- It will get enabled when the cvar is reached. Else its just to the spawn.

If U got some improvements, post them!

Btw this is made for Deathmatch mode, so everyone won't spawn at once.

xPaw 12-23-2011 05:51

Re: Spawn Generator
 
Why not check minimum distance between spawns? There could be 10 spawns literally on same place.

Xalus 12-23-2011 09:16

Re: Spawn Generator
 
Hmm, good idea.

I will add it, and a checker if a player is close, don't teleport him to there.

xPaw 12-23-2011 09:44

Re: Spawn Generator
 
You could also add "angles calculator", so players won't spawn aiming at the wall.

Xalus 12-23-2011 10:07

Re: Spawn Generator
 
With "angles calculator",
You mean save player that die's his angles,
& put it to the player that spawns,

or just put it *AMOUNT* ?

xPaw 12-23-2011 10:35

Re: Spawn Generator
 
Quote:

Originally Posted by Xalus (Post 1618316)
With "angles calculator",
You mean save player that die's his angles,
& put it to the player that spawns,

or just put it *AMOUNT* ?

Saving angles of dead player is a bad idea, he could die looking at the wall. Tracelines is what you are looking for, do a 360 loop around origin (+= 45), and make trace in that direction, if you hit wall too close, continue doing that.

Xalus 12-23-2011 13:25

Re: Spawn Generator
 
Update

Added a "spawn close" check,
and a check if a player is close, but not tested that one.

About angles, I will do some researche.

Xalus 12-24-2011 07:27

Re: Spawn Generator
 
For some reasons player spawn somtimes in the ground Oo

Levels 12-24-2011 14:54

Re: Spawn Generator
 
Nice! can be useful


All times are GMT -4. The time now is 20:50.

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