Raised This Month: $32 Target: $400
 8% 

Solved Player "not in-game" at Ham_Spawn (post) on lastest 1.9 but working on 1.8.2


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Th3822
Member
Join Date: Jan 2013
Location: Venezuela
Old 09-11-2019 , 23:20   Player "not in-game" at Ham_Spawn (post) on lastest 1.9 but working on 1.8.2
Reply With Quote #1

While testing this plugin:
PHP Code:
#include <amxmodx>
#include <engine>
#include <hamsandwich>

// random_mod(max): A small function to give a random number from 0 to max-1. Useful for get random values from arrays
#define random_mod(%1) (random_num(0, (100 * (%1)) - 1) % (%1))

new Array:g_aSpawnOrigins, Array:g_aSpawnAngles;
new 
g_iSpawnsCount;

public 
plugin_init()
{
    
register_plugin("[HL] Random Spawn Sort""1.0""Th3-822");

    
g_aSpawnOrigins ArrayCreate(3);
    
g_aSpawnAngles ArrayCreate(3);
}

public 
plugin_cfg()
{
    
loadSpawns();

    if (
g_iSpawnsCount 1)
    {
        
RegisterHam(Ham_Spawn"player""Ham_Player_Spawn_Post"1);
    }
}

loadSpawns()
{
    new 
iEnt get_maxplayers(), Float:fVector[3];
    while ((
iEnt find_ent_by_class(iEnt"info_player_deathmatch")))
    {
        
entity_get_vector(iEntEV_VEC_originfVector);
        
ArrayPushArray(g_aSpawnOriginsfVector);

        
entity_get_vector(iEntEV_VEC_anglesfVector);
        
ArrayPushArray(g_aSpawnAnglesfVector);

        
g_iSpawnsCount++;
    }
}

is_spawn_valid(idFloat:vOrigin[3])
{
    return (
trace_hull(vOrigin, (get_user_flags(id) & FL_DUCKING HULL_HEAD HULL_HUMAN), idDONT_IGNORE_MONSTERS) & 2) ? 1;
}

public 
Ham_Player_Spawn_Post(id)
{
    
//if (is_user_alive(id))
    //{
    
new iRandomSpawn random_mod(g_iSpawnsCount), Float:fVector[3];
    
entity_get_vector(idEV_VEC_originfVector);
    
server_print(" * Player %i spawned @ {%.2f, %.2f, %.2f} : is_user_alive = %i*"idfVector[0], fVector[1], fVector[2], is_user_alive(id));

    
ArrayGetArray(g_aSpawnOriginsiRandomSpawnfVector);
    if (
is_spawn_valid(idfVector))
    {
        
entity_set_origin(idfVector);

        
ArrayGetArray(g_aSpawnAnglesiRandomSpawnfVector);
        
entity_set_vector(idEV_VEC_anglesfVector);
        
entity_set_int(idEV_INT_fixangle1);

        return 
HAM_HANDLED;
    }
    
//}
    
return HAM_IGNORED;

Got the following error while running it on 1.9.0.5249 (Windows):
Code:
[ENGINE] Invalid player 1 (not in-game)
[AMXX] Displaying debug trace (plugin "hl_random_spawn_sort.amxx", version "1.0")
[AMXX] Run time error 10: native error (native "trace_hull")
[AMXX]    [0] hl_random_spawn_sort.sma::is_spawn_valid (line 46)
[AMXX]    [1] hl_random_spawn_sort.sma::Ham_Player_Spawn_Post (line 58)
but on 1.8.2 the same plugin works fine, this happens on the first spawn when i join to the server
here are pictures from the console (i was using rehlds when i got the error, so i did had to switch to vanilla hlds to test too)

(Win) HLDS (8196) & AMXX v1.9.0.5249:

(Win) HLDS (8196) & AMXX v1.8.2:


(Win) reHLDS (3.6.0.672-dev) & AMXX v1.9.0.5249:

(Win) reHLDS (3.6.0.672-dev) & AMXX v1.8.2:


the hlds build is a couple of months old (too lazy to update it), but the issue gets noticed on the images with the server version and meta dll too (also tested with other metamod with the same)

also, i wasn't expecting is_user_alive returning 0 in Ham_Spawn_Post, but, as the result is the same as 1.9.0, i will do a workaround for it

--- Edit 1 ---

Forgot to add that, on the 1.9.0 tests, i tested both plugins: Compiled with 1.9.0 and with 1.8.2 and the issue was present on both cases (just in case)

--- Edit 2 ---

Got to test on a linux server too (just with reHLDS 3.7.0.687-dev) and it was the same result

(Linux) reHLDS (3.7.0.687-dev) & AMXX v1.9.0.5249:

(Linux) reHLDS (3.7.0.6872-dev) & AMXX v1.8.2:


--- Edit 3 ---

Solved, the issue was on 1.8.2, more info: https://forums.alliedmods.net/showpo...87&postcount=5
If anybody wants to use the plugin, apply the workaround on the post and uncomment the "if" block

Last edited by Th3822; 09-12-2019 at 22:17. Reason: Solved
Th3822 is offline
E1_531G
Senior Member
Join Date: Dec 2017
Old 09-11-2019 , 23:33   Re: Player "not in-game" at Ham_Spawn (post) on lastest 1.9 but working on 1.8.2
Reply With Quote #2

You have to always check if user is alive in Ham_Spawn post, bcz Ham_Spawn is got called also when the player join in the server.
__________________
My English is A0
E1_531G is offline
Th3822
Member
Join Date: Jan 2013
Location: Venezuela
Old 09-11-2019 , 23:51   Re: Player "not in-game" at Ham_Spawn (post) on lastest 1.9 but working on 1.8.2
Reply With Quote #3

Quote:
Originally Posted by E1_531G View Post
You have to always check if user is alive in Ham_Spawn post, bcz Ham_Spawn is got called also when the player join in the server.
As you can see at the server output it just got called one time on entering, btw, the alive check works fine when respawning, but thats wasn't included on the screenshots
Th3822 is offline
Old 09-12-2019, 03:35
HamletEagle
This message has been deleted by HamletEagle.
bad_boy
Member
Join Date: Oct 2018
Old 09-12-2019 , 17:17   Re: Player "not in-game" at Ham_Spawn (post) on lastest 1.9 but working on 1.8.2
Reply With Quote #4

Quote:
Originally Posted by Th3822 View Post
As you can see at the server output it just got called one time on entering
That's why you are getting the error. E1_531G is correct.
PHP Code:
if( is_user_aliveid ) && is_spawn_valid(idfVector)) 
bad_boy is offline
Th3822
Member
Join Date: Jan 2013
Location: Venezuela
Old 09-12-2019 , 22:10   Re: Player "not in-game" at Ham_Spawn (post) on lastest 1.9 but working on 1.8.2
Reply With Quote #5

Quote:
Originally Posted by bad_boy View Post
That's why you are getting the error. E1_531G is correct.
PHP Code:
if( is_user_aliveid ) && is_spawn_valid(idfVector)) 
The player is indeed alive at that moment, but is_user_alive returns 0 because is_user_connected is also returning 0...
Anyways, i'll re-add the user alive check and the "solution" (it's more a workaround) that i got for that

---

I got my own answer after checking and rechecking things, and to notice it better i wrote a small plugin to get this output (on both versions):
PHP Code:
  client_connect(1) *
 * 
client_authorized(1) *
 * 
Ham_Player_Spawn_Pre(1) *
    * 
is_user_connecting(1): is_user_connected(1): *
    * 
pev_valid(1): is_user_alive(1): *
    * 
ExecuteHam(Ham_IsAlive1): entity_get_float(1EV_FL_health): 0.00 *
 * 
Ham_Player_Spawn_Post(1) *
    * 
is_user_connecting(1): is_user_connected(1): *
    * 
pev_valid(1): is_user_alive(1): *
    * 
ExecuteHam(Ham_IsAlive1): entity_get_float(1EV_FL_health): 100.00 *
 * 
client_putinserver(1) *
    * 
is_user_connecting(1): is_user_connected(1): *
    * 
pev_valid(1): is_user_alive(1): *
    * 
ExecuteHam(Ham_IsAlive1): entity_get_float(1EV_FL_health): 100.00 
AMXX doesn't consider the client fully connected until just before calling the client_putinserver forward... And... As is_user_alive also includes the is_user_connected check, it will return 0

I initially thought that it was an issue on 1.9, but on 1.8.2 lot's of engine functions didn't have safeguard checks for the entity, that's why it was working on 1.8.2.
So getting the error was the correct result, now i have to fix my plugin:

Re-adding the is_user_alive check that was commented on Ham_Player_Spawn_Post will make it work fine, but it won't be called "correctly" with the spawn when user joins, so as solution i will call the hook function on client_putinserver and that is all.

PHP Code:
public client_putinserver(id)
{
    
// Workaround for first spawn at join
    
Ham_Player_Spawn_Post(id);

Not all things works in the same way as cstrike plugins, i will mark the thread as solved.
Th3822 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 09-13-2019 , 21:28   Re: Player "not in-game" at Ham_Spawn (post) on lastest 1.9 but working on 1.8.2
Reply With Quote #6

Quote:
Originally Posted by Th3822 View Post
AMXX doesn't consider the client fully connected until just before calling the client_putinserver forward... And... As is_user_alive also includes the is_user_connected check, it will return 0

I initially thought that it was an issue on 1.9, but on 1.8.2 lot's of engine functions didn't have safeguard checks for the entity, that's why it was working on 1.8.2.
Realize that AMX Mod X doesn't do much, if any, of this logic. For example, Ham_Spawn is a function in the actual game and AMX Mod X simply allows you to hook it. If the original developers of the game decided to use that function in ways that you don't expect, it's just something that you have to deal with. E.g. it has always been a necessity (afaik) to have an alive check in a Ham_Spawn hook.

I'm not sure why you think you wouldn't need an alive check in any version of AMX Mod X. Also, I didn't really understand why you are calling your Ham_Spawn post function at client_putinserver(). Ham_Spawn will occur when you spawn.

Also, you can't be alive is you are not yet in the server.
__________________
fysiks is offline
AmXDusT
Member
Join Date: Feb 2019
Location: Italy / Albania
Old 09-14-2019 , 13:43   Re: Player "not in-game" at Ham_Spawn (post) on lastest 1.9 but working on 1.8.2
Reply With Quote #7

Just for curiosity
PHP Code:
// random_mod(max): A small function to give a random number from 0 to max-1. Useful for get random values from arrays
#define random_mod(%1) (random_num(0, (100 * (%1)) - 1) % (%1)) 
Is there any use of getting random that way instead of simply "random_num( 0, (%1) - 1 )"?

Last edited by AmXDusT; 09-14-2019 at 13:44.
AmXDusT is offline
Th3822
Member
Join Date: Jan 2013
Location: Venezuela
Old 09-14-2019 , 14:40   Re: Player "not in-game" at Ham_Spawn (post) on lastest 1.9 but working on 1.8.2
Reply With Quote #8

Quote:
Originally Posted by AmXDusT View Post
Just for curiosity
PHP Code:
// random_mod(max): A small function to give a random number from 0 to max-1. Useful for get random values from arrays
#define random_mod(%1) (random_num(0, (100 * (%1)) - 1) % (%1)) 
Is there any use of getting random that way instead of simply "random_num( 0, (%1) - 1 )"?
This one i can reply right away (i will answer the other one, when i get home from work):

I always disliked how random_num gives results that looks "not so random" when using small numbers, so i make a big random number and apply modulo on it to get a value from 0-(%1 - 1)

Of course, this is just personal opinion... But i have noticed the differences while using it and i'm happy with it.
Th3822 is offline
Th3822
Member
Join Date: Jan 2013
Location: Venezuela
Old 09-15-2019 , 19:14   Re: Player "not in-game" at Ham_Spawn (post) on lastest 1.9 but working on 1.8.2
Reply With Quote #9

Quote:
Originally Posted by fysiks View Post
Realize that AMX Mod X doesn't do much, if any, of this logic. For example, Ham_Spawn is a function in the actual game and AMX Mod X simply allows you to hook it. If the original developers of the game decided to use that function in ways that you don't expect, it's just something that you have to deal with. E.g. it has always been a necessity (afaik) to have an alive check in a Ham_Spawn hook.

I'm not sure why you think you wouldn't need an alive check in any version of AMX Mod X. Also, I didn't really understand why you are calling your Ham_Spawn post function at client_putinserver(). Ham_Spawn will occur when you spawn.

Also, you can't be alive is you are not yet in the server.
Players always spawns alive at PutInServer, but on cstrike gets switched to spec until teamselect, then CGameRules manages it's respawn. (That was a lot of links XD)

In HL there is no team/class select on connect, so you spawn directly at PutInServer as there is no need to defer the (alive) spawn...
But, on that first spawn (hooked with HAM), is_user_alive returns false because AMXX's PutInServer_Post hook (from meta) hasn't been called yet...
It's something a little bit like this issue.

So, i have 2 options for doing the stuff i need to do on that first spawn when is_user_alive (and _connected) are true and can run functions on the player:
  • Do the stuff on the player on the next hookable action ( that it's just client_putinserver(id) )
  • Detect the "first spawn" (!is_user_alive(id) && is_user_connecting(id)) at my hook and set a task for doing it "later"

The first one it's the best option, so that's why there is a call to the Spawn_Post hook at there.
Th3822 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 03:50.


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