Raised This Month: $ Target: $400
 0% 

[Help] Player Team Spawns in HL


Post New Thread Reply   
 
Thread Tools Display Modes
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 02-16-2015 , 12:39   Re: [Help] Player Team Spawns in HL
Reply With Quote #11

Well, no delay, this is the good part. The bad part is that you must also use traces and to search a bit for a free space, because you can't teleport all the players on the same place, they will get stuck. With the hope that I don't confuse you more than helping, here is what I come with.

But before, get_brush_entity_origin is a stock from engine_stocks, so you should include engine or directly engine_stocks.inc
When you don't know from where a native comes search in include files, or if you are lazy go to: http://amxmodx.org/api/
Write the function into the search box and you can see the include file and the function description.
Code:
engine_stocks.inc Functions get_brush_entity_origin
Now, back to the topic.

PHP Code:
#include <amxmodx>
#include <engine>
#include <fakemeta>
#include <hamsandwich>

new const EntClassnames[][] =
{
    
"info_player_deathmatch",
    
"info_player_team1",
    
"info_player_team2"
}

new 
FloatEntityOrigin[2][3]

public 
plugin_init()
{
    
//Remove all info_player_deathmatch ents
    
new Target = -
    
while((Target find_ent_by_class(TargetEntClassnames[0])))
    {
        if(
pev_valid(Target))
        {
            
remove_entity(Target)
        }
    }
    
    
//Search for info_player_team1 and info_player_team2 ents
    
new Ents[2]
    for(new 
13i++)
    {
        
Ents[i-1] = find_ent_by_class(-1EntClassnames[i])
        
get_brush_entity_origin(Ents[i-1], EntityOrigin[i-1])
    }
    
    
//Hook spawn
    
RegisterHam(Ham_Spawn"player""CBasePlayer_Spawn"true)
}

public 
CBasePlayer_Spawn(id)
{
    
//Filter invalid spawns.
    
if(!is_user_alive(id))
    {
        return 
    }
    
    
//If player is T use the origin from info_player_team1
    //Else use the one from info_player_team2
    //Is clamp really needed here ??? Well, let's make sure we don't get -1 or 2 :)
    
new Float:SearchOrigin[3]
    
SearchOrigin EntityOrigin[clamp(get_user_team(id)-10,1)]
    
    
//Check if the origin that we have is empty
    
if(ValidSpotFound(idSearchOrigin))
    {
        
//Teleport the player
        
set_pev(idpev_originSearchOrigin)
    }
    else
    {
        
//If the sport is not free we need to do some searches
        //I've set the max searches to 300, you can increase it if it's found nothing and fail to teleport the player
        
new RestrictMaxSearches 300iFloat:FoundOrigin[3]
        while(--
RestrictMaxSearches 0)
        {
            
//Get some random origins around our one
            
for(03i++)
            {
                
FoundOrigin[i] = random_float(SearchOrigin[i] - 5SearchOrigin[i] + 5)
            }
            if(
ValidSpotFound(idFoundOrigin))
            {
                
//A valid spot has been found, set player origin and stop the loop
                
set_pev(idpev_originFoundOrigin)
                break
            }
        }
    }
}

bool:ValidSpotFound(idFloat:SearchOrigin[3])
{
    
//Send a TraceHull to check if the spot that we found is empty
    //Return true if found
    //False otherwise
    
new HandleGlobalTraceLine
    engfunc
(EngFunc_TraceHullSearchOriginSearchOriginIGNORE_MONSTERSpev(idpev_flags) & FL_DUCKING HULL_HEAD HULL_HUMANidHandleGlobalTraceLine)    
    if(
get_tr2(HandleGlobalTraceLineTR_InOpen) && !(get_tr2(HandleGlobalTraceLineTR_StartSolid) || get_tr2(HandleGlobalTraceLineTR_AllSolid))) 
    {
        return 
true
    
}
    return 
false        

I've took the trace system from my bomb status plugin, there it's working fine, hope that here too. Because I saw that you are trying to figure out by yourself and to understand this stuffs I left some comments into the code. Btw, it's nice that you try by yourself and only after that ask here
__________________

Last edited by HamletEagle; 02-16-2015 at 12:43.
HamletEagle is offline
Old 02-16-2015, 12:40
RateX
This message has been deleted by RateX.
kNowo
Senior Member
Join Date: Apr 2011
Location: Malaysia
Old 02-16-2015 , 12:56   Re: [Help] Player Team Spawns in HL
Reply With Quote #12

Came up with this real quick. Haven't been doing AMXX coding for over a year now.

PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>
#include <engine>

enum _:g_iTotalTeams
{
    
Team_1 0,
    
Team_2
}

new 
szSpawnPointClassNames[g_iTotalTeams][18] =
{
    
"info_player_team1",
    
"info_player_team2"
}

new Array:
g_aTeam1SpawnPoints
new Array:g_aTeam2SpawnPoints

public plugin_init()
{
    
register_plugin("Respawn Entity Changer""0.1""HL Fan")
    
RegisterHam(Ham_Spawn"player""OnPlayerSpawn"1)

    
g_aTeam1SpawnPoints ArrayCreate(332)
    
g_aTeam2SpawnPoints ArrayCreate(332)

    
CacheNewSpawnPoints()
}

public 
OnPlayerSpawn(iClient)
{
    new 
iPlayerTeam get_user_team(iClient)
    new 
Float:flPos[3]

    switch(
iPlayerTeam)
    {
        case 
Team_1ArrayGetArray(g_aTeam1SpawnPointsrandom_num(0ArraySize(g_aTeam1SpawnPoints)), flPos)
        case 
Team_2ArrayGetArray(g_aTeam2SpawnPointsrandom_num(0ArraySize(g_aTeam2SpawnPoints)), flPos)
    }

    
set_pev(iClientpev_originflPos)
//    server_print("pos is %.0f %.0f %.0f", flPos[0], flPos[1], flPos[2])
}

CacheNewSpawnPoints()
{
    new 
iEnt = -1Float:flPos[3]
    while((
iEnt find_ent_by_class(iEntszSpawnPointClassNames[Team_1])))
    {
        if(
pev_valid(iEnt))
        {
            
pev(iEntpev_originflPos)
            
ArrayPushArray(g_aTeam1SpawnPointsflPos)
//            server_print("Found a team1 spawn: %.0f %.0f %.0f", flPos[0], flPos[1], flPos[2])
        
}
    }

    
iEnt = -1
    
while((iEnt find_ent_by_class(iEntszSpawnPointClassNames[Team_2])))
    {
        if(
pev_valid(iEnt))
        {
            
pev(iEntpev_originflPos)
            
ArrayPushArray(g_aTeam2SpawnPointsflPos)
//            server_print("Found a team2 spawn: %.0f %.0f %.0f", flPos[0], flPos[1], flPos[2])
        
}
    }

Mine is missing "find empty space" function compared to HamletEagle's. If HamletEagle's version is working fine, use his.

Last edited by kNowo; 02-16-2015 at 12:58.
kNowo is offline
hlfan
Junior Member
Join Date: Dec 2014
Old 02-17-2015 , 09:50   Re: [Help] Player Team Spawns in HL
Reply With Quote #13

Hey all,

Thank you HamletEagle and kNowo for the work you have done on the code you posted. I have spent some time with it already and noticed a few things. I was able to successfully strip out the "info_player_deathmatch" entity but I then discovered something else. By default, if there is no "info_player_deathmatch" entity available it will default to another respawn entity called "info_player_start". This is HL's single player spawn entity, the other is the mulitplayer spawn entity. So I used the code provided and also removed the "info_player_start" entity. They both work now!

On to the interesting stuff. Now I tried to run the plugin and was not spawned at either of the two existing start entities. (on a side note: MOST multiplayer maps will have ONE "info_player_start" entity and SEVERAL "info_player_deathmatch" entities.) I was not spawned at either of those entities but rather was spawned at 0, 0, 0, co-ords on the map.

Here is another important point:
1) Problem: There are multiple "info_player_team1" and "info_player_team2" entities and one needs to be randomly selected for a respawn.
1) Solution: I will try to create an array with all of the spawn points, select one randomly with a random number based on the number of given spawns in the array, and use it for respawn.

I also discovered that it appears as if the plugin is unable to actually hook the spawn. I tried sending out a print for each time the spawn is hooked and I was unable to see anything showup in the server - which leads me to believe it is not being hooked. I am still trying to figure out why. (maybe it is a different hook for Half-Life?)

Overall, I am really happy with what you two have given me to work with and I will continue to look over it for the next few days and see if I can get it to work properly. However, I am still wondering in the back of my head, if it is simply possible to tell the game engine to point to a different entity to use for spawning. If this IS possible then all I need to do is check for the team at each spawn and tell the engine to spawn with the appropriate entity.


Again thank you guys so much for the help, it has been awesome!


P.S.: I thought briefly about another way if this cannot work. Althought this may be more time consuming on my end - Would it simply be easier to provide a list of spawn points and face angles into an array, and then on player spawn, check team, then use the set_pev function to send them to a randomly selected choice in that array? Before exploring this option I would like to try my best to get the other code working as it uses spawn entities already in the maps.

I will post my revised code a bit later after I have worked on it some more.


Thanks a TON,
HL Fan
hlfan is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 02-17-2015 , 13:19   Re: [Help] Player Team Spawns in HL
Reply With Quote #14

This infos were welcome at the beginning as I know nothing about HL.

PHP Code:
#include <amxmodx>
#include <engine>
#include <fakemeta>
#include <hamsandwich>

enum _:EntityProp
{
    
EntityIndex,
    
EntityType,
    
Float:BrushEntityOrigin[3]
}

new const 
EntsToRemove[][] =
{
    
"info_player_deathmatch",
    
"info_player_start"
}
new const 
EntClassnames[][] =
{
    
"info_player_team1",
    
"info_player_team2"
}

new Array:
ArrayEnts

public plugin_init()
{
    
ArrayEnts ArrayCreate(EntityProp)
    
    
//Remove ents
    
new Targeti
    
for(02i++)
    {
        
Target = -1
        
while((Target find_ent_by_class(TargetEntsToRemove[i])))
        {
            if(
pev_valid(Target))
            {
                
server_print("Removing %i ent[ %s ]"TargetEntsToRemove[i])
                
remove_entity(Target)
            }
        }
    }

    
//Search for info_player_team1 and info_player_team2 ents
    
new Data[EntityProp]
    
Target = -1
    
new FloatBrushOrigin[3]
    for(new 
02i++)
    {
        while((
Target find_ent_by_class(TargetEntClassnames[i])))
        {
            
//Found a valid entity
            
if(pev_valid(Target))
            {
                
//Save it's index, type(for t or ct) and origin
                //Push everything in the array
                
get_brush_entity_origin(TargetBrushOrigin)
                
                
Data[EntityIndex] = Target
                Data
[EntityType] = i
                Data
[BrushEntityOrigin] = _:BrushOrigin
                ArrayPushArray
(ArrayEntsData)
            }
        }
    }

    
//Hook spawn
    
RegisterHam(Ham_Spawn"player""CBasePlayer_Spawn"true)
}

public 
plugin_end()
{
    
//Destroy the array to free memory
    
ArrayDestroy(ArrayEnts)
}

public 
CBasePlayer_Spawn(id)
{
    
server_print("Spawn has been triggered")
    
    
//Filter invalid spawns.
    
if(!is_user_alive(id))
    {
        return 
    }
    
server_print("Player is succesfully spawned")
    
    new 
Team get_user_team(id)
    
    new 
EntsArraySize ArraySize(ArrayEnts), Data[EntityProp], i
    
new Array: TempArray ArrayCreate(EntityProp)
    
    for(
0EntsArraySizei++)
    {
        
ArrayGetArray(ArrayEntsiData)
        
Team Team 1
        
if(Data[EntityType] == Team)
        {
            
ArrayPushArray(TempArrayData)
        }
    }
    
    
ArrayGetArray(TempArrayrandom_num(0ArraySize(TempArray) - 1), Data)
    
ArrayDestroy(TempArray)//done with that array, destroy it

    
new Float:SearchOrigin[3
    
SearchOrigin Data[BrushEntityOrigin]
    
    
//Check if the origin that we have is empty
    
if(ValidSpotFound(idSearchOrigin))
    {
        
//Teleport the player
        
set_pev(idpev_originSearchOrigin)
    }
    else
    {
        
//If the sport is not free we need to do some searches
        //I've set the max searches to 300, you can increase it if it's found nothing and fail to teleport the player
        
new RestrictMaxSearches 600iFloat:FoundOrigin[3]
        while(--
RestrictMaxSearches 0)
        {
            
//Get some random origins around our one
            
for(03i++)
            {
                
FoundOrigin[i] = random_float(SearchOrigin[i] - 5SearchOrigin[i] + 5)
            }
            if(
ValidSpotFound(idFoundOrigin))
            {
                
//A valid spot has been found, set player origin and stop the loop
                
set_pev(idpev_originFoundOrigin)
                break
            }
        }
    }
}

bool:ValidSpotFound(idFloat:SearchOrigin[3])
{
    
//Send a TraceHull to check if the spot that we found is empty
    //Return true if found
    //False otherwise
    
new HandleGlobalTraceLine
    engfunc
(EngFunc_TraceHullSearchOriginSearchOriginIGNORE_MONSTERSpev(idpev_flags) & FL_DUCKING HULL_HEAD HULL_HUMANidHandleGlobalTraceLine)    
    if(
get_tr2(HandleGlobalTraceLineTR_InOpen) && !(get_tr2(HandleGlobalTraceLineTR_StartSolid) || get_tr2(HandleGlobalTraceLineTR_AllSolid))) 
    {
        return 
true
    
}
    return 
false        

Sure that this can be done better, but now I must hurry, so use this just a test code. It finds all info_player_team* ents and also remove the other ones, and when player spawn just pickup one depending on his team. Hope this will work fine :-??

You say that spawn is not triggered it's strange. As far as I found Hamsandwich should work for HL too, if your hamdata file is correct. Try to get the hamdata.ini from amxmodx 1.8.3 and replace the old one from 1.8.2

I've added some debug messages, please give me here the output if it doesn't work.
__________________
HamletEagle is offline
Old 02-18-2015, 05:19
Kuma77
This message has been deleted by Kuma77.
hlfan
Junior Member
Join Date: Dec 2014
Old 02-20-2015 , 08:22   Re: [Help] Player Team Spawns in HL
Reply With Quote #15

Hello everyone!


Wow - I am extremely impressed with the help you all have given out! Thank you so much HamletEagle, kNowo, and Kuma77.


HamletEagle: I have tried several times to get the plugin working you provided without any success. I do not think it is the plugin but a small issue with the HAM perhaps. I checked the server for the server_print's and I did not see anything, which leads me to believe the spawn is not actually getting hooked for whatever reason.

I downloaded the AMXX packages and I doubled checked the hamdata.ini and I believe it is up-to-date. Is it possible for me to see if there is a newer version for the 1.8.3 mod? Maybe that is the solution and it will work. I am really not sure!

The code itself appears as though it should work. So I am still hoping this can be figured out since you have put a lot of hard work into helping me. I will continue to search for solutions.


Kuma77: I got the code that you have provided and I have began testing it. So far I have reached a couple conclusions. There is some good news - the plugin does work - just not all the time.

I am able to set new spawns individually for each team using the command provided "addspawn". The menu appears and it allows me to save the co-ords into an .ini file to read from on restart. It will keep the spawn angles too. This does seem to be working. However, there is a problem.

Sometimes when a team is joined it will revert back to an original spawn "info_player_deathmatch" at a random time. This does not happen all the time. Only on occasion, but I have not been able to pin-point why it happens or when it happens to reproduce the bug. If this can be fixed I would say the plugin is working perfectly.

This was always another option I had thought about, the only downside is that I must create the spawns for every single map. Like I said earlier, it is fine, I would just like to see if it is also possible to get the map working naturally. If not, either way, it will function appropriately for what I am looking for!


A couple more side notes:
1) I combined a version of the all of the plugins provided and HamletEagle and kNowo's plugins were similar and were both unable to hook the spawn - it seems. However, I used the ability to strip the entities out with some of the code I had learned. When I strip out the entities "info_player_deathmatch" and "info_player_start" it will causes kuma77's spawner to stop working correctly. Everyone just begins to spawn at the center 0, 0, 0 co-ords. I tried this as I thought it may prevent the bug that was happening.

2) I will continue to think about this over again. I don't want to give up on the code provided from Hamlet or kNowo - I would like to get a version working! After all the help you have given it would be nice to finally get it going! Let me know what you guys think.


Again, I would just like to thank the community and anyone reading these posts for their time and efforts, it is greatly appreciated. Talk to everyone soon!

HL Fan
hlfan is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 02-20-2015 , 11:56   Re: [Help] Player Team Spawns in HL
Reply With Quote #16

Too bad that I can't test, maybe I did an unwanted mistake...
If you say that you get no debug message it means that the plugin is not even running, you should at least get the ones from ent removing part. See if it appears as running at amx_plugins command please and check if it throw some errors.
__________________

Last edited by HamletEagle; 02-20-2015 at 11:56.
HamletEagle is offline
kNowo
Senior Member
Join Date: Apr 2011
Location: Malaysia
Old 02-20-2015 , 21:38   Re: [Help] Player Team Spawns in HL
Reply With Quote #17

Dig up my old HLDM server files and found this hamdata.ini. See if this one works for you.
Attached Files
File Type: ini hamdata.ini (33.2 KB, 95 views)
kNowo is offline
abdobiskra
Veteran Member
Join Date: Jul 2014
Location: Algeria
Old 12-07-2017 , 05:41   Re: [Help] Player Team Spawns in HL
Reply With Quote #18

HamletEagle

Quote:
L 12/07/2017 - 108:01: Start of error session.
L 12/07/2017 - 108:01: Info (map "agctf_duff") (file "addons/amxmodx/logs/error_20171207.log")
L 12/07/2017 - 108:01: Invalid index 0 (count: 0)
L 12/07/2017 - 108:01: [AMXX] Displaying debug trace (plugin "team_spawn.amxx", version "unknown")
L 12/07/2017 - 108:01: [AMXX] Run time error 10: native error (native "ArrayGetArray")
L 12/07/2017 - 108:01: [AMXX] [0] team_spawn.sma::CBasePlayer_Spawn (line 104)
line 104 :
PHP Code:
ArrayGetArray(TempArrayrandom_num(0ArraySize(TempArray) - 1), Data
__________________

Last edited by abdobiskra; 12-07-2017 at 05:42.
abdobiskra is offline
Send a message via Skype™ to abdobiskra
abdobiskra
Veteran Member
Join Date: Jul 2014
Location: Algeria
Old 12-08-2017 , 02:59   Re: [Help] Player Team Spawns in HL
Reply With Quote #19

Quote:
Originally Posted by abdobiskra View Post
HamletEagle



line 104 :
PHP Code:
ArrayGetArray(TempArrayrandom_num(0ArraySize(TempArray) - 1), Data
Is there any idea guys ? I really need it
__________________
abdobiskra is offline
Send a message via Skype™ to abdobiskra
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 04:54.


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