AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Spawn on connect (https://forums.alliedmods.net/showthread.php?t=162650)

BeeT 07-21-2011 10:28

Spawn on connect
 
Hello all, i would like to make a simple plugin.
Respawn player on connect, when player connected and selected team, he should be respawned. How to make it?

I have simple script, but it doesn't work all time, sometimes it's works sometimes no. And idk why...

Code:

/* Plugin generated by AMXX-Studio */
 
#include <amxmodx>
#include <hamsandwich>
 
#define PLUGIN "Spawn on connect"
#define VERSION "1.0"
#define AUTHOR "aaarnas"
 
new client_validate[33]
 
public plugin_init()
    register_plugin(PLUGIN, VERSION, AUTHOR)
 
public client_connect(id)
    client_validate[id] = 0
 
public client_command(id) {
 
    new cmd[20]
    read_argv(0, cmd, charsmax(cmd))
 
    if(equal(cmd, "jointeam")) client_validate[id]++
    else if(equal(cmd, "joinclass")) client_validate[id]++
 
    if(client_validate[id] == 2) set_task(0.3, "spawn_player", id)
}
 
public spawn_player(id) if(!is_user_alive(id)) ExecuteHamB(Ham_CS_RoundRespawn, id)


jim_yang 07-21-2011 11:08

Re: Spawn on connect
 
someone cared this question or researched this before? Let's discuess an efficient hacking method. I think there's something related to the time. cause sometime game will respawn a connected player, sometime not(when the round has started for a while). I once tried to find some info about this, but end with fail.
the procedure from a player connected to physicically spawn is a mess. I can't even find a good place to hook. Anyone interested ? Let's talk about it here

BeeT 07-21-2011 17:18

Re: Spawn on connect
 
Maybe someone can copy code from CSDM mod?
Because there on connect you are always respawn.

Sylwester 07-21-2011 19:35

Re: Spawn on connect
 
try this:
PHP Code:

#include <amxmodx>
#include <hamsandwich>

#define TID_HIDE_MENU 5323568

new bool:g_autojoin_team[33]
new 
bool:g_autojoin_class[33]
new 
g_vgui_menus[33][5]

public 
plugin_init(){
    
register_plugin("autojoin""1.0""Sylwester")
    
register_message(get_user_msgid("ShowMenu"), "message_show_menu")
}


public 
client_connect(id){
    
get_user_info(id"_vgui_menus"g_vgui_menus[id], 4)
    
set_user_info(id"_vgui_menus""0")
    
g_autojoin_team[id] = true
}


public 
message_show_menu(msgiddestid) {
    new 
tmp[32]
    
get_msg_arg_string(4tmp31)
    if(
contain(tmp"#Team_Select")==0){
        if(!
g_autojoin_team[id])
            return 
PLUGIN_CONTINUE
        g_autojoin_team
[id] = false
        g_autojoin_class
[id] = true
        client_cmd
(id"jointeam 5")
        return 
PLUGIN_HANDLED
    
}
    if(
contain(tmp"#CT_Select")==|| contain(tmp"#Terrorist_Select")==0){
        if(!
g_autojoin_class[id])
            return 
PLUGIN_CONTINUE
        
if(!task_exists(TID_HIDE_MENU+id))
            
set_task(0.1"hide_menu"TID_HIDE_MENU+id)
        
g_autojoin_class[id] = false
        client_cmd
(id"joinclass 5")
        
set_user_info(id"_vgui_menus"g_vgui_menus[id])
        return 
PLUGIN_HANDLED
    
}
    return 
PLUGIN_CONTINUE
}

public 
hide_menu(tid){
    new 
id tid-TID_HIDE_MENU
    show_menu
(id0"^n"1)
    if(!
is_user_alive(id))
        
ExecuteHam(Ham_CS_RoundRespawnid)



BeeT 07-22-2011 03:14

Re: Spawn on connect
 
It works, thanks man, but i have one more problem.
I edited hide_menu

Code:

public hide_menu(tid){
        new id = tid-TID_HIDE_MENU
        show_menu(id, 0, "^n", 1)
        set_task(1.0, "Respawn", id)
}


and

Code:

public Respawn(id)
{
        if(is_user_alive(id))
                return HAM_IGNORED;
       
        ExecuteHamB(Ham_CS_RoundRespawn, id);
        return HAM_IGNORED;
}



Why after connect i don't see "Respawned" message?
client_print(id, print_chat, "Respawned!");


All times are GMT -4. The time now is 01:10.

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