This site is a testing version, but all data is shared with the live forum.


Raised This Month: $ Target: $400
 0% 

/spec /ct won't work properly


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Nikol4u
Member
Join Date: Jan 2007
Location: Burgas
Old 04-01-2013 , 10:17   /spec /ct won't work properly
Reply With Quote #1

I use this code so people in my server would switch between being CT or spectators. For a reason, sometimes it buggs and the guy who is CT goes to SPEC (on player status (TAB) it shows he's SPEC), but he is alive and he can play (basically he stays CT, just his team is SPEC).

Can you tell me what do I do wrong?

cmdSpectate() is triggered on say /spec and say /ct

Code:
public cmdSpectate( plr )
{
	set_hudmessage( 0, 150, 250, -1.0, -0.1, 0, 6.0, 1.9, 0.0, 0.0, 1 );
	
	if( cs_get_user_team( plr ) != CS_TEAM_SPECTATOR )
	{
		
		g_bTimerStarted[plr] = false;
		show_hudmessage( plr, "You have become a spectator" );
		
		set_pev( plr, pev_solid, SOLID_NOT );
		set_pev( plr, pev_movetype, MOVETYPE_FLY );
		set_pev( plr, pev_effects, EF_NODRAW );
		set_pev( plr, pev_deadflag, DEAD_DEAD );
		set_pev( plr, pev_takedamage, DAMAGE_NO );
		cs_set_user_team( plr, CS_TEAM_SPECTATOR );
		entity_set_int( plr, EV_INT_deadflag, DEAD_DISCARDBODY );
		set_entity_flags( plr, FL_FROZEN, 0 );
	}
	else
	{
		cs_set_user_team( plr, CS_TEAM_CT, CS_CT_URBAN );
		set_pev( plr, pev_effects, 0 );
		set_pev( plr, pev_movetype, MOVETYPE_WALK );
		set_pev( plr, pev_deadflag, DEAD_NO );
		set_pev( plr, pev_takedamage, DAMAGE_AIM );
		cs_user_spawn( plr );
		
		g_bDuck[plr] = true;
		
		if( !user_has_weapon( plr, CSW_KNIFE ) )
		{
			fm_give_item( plr, "weapon_knife" );
		}
						
		if( !user_has_weapon( plr, CSW_USP ) )
		{
			fm_give_item( plr, "weapon_usp" );
			cs_set_user_bpammo( plr, CSW_USP, 36 );
		}
		
		show_hudmessage( plr, "You have become a counter-terrorist" );
	}
	
	return PLUGIN_HANDLED;
}
Nikol4u is offline
Send a message via ICQ to Nikol4u Send a message via Skype™ to Nikol4u
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 04-01-2013 , 10:47   Re: /spec /ct won't work properly
Reply With Quote #2

I think i have something really better but i can't find it, so try this for the moment :

PHP Code:
/*    Formatright © 2009, ConnorMcLeod

    Kz ChooseTeam is free software;
    you can redistribute it and/or modify it under the terms of the
    GNU General Public License as published by the Free Software Foundation.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Kz ChooseTeam; if not, write to the
    Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/

#include <amxmodx>
#include <fakemeta>

#define VERSION "0.3.0"

#define m_fGameHUDInitialized 349

#define SetIdBits(%1,%2)        %1 |= 1<<(%2 & 31)
#define ClearIdBits(%1,%2)    %1 &= ~( 1<<(%2 & 31) )
#define GetIdBits(%1,%2)        %1 &  1<<(%2 & 31)

new g_bDontHook

#define CS_TEAM_CT 2
#define CS_TEAM_SPECTATOR 4
#define fm_cs_get_user_team(%1)    get_pdata_int(%1, 114)

#define OFFSET_CAN_CHOOSETEAM 125
const CANT_CHOOSETEAM 1<<8
#define AllowPlayerChooseTeam(%1)    set_pdata_int(%1, OFFSET_CAN_CHOOSETEAM, get_pdata_int(%1, OFFSET_CAN_CHOOSETEAM) & ~CANT_CHOOSETEAM)

new gmsgTextMsg

public plugin_init()
{
    
register_plugin("Kz ChooseTeam"VERSION"ConnorMcLeod")

    
register_clcmd("say /spec""ClientCommand_Spec")
    
register_clcmd("say /ct""ClientCommand_CT")
    
register_clcmd("chooseteam""ClientCommand_ChooseTeam")

    
register_menucmd(register_menuid("#Team_Select_Spect"), 51"Menu_ChooseTeam")

    
gmsgTextMsg get_user_msgid("TextMsg")
}

public 
client_putinserver(id)
{
    
SetIdBits(g_bDontHookid)
}

public 
ClientCommand_ChooseTeam(id)
{
    
ClearIdBits(g_bDontHookid)
    
AllowPlayerChooseTeam(id)
    
show_menu(id51"#Team_Select_Spect", -1)

    return 
PLUGIN_HANDLED
}

public 
Menu_ChooseTeam(idiKey)
{
    if( 
GetIdBits(g_bDontHookid) )
    {
        
ClearIdBits(g_bDontHookid)
        return 
PLUGIN_CONTINUE
    
}

    switch(
iKey)
    {
        case 
1:
        {
            
ClientCommand_CT(id)
        }
        case 
5:
        {
            
ClientCommand_Spec(id)
        }
    }
    return 
PLUGIN_HANDLED
}

public 
ClientCommand_Spec(id)
{
    if( 
fm_cs_get_user_team(id) != CS_TEAM_SPECTATOR )
    {
        
SetIdBits(g_bDontHookid)
        new 
BLOCK_RESTORE get_msg_block(gmsgTextMsg)
        
set_msg_block(gmsgTextMsgBLOCK_ONCE)
        
dllfunc(DLLFunc_ClientPutInServerid)
        
set_msg_block(gmsgTextMsgBLOCK_RESTORE)
        
set_pdata_int(idm_fGameHUDInitialized1)
        
engclient_cmd(id"jointeam""6")
        
client_cmd(id"slot1")
        return 
PLUGIN_CONTINUE
    
}
    return 
PLUGIN_HANDLED
}

public 
ClientCommand_CT(id)
{
    if( 
fm_cs_get_user_team(id) != CS_TEAM_CT )
    {
        new 
iRestore get_pdata_int(id510)
        new 
bVGUI iRestore & (1<<0)
        if( 
bVGUI )
        {
            
set_pdata_int(id510iRestore & ~(1<<0))
        }
        
AllowPlayerChooseTeam(id)
        new 
BLOCK_RESTORE get_msg_block(gmsgTextMsg)
        
set_msg_block(gmsgTextMsgBLOCK_ONCE)
        
engclient_cmd(id"jointeam""2")
        
engclient_cmd(id"joinclass""1")
        
set_msg_block(gmsgTextMsgBLOCK_RESTORE)
        
client_cmd(id"slot1")
        if( 
bVGUI )
        {
            
set_pdata_int(id510iRestore)
        }
        return 
PLUGIN_CONTINUE
    
}
    return 
PLUGIN_HANDLED


EDIT : Try rather this :
PHP Code:
/*    Formatright © 2011, ConnorMcLeod

    This plugin is free software;
    you can redistribute it and/or modify it under the terms of the
    GNU General Public License as published by the Free Software Foundation.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this plugin; if not, write to the
    Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/

#include <amxmodx>
#include <fakemeta>

#define VERSION "0.0.1"
#define PLUGIN "Spec"

#define m_iDefaultItems         120
#define m_iJoinedState 121
#define m_iMenuId 205

const DEFAULTITEMS_GIVEN  =    (1<<0)
#define JOIN_ONTEAM             5

new gmsgShowMenugmsgVGUIMenu

public plugin_init()
{
    
register_plugin(PLUGINVERSION"ConnorMcLeod")

    
gmsgShowMenu get_user_msgid("ShowMenu")
    
gmsgVGUIMenu get_user_msgid("VGUIMenu")

    
register_clcmd("say /spec""ClCmd_Spec")
    
register_clcmd("say /ct""ClCmd_Ct")
}

public 
ClCmd_Specid )
{
    if( 
is_user_alive(id) )
    {
        
user_kill(id1// this is exactly what is done if you select spectator team during freezetime
    
}
    
engclient_cmd(id"jointeam""6")
}

public 
ClCmd_Ctid )
{
    
set_pev(idpev_deadflagDEAD_NO// allow return CT the same round
    
set_pdata_int(idm_iMenuId0// in case we are already in such a menu

    
new iBlockShowMenu get_msg_block(gmsgShowMenu)
    if( 
iBlockShowMenu != BLOCK_SET )
    {
        if( !
iBlockShowMenu )
        {
            
set_msg_block(gmsgShowMenuBLOCK_ONCE)
        }
    }
    new 
iBlockVGUIMenu get_msg_block(gmsgVGUIMenu)
    if( 
iBlockVGUIMenu != BLOCK_SET )
    {
        if( !
iBlockVGUIMenu )
        {
            
set_msg_block(gmsgVGUIMenuBLOCK_ONCE)
        }
    }

    
engclient_cmd(id"jointeam""2")

    if( !
iBlockShowMenu )
    {
        
set_msg_block(gmsgShowMenuBLOCK_NOT)
    }
    if( !
iBlockVGUIMenu )
    {
        
set_msg_block(gmsgVGUIMenuBLOCK_NOT)
    }

    
engclient_cmd(id"joinclass""2")

    
set_pdata_int(idm_iDefaultItemsget_pdata_int(idm_iDefaultItems) & ~DEFAULTITEMS_GIVEN)
    
set_pdata_int(idm_iJoinedStateJOIN_ONTEAM)
    
set_pev(idpev_deadflagDEAD_RESPAWNABLE)
    
dllfunc(DLLFunc_Thinkid)
}

// Observator modes
// enum
// {
    // OBS_NONE = 0,
    // OBS_CHASE_LOCKED,
    // OBS_CHASE_FREE, 
    // OBS_ROAMING, // free look
    // OBS_IN_EYE, // first person view
    // OBS_MAP_FREE, 
    // OBS_MAP_CHASE, 
// } 
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 04-01-2013 at 10:48.
ConnorMcLeod is offline
Nikol4u
Member
Join Date: Jan 2007
Location: Burgas
Old 04-01-2013 , 11:00   Re: /spec /ct won't work properly
Reply With Quote #3

Isn't there a way to do this without actually killing the guy?
Nikol4u is offline
Send a message via ICQ to Nikol4u Send a message via Skype™ to Nikol4u
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 04-01-2013 , 11:57   Re: /spec /ct won't work properly
Reply With Quote #4

Try setting deadflag, but you may need to strip his weapons first.
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 04-01-2013 at 11:57.
ConnorMcLeod is offline
Nikol4u
Member
Join Date: Jan 2007
Location: Burgas
Old 04-01-2013 , 12:03   Re: /spec /ct won't work properly
Reply With Quote #5

Quote:
Originally Posted by Nikol4u View Post
Code:
		set_pev( plr, pev_deadflag, DEAD_DEAD );
Isn't that the deadflag?

The thing is it happens randomly, sometimes it works perfectly, some times spectators move around and bug people as the semiclip won't work for them
Nikol4u is offline
Send a message via ICQ to Nikol4u Send a message via Skype™ to Nikol4u
Leon M.
Senior Member
Join Date: Apr 2009
Location: Germany
Old 04-01-2013 , 13:23   Re: /spec /ct won't work properly
Reply With Quote #6

It sounds lhat you using it for Kreedz. I'm right?
__________________
  • ZapTic - Paintball (Version 7.1.3 b1303)
  • Your #1 CS Paintball Server since 2008
  • 85.131.163.101:27015
Leon M. is offline
Nikol4u
Member
Join Date: Jan 2007
Location: Burgas
Old 04-01-2013 , 13:33   Re: /spec /ct won't work properly
Reply With Quote #7

Quote:
Originally Posted by Leon M. View Post
It sounds lhat you using it for Kreedz. I'm right?
Yeah I am running KZ server.

Every plugin I have seen which has /spec /ct uses the same function calls which are in my cmdSpectate() function as well, but for a reason it does not work properly.

I guess @ConnorMcLeod would work totally fine (I tested it on LAN it does work) but I prefer if the user doesn't get killed. If no other way, I will use his method though.
Nikol4u is offline
Send a message via ICQ to Nikol4u Send a message via Skype™ to Nikol4u
Leon M.
Senior Member
Join Date: Apr 2009
Location: Germany
Old 04-01-2013 , 14:05   Re: /spec /ct won't work properly
Reply With Quote #8

I'm using a private Kreedz plugin but I can help you anyways. Please consider it is working just fine for me but I removed some code from the function since it is interacting with other features of my mod. May there are similar features on your mod, I don't know.

Take it as an example.

Remarks I'm using this function as a toggle in my menu. To en- or diable it you just need to call the function cmd_spectator again.
PHP Code:
new bool:g_bSpectator[33]
new 
Float:g_f_vSpecAngles[33][3]
new 
Float:g_f_vSpecOrigin[33][3]

public 
cmd_spectator(id){

    if (
g_bSpectator[id]){
        
g_bSpectator[id] = false

        
// Mark player as ct
        
cs_set_user_team(idCS_TEAM_CT)
        
set_pev(idpev_deadflagDEAD_NO)
        
set_pev(idpev_movetypeMOVETYPE_WALK)
        
set_pev(idpev_solidSOLID_SLIDEBOX)
        
set_pev(idpev_takedamageDAMAGE_AIM)
        
set_pev(idpev_effectspev(idpev_effects) & ~EF_NODRAW)

        
// Respawn player
        
ExecuteHamB(Ham_CS_RoundRespawnid)

        
// Old position has been stored
        
if (!(g_f_vSpecOrigin[id][0] == 0.0 && g_f_vSpecOrigin[id][1] == 0.0 && g_f_vSpecOrigin[id][2] == 0.0)){

            
// Teleport player
            
set_pev(idpev_flagspev(idpev_flags) | FL_DUCKING)
            
set_pev(idpev_fuser20.0)
            
set_pev(idpev_velocity, {0.00.00.0})
            
engfunc(EngFunc_SetOriginidg_f_vSpecOrigin[id])
            
engfunc(EngFunc_SetSizeid, {-16.0, -16.0, -18.0}, {16.016.018.0})

            
// Set old angles
            
set_pev(idpev_anglesg_f_vSpecAngles[id])
            
set_pev(idpev_fixangle1)
        }
    }
    else{
        if (!
is_user_alive(id)){
            
client_print(idprint_chat"[AMXX] You must be alive to use this command.")
            return
        }
        if (!(
pev(idpev_flags) & FL_ONGROUND)){
            
client_print(idprint_chat"[AMXX] You can't join to the spectators. You must stand on a ground.")
            return
        }

        
g_bSpectator[id] = true
        g_f_vSpecOrigin
[id][0] = 0.0
        g_f_vSpecOrigin
[id][1] = 0.0
        g_f_vSpecOrigin
[id][2] = 0.0
        pev
(idpev_v_angleg_f_vSpecAngles[id])
        
pev(idpev_origing_f_vSpecOrigin[id])

        
// FL_FROZEN must be removed
        
set_pev(idpev_flagspev(idpev_flags) & ~FL_FROZEN)

        
// Mark player as spectator
        
cs_set_user_team(idCS_TEAM_SPECTATOR)
        
set_pev(idpev_deadflagDEAD_DEAD)
        
set_pev(idpev_movetypeMOVETYPE_FLY)
        
set_pev(idpev_solidSOLID_NOT)
        
set_pev(idpev_takedamageDAMAGE_NO)
        
set_pev(idpev_effectspev(idpev_effects) | EF_NODRAW)
    }

EDIT: Looks pretty equal, at least with team switch
__________________
  • ZapTic - Paintball (Version 7.1.3 b1303)
  • Your #1 CS Paintball Server since 2008
  • 85.131.163.101:27015

Last edited by Leon M.; 04-01-2013 at 14:13.
Leon M. is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 04-01-2013 , 14:21   Re: /spec /ct won't work properly
Reply With Quote #9

Try this (kill shouldn't be noticable) :

PHP Code:
/*    Formatright © 2011, ConnorMcLeod

    This plugin is free software;
    you can redistribute it and/or modify it under the terms of the
    GNU General Public License as published by the Free Software Foundation.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this plugin; if not, write to the
    Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/

#include <amxmodx>
#include <fakemeta>

#tryinclude <cstrike_pdatas>

#if !defined _cbaseentity_included
        #assert Cstrike Pdatas and Offsets library required! Read the below instructions:   \
                
1. Download it at forums.alliedmods.net/showpost.php?p=1712101#post1712101   \
                
2. Put it into amxmodx/scripting/include/ folder   \
                
3. Compile this plugin locallydetailswiki.amxmodx.org/index.php/Compiling_Plugins_%28AMX_Mod_X%29   \
                
4. Install compiled plugindetailswiki.amxmodx.org/index.php/Configuring_AMX_Mod_X#Installing
#endif

#define VERSION "0.0.1"
#define PLUGIN "Spec"

new gmsgShowMenugmsgVGUIMenu

public plugin_init()
{
    
register_plugin(PLUGINVERSION"ConnorMcLeod")

    
gmsgShowMenu get_user_msgid("ShowMenu")
    
gmsgVGUIMenu get_user_msgid("VGUIMenu")

    
register_clcmd("say /spec""ClCmd_Spec")
    
register_clcmd("say /ct""ClCmd_Ct")
}

public 
ClCmd_Specid )
{
    if( 
is_user_alive(id) )
    {
        
set_pdata_bool(idm_bBlastDamagedtrue)
        
user_kill(id1// this is exactly what is done if you select spectator team during freezetime
    
}
    
engclient_cmd(id"jointeam""6")
}

public 
ClCmd_Ctid )
{
    
set_pev(idpev_deadflagDEAD_NO// allow return CT the same round
    
set_pdata_int(idm_iMenu0// in case we are already in such a menu

    
new iBlockShowMenu get_msg_block(gmsgShowMenu)
    if( 
iBlockShowMenu != BLOCK_SET )
    {
        if( !
iBlockShowMenu )
        {
            
set_msg_block(gmsgShowMenuBLOCK_ONCE)
        }
    }
    new 
iBlockVGUIMenu get_msg_block(gmsgVGUIMenu)
    if( 
iBlockVGUIMenu != BLOCK_SET )
    {
        if( !
iBlockVGUIMenu )
        {
            
set_msg_block(gmsgVGUIMenuBLOCK_ONCE)
        }
    }

    
engclient_cmd(id"jointeam""2")

    if( !
iBlockShowMenu )
    {
        
set_msg_block(gmsgShowMenuBLOCK_NOT)
    }
    if( !
iBlockVGUIMenu )
    {
        
set_msg_block(gmsgVGUIMenuBLOCK_NOT)
    }

    
engclient_cmd(id"joinclass""2")

    
set_pdata_bool(idm_bHasReceivedDefItemsfalse)
    
set_pdata_int(idm_iJoinedState5)
    
set_pev(idpev_deadflagDEAD_RESPAWNABLE)
    
dllfunc(DLLFunc_Thinkid)

__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Nikol4u
Member
Join Date: Jan 2007
Location: Burgas
Old 04-02-2013 , 14:13   Re: /spec /ct won't work properly
Reply With Quote #10

I used Leon's code as it was easier for me to use it and implemented but it was still buggable.

This is a demo of the bug: http://www.sendspace.com/file/081rgd
This is the map (Nukk_miniegypt) http://www.sendspace.com/file/q16hfr

It is possible that to happen from something else? The only thing that has interaction in some why is the semiclip. I use skyjur's one from this post http://forums.alliedmods.net/showthr...358#post699358
Nikol4u is offline
Send a message via ICQ to Nikol4u Send a message via Skype™ to Nikol4u
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 20:34.


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