Raised This Month: $51 Target: $400
 12% 

New Round / Player Spawn / Round Start / Round End - do Not mess it


Post New Thread Reply   
 
Thread Tools Display Modes
Doc-Holiday
AlliedModders Donor
Join Date: Jul 2007
Old 07-06-2008 , 17:28   Re: New Round / Player Spawn / Round Start / Round End - do Not mess it
Reply With Quote #81

I tried using your ham player spawn in a plugin made by pete b or w/e the M4A1 and AK47 mod i get an error saying unreachable code and loose indentation. i was wondering if ham works with engine and engine stocks as well but if you need ill send you the code so you can look at it.
Doc-Holiday is offline
Alka
AMX Mod X Plugin Approver
Join Date: Dec 2006
Location: malloc(null)
Old 07-06-2008 , 18:25   Re: New Round / Player Spawn / Round Start / Round End - do Not mess it
Reply With Quote #82

Of course it works, but you did somehting wrong...also you can use fakemeta instead of engine.
__________________
Still...lovin' . Connor noob! Hello
Alka is offline
Doc-Holiday
AlliedModders Donor
Join Date: Jul 2007
Old 07-06-2008 , 18:31   Re: New Round / Player Spawn / Round Start / Round End - do Not mess it
Reply With Quote #83

im not good with fakemeta stuff to different and i dont really code my self alka would u like to see the code maybe you can help me out?

http://forums.alliedmods.net/showthread.php?t=73816
Doc-Holiday is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 07-07-2008 , 00:27   Re: New Round / Player Spawn / Round Start / Round End - do Not mess it
Reply With Quote #84

If you don't want to use fakemeta, you can try this, should work (it seems to work but i haven't tested it enough).
PHP Code:
#include <amxmodx>

#define MAX_PLAYERS    32

new bool:g_bPlayerNonSpawnEvent[MAX_PLAYERS+1]
new 
bool:g_bJustTiggeredFullupdate[MAX_PLAYERS+1]
new 
g_iMaxPlayers

public plugin_init()
{
    
register_pluginPLUGINVERSIONAUTHOR )

    
register_event("ResetHUD""Event_ResetHUD""b")
    
register_event("TextMsg""Event_TextMsg_GameWillRestartIn""a""2=#Game_will_restart_in")

    
register_clcmd("fullupdate""ClientCommand_fullupdate")

    
g_iMaxPlayers get_maxplayers()
}

public 
Event_TextMsg_GameWillRestartIn()
{
    static 
id
    
for(id 1id <= g_iMaxPlayers; ++id)
        if( 
is_user_alive(id) )
            
g_bPlayerNonSpawnEvent[id] = true
}

public 
ClientCommand_fullupdate(id)
{
    
g_bPlayerNonSpawnEvent[id] = true
    g_bJustTiggeredFullupdate
[id] = true
}

public 
client_command(id)
{
    if(
g_bJustTiggeredFullupdate[id])
    {
        
g_bPlayerNonSpawnEvent[id] = false
        g_bJustTiggeredFullupdate
[id] = false
    
}
}

public 
Event_ResetHUD(id)
{
    if(!
is_user_alive(id))
        return

    if(
g_bPlayerNonSpawnEvent[id])
    {
        
g_bPlayerNonSpawnEvent[id] = false
        
return
    }

    
PlayerSpawn(id)
}

PlayerSpawn(id)
{
    
// do stuff here

__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
vittu
SuperHero Moderator
Join Date: Oct 2004
Location: L.A. County, CA
Old 07-09-2008 , 20:23   Re: New Round / Player Spawn / Round Start / Round End - do Not mess it
Reply With Quote #85

(Note: I only tested with podbots in cs and cz's bots in cz)

Well after some messing around I think I've come up with a method. Feel free to clean it up or whatever.

Basically the initial call of Ham_Spawn must be skipped. is_user_alive() is not a good enough check for this. Clients are fine, the problem is with bots.

The first Ham_Spawn call is when the client is put in the server or the bot is created, players are not actually alive at this point. Problems are as follows:
  1. Bots will pass an alive check when they are created for the first Ham_Spawn even though they are not.

  2. For CZ bots to use Ham_Spawn we must RegisterHamFromEntity after their private data initializes. Because of this, the first bot that is created and possibly spawned will not fire the initial and possibly first spawn calls of Ham_Spawn. However, subsequent newly created bots will need to again be blocked from the first Ham_Spawn call on them since the Ham would be registed before they are created.

Example problem:
Bot joins during a round and does not spawn into the game, the bot is dead. Ham_Spawn is called on that bot and it bypasses the is_user_alive() check running whatever code is supposed to be done on alive players that spawned.



Code:
#include <amxmodx> #include <cstrike> #include <fakemeta> #include <hamsandwich> new bool:g_bIsCzero new bool:g_bCZBotRegisterHam new g_iServerMaxPlayers new g_iBotQuota public plugin_init() {     // Must use post or else is_user_alive will return false on a dead player's next spawn     // Note: CZ bots will not hook here, must RegisterHamFromEntity for them     RegisterHam(Ham_Spawn, "player", "fwHamPlayerSpawnPost", 1)     g_iServerMaxPlayers = get_maxplayers()     // See if mod is CZ     new modName[6]     get_modname(modName, 5)     if ( equal(modName, "czero") ) g_bIsCzero = true     g_iBotQuota = get_cvar_pointer("bot_quota") } public fwHamPlayerSpawnPost(iPlayer) {     // Ham_Spawn will initially be called for both clients and bots when     // they are not alive. This first call will fire for clients when they     // are put into the server and for bots when they are created. Neither     // are spawned alive on a team. Therefore, the first Ham_Spawn call     // must be blocked.     // is_user_alive will be sufficent to block first Ham_Spawn for     // clients. However, bots will pass this check even though dead on     // first Ham_Spawn. Also, if checking cs_get_user_team clients must be     // alive or else the native will error.     if ( !is_user_alive(iPlayer) ) return HAM_IGNORED     // A team check will return 0 or unassigned for the first Ham_Spawn     // for both clients and players. - thx to MeRcyLeZZ for this fix     // Note: For you weirdos who don't want to use the cstikre module     // get_user_team() seems to work just as well.     if ( cs_get_user_team(iPlayer) == CS_TEAM_UNASSIGNED ) return HAM_IGNORED     // player has spawned and is alive in game     return HAM_IGNORED } public client_putinserver(iPlayer) {     if ( iPlayer < 1 || iPlayer > g_iServerMaxPlayers ) return     // Only want to run this if: mod is CZ (zbot not supported), client is a bot,     // these are CZ bots (bot_quota), and the ham has not been registed yet.     if ( g_bIsCzero && (pev(iPlayer, pev_flags) & FL_FAKECLIENT) && get_pcvar_num(g_iBotQuota) > 0 && !g_bCZBotRegisterHam ) {         // Delay for private data to initialize         set_task(0.1, "czbotHookHam", iPlayer)     } } public czbotHookHam(iPlayer) {     // Thx to Avalanche and GunGame of which this method is based off of     if ( g_bCZBotRegisterHam || !is_user_connected(iPlayer) ) return     // Recheck for safety.     if ( (pev(iPlayer, pev_flags) & FL_FAKECLIENT) && get_pcvar_num(g_iBotQuota) > 0 ) {         // Post spawn fix for cz bots, since RegisterHam does not work for them         RegisterHamFromEntity(Ham_Spawn, iPlayer, "fwHamPlayerSpawnPost", 1)         // Only needs to run once after ham is registed ignore.         g_bCZBotRegisterHam = true         // Incase this bot has spawned alive into a game that already has         // started we must manually call a Ham_Spawn because the ham will         // not register early enough. - thx to MeRcyLeZZ for this fix         if ( is_user_alive(iPlayer) ) fwHamPlayerSpawnPost(iPlayer)     } }

Also, just to make a note: CZ bots do have a classname of "player"...

Last edited by vittu; 08-30-2008 at 01:36. Reason: Updated example and comments due to MeRcyLeZZ finds
vittu is offline
Send a message via AIM to vittu Send a message via MSN to vittu Send a message via Yahoo to vittu
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 08-04-2008 , 12:48   Re: New Round / Player Spawn / Round Start / Round End - do Not mess it
Reply With Quote #86

vittu: I discovered that if you try to hook it in client_putinserver, you do get errors that the private data isn't right. But you don't have to wait a whole second, 0.1 seconds works fine. This solved some problems for me when using Ham_Spawn and having lots of CZ bots join the game at once (ie: just setting bot_quota from 0 to 10 or something).
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS
XxAvalanchexX is offline
MeRcyLeZZ
Veteran Member
Join Date: Dec 2007
Old 08-28-2008 , 19:40   Re: New Round / Player Spawn / Round Start / Round End - do Not mess it
Reply With Quote #87

@vittu: Sorry about my last reply, definitely didn't get your post right...

I agree that "the initial call of Ham_Spawn must be skipped" and your code proves flawless in doing that, but I kept wondering about this:
Quote:
Originally Posted by vittu
1. Bots will be considered both alive and on team when they are created for the first Ham_Spawn even though they are neither.
The alive part I could reproduce, but when I retrieved a bot's team by using cs_get_user_team() the output was 0 (CS_TEAM_UNASSIGNED) both for PODBots and CZ bots; whereas for the actual spawn event I would get 1 or 2 (CS_TEAM_T or CS_TEAM_CT).
If I'm right about this, the whole workaround could be avoided by adding an additional check in the spawn forward: (maybe is_user_alive() could be also skipped, just left there for safety though)
Code:
public fwHamPlayerSpawnPost(iPlayer) {     // Alive (players only) AND on team (bots/players)     if ( is_user_alive(iPlayer) && cs_get_user_team(iPlayer) )     {         // Player spawned     }         return HAM_IGNORED; }
Of course this is only a suggestion to make the script simpler, as I said previously it works fine anyway...


Moving on to a more significant issue. Regarding CZ bots, you may have already noticed that when the first bot is created and spawns immediately, the Ham forwards won't yet be initialized to catch this spawn (because of the much needed delay we set on the task).
Now, most of the times this won't be a problem since bots are usually added at the beginning of a map and CS triggers a round restart shortly after. But what if the first bot spawns mid-game? Right. No spawn event. No code executed for this bot. And thus he walks freely around the map for a whole round without being affected by whatever your spawn code was supposed to do.

I've come up with a really small fix to prevent that, here's what you need to add to the previous code:
Code:
public czbotHookHam(iPlayer) {     // Thx to Avalanche and GunGame of which this method is based off of     if ( g_bCZBotRegisterHam || !is_user_connected(iPlayer) ) return         // Recheck for safety.     if ( (pev(iPlayer, pev_flags) & FL_FAKECLIENT) && get_pcvar_num(g_iBotQuota) > 0 )     {         // Post spawn fix for cz bots, since RegisterHam does not work for them         RegisterHamFromEntity(Ham_Spawn, iPlayer, "fwHamPlayerSpawnPost", 1)                 // Only needs to run once after ham is registed ignore.         g_bCZBotRegisterHam = true        
        // If the bot has already spawned, call the forward manually for him
        if ( is_user_alive(iPlayer) ) fwHamPlayerSpawnPost(iPlayer)
    } }
And since bots seem to delay their creation 0.3 seconds between each other, you don't have to worry about this happening for anyone else than the firstly created bot.

Suggestions and comments are nice to hear...
__________________
MeRcyLeZZ is offline
vittu
SuperHero Moderator
Join Date: Oct 2004
Location: L.A. County, CA
Old 08-28-2008 , 22:51   Re: New Round / Player Spawn / Round Start / Round End - do Not mess it
Reply With Quote #88

Quote:
Originally Posted by MeRcyLeZZ View Post
The alive part I could reproduce, but when I retrieved a bot's team by using cs_get_user_team() the output was 0 (CS_TEAM_UNASSIGNED) both for PODBots and CZ bots; whereas for the actual spawn event I would get 1 or 2 (CS_TEAM_T or CS_TEAM_CT).
Tested and verifyed... Ok wow I don't know how I got that wrong, I swear they passed a team check. Just wish I still had the code I tested with to recheck.

Quote:
Originally Posted by MeRcyLeZZ View Post
But what if the first bot spawns mid-game? Right. No spawn event. No code executed for this bot. And thus he walks freely around the map for a whole round without being affected by whatever your spawn code was supposed to do.
Was unaware of this one because I didnt have a live player to test with to start the round before any bots joined.



Thank you for checking on this, and I'm sorry about being wrong. Will update example asap.

Last edited by vittu; 08-29-2008 at 01:57.
vittu is offline
Send a message via AIM to vittu Send a message via MSN to vittu Send a message via Yahoo to vittu
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 08-30-2008 , 17:16   Re: New Round / Player Spawn / Round Start / Round End - do Not mess it
Reply With Quote #89

Thanks MeRcyLeZZ.
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS
XxAvalanchexX is offline
pacheco
Senior Member
Join Date: Jul 2011
Old 12-15-2011 , 15:16   Re: New Round / Player Spawn / Round Start / Round End - do Not mess it
Reply With Quote #90

Nice Tutorial!!
__________________



pacheco 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 03:06.


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