Raised This Month: $ Target: $400
 0% 

Spawn Generator


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Xalus
Veteran Member
Join Date: Dec 2009
Location: Belgium
Old 12-22-2011 , 19:29   Spawn Generator
Reply With Quote #1

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.
__________________
Retired.

Last edited by Xalus; 12-23-2011 at 13:18.
Xalus is offline
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 12-23-2011 , 05:51   Re: Spawn Generator
Reply With Quote #2

Why not check minimum distance between spawns? There could be 10 spawns literally on same place.
__________________
xPaw is offline
Xalus
Veteran Member
Join Date: Dec 2009
Location: Belgium
Old 12-23-2011 , 09:16   Re: Spawn Generator
Reply With Quote #3

Hmm, good idea.

I will add it, and a checker if a player is close, don't teleport him to there.
__________________
Retired.
Xalus is offline
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 12-23-2011 , 09:44   Re: Spawn Generator
Reply With Quote #4

You could also add "angles calculator", so players won't spawn aiming at the wall.
__________________
xPaw is offline
Xalus
Veteran Member
Join Date: Dec 2009
Location: Belgium
Old 12-23-2011 , 10:07   Re: Spawn Generator
Reply With Quote #5

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

or just put it *AMOUNT* ?
__________________
Retired.
Xalus is offline
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 12-23-2011 , 10:35   Re: Spawn Generator
Reply With Quote #6

Quote:
Originally Posted by Xalus View Post
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.
__________________
xPaw is offline
Xalus
Veteran Member
Join Date: Dec 2009
Location: Belgium
Old 12-23-2011 , 13:25   Re: Spawn Generator
Reply With Quote #7

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.
__________________
Retired.
Xalus is offline
Xalus
Veteran Member
Join Date: Dec 2009
Location: Belgium
Old 12-24-2011 , 07:27   Re: Spawn Generator
Reply With Quote #8

For some reasons player spawn somtimes in the ground Oo
__________________
Retired.
Xalus is offline
Levels
Member
Join Date: Dec 2011
Old 12-24-2011 , 14:54   Re: Spawn Generator
Reply With Quote #9

Nice! can be useful
Levels is offline
Reply


Thread Tools
Display Modes

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 20:50.


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