AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [Respawn] Crash my server ... (https://forums.alliedmods.net/showthread.php?t=54016)

sbeex 04-15-2007 11:03

[Respawn] Crash my server ...
 
Hello !
Today with help of Doombringer I tried to do a plugin who do : auto-respawn when you die.

The problem is that it do crash the server when you're die ^^

This is the code :
Code:

#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <string>

#define PLUGIN "Auto-Respawn"
#define VERSION "1.0"
#define AUTHOR "Sbeex"


public plugin_init() {
        register_plugin(PLUGIN, VERSION, AUTHOR)
        register_event("DeathMsg", "Respawn", "a")        //when someone die -> exec Respawn()
       
}

public Respawn() {
       
        new id = read_data(2)
       
        //Read_data values :
       
        // 1 -> killer
        // 2 -> victim
        // 3 -> headshot
        // 4 -> weapon id

        spawn(id);
        set_task(0.5, "Respawn_Again", id);
        client_print(id, print_chat, "If it work you have respawn !");
       
       
       
        return PLUGIN_CONTINUE       
}

public Respawn_Again(id)
{
        spawn(id);
}

If you can see any errors please tell me ! :)

(i'm french sorry for my english)

Dark Kingdom 04-15-2007 12:03

Re: [Respawn] Crash my server ...
 
Try this, you need fun module and cstrike module activated.
But if you want this for another game PM me and we can get this sorted out.
PHP Code:

#include <amxmodx>
#include <fun>
#include <cstrike>

#define DISABLE_CS 0

#define UNASSIGNED 0 
#define TS 1 
#define CTS 2 
#define AUTO_TEAM 5 

new bool:g_PistolsDisabled false
new const VERSION[] =    "1.1"

public plugin_init(){

    
register_plugin("Respawn Forever"VERSION"respawn")

    
register_event("DeathMsg","on_Death","a")
    
    
register_cvar("sv_checkpistols""1")
    
register_cvar("sv_respawn""1")
    
register_cvar("respawn_forever_version"VERSIONFCVAR_SERVER)

    
register_clcmd("say","on_Chat")
    
register_clcmd("say_team","on_Chat")
}

public 
on_Chat(id)
{
    if ( !
get_cvar_num("sv_respawn") )
    {
        
client_print(idprint_chat"* Respawn plugin disabled")
        return 
PLUGIN_CONTINUE
    
}

    new 
szSaid[32]
    
read_args(szSaid31

    if (
equali(szSaid,"^"/respawn^"") || equali(szSaid,"^"respawn^""))
    {
        
spawn_func(id)
    }
}

public 
check_pistols()
{
    if ( 
get_cvar_num("sv_checkpistols") )
    {
        
set_task(1.0"check_pistols")
        new 
mapname[32]
        
get_mapname(mapname,31
        if ( 
containi(mapname,"ka_")!=-|| containi(mapname,"scoutzknivez")!=-)
                
g_PistolsDisabled true
    
}
}

public 
spawn_func(id)
{
    new 
parm[1]
    
parm[0]=id
    
    set_task
(0.5,"player_spawn",72,parm,1)
    
set_task(0.7,"player_spawn",72,parm,1)

    
set_task(0.9,"player_giveitems",72,parm,1)
}

public 
on_Death()
{
    if ( !
get_cvar_num("sv_respawn") )
        return 
PLUGIN_CONTINUE
    
    
new victim_id read_data(2)
    
    
spawn_funcvictim_id )

    return 
PLUGIN_CONTINUE
}

public 
player_giveitems(parm[1])
{
    new 
id parm[0]

    
give_item(id"item_suit")
    
give_item(id"weapon_knife")

    if ( !
g_PistolsDisabled )
    {
        new 
wpnList[32] = 0number 0bool:foundGlock falsebool:foundUSP false 
        get_user_weapons
(id,wpnList,number)
        
        for (new 
0;number;i++)
        { 
            if (
wpnList[i] == CSW_GLOCK18
                
foundGlock true 
            
if (wpnList[i] == CSW_USP
                
foundUSP true 
        
}
        
        if ( 
get_user_team(id)==TS && !foundGlock )
        {
                
give_item(id,"weapon_glock18")
                
give_item(id,"ammo_9mm")
                
give_item(id,"ammo_9mm")
        }
        else if ( 
get_user_team(id)==CTS && !foundUSP )
        {
                
give_item(id,"weapon_usp")
                
give_item(id,"ammo_45acp")
                
give_item(id,"ammo_45acp")
        }
    }

    return 
PLUGIN_CONTINUE
}

public 
player_spawn(parm[1])
{
    
spawn(parm[0])



sbeex 04-16-2007 03:32

Re: [Respawn] Crash my server ...
 
thank's i've find my errors ^^ it was with set_task i have to put in an array the parameters

This is my actually code and there is some bugs ... I try to give the same item to the player respawned he had before dying.

PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <fun>
 
#define PLUGIN "Auto-Respawn"
#define VERSION "1.0"
#define AUTHOR "Sbeex"
 
#define TIME_RESPAWN     0.5    // Delay before respawn
#define DELAY_RESPAWN     0.5    // Delay before the second respawn
 
public plugin_init( ) 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_event("DeathMsg""Event_Deathmsg""a");    //when someone die -> exec event_deathmsg()
    
register_event("Damage" "Check_HP""b");        //when someone loose hp -> exec Check_HP()
}

 
public 
Event_Deathmsg() 
{
    new 
victim read_data(2);
    
    
//read_data values :
    
    // 1 -> killer
    // 2 -> victim
    // 3 -> headshot
    // 4 -> weapon id    
    
    
new params[1];
    
params[0] = victim;
    
    
set_task(TIME_RESPAWN"Respawn_Again"victim 558params1);    // First Respawn
    
set_task(TIME_RESPAWN DELAY_RESPAWN"Respawn_Again"victim 559params1);    //Second Respawn
    
    
client_print(victimprint_chat"If it work you have respawn !"); 
}
 
public 
Respawn_Again(params[])
{
    
spawn(params[0]);    //Spawn the victim
}

//----------------------------------------------------------------------------------------
// Save and give equipement after respawn
//----------------------------------------------------------------------------------------
public Check_HP()
{
    new 
victim read_data(2)
    
    
//read_data values :
    
    // 1 -> killer
    // 2 -> victim
    // 3 -> damage
    // 4 -> weapon[]
    // 5 -> hitplace
    // 6 -> Teamkill
    
    
new hp get_user_health(victim);    //HP of player
    
    //Player is died !
    
if(hp << 1)
    {
        
//Debug message
        
client_print(victimprint_chat"Your are died !"); 
        
        new 
params[1];
        
params[0] = victim;
        
        
set_task(TIME_RESPAWN"Respawn_Again"victim 558params1);    // First Respawn
        
set_task(TIME_RESPAWN DELAY_RESPAWN"Respawn_Again"victim 559params1);    //Second Respawn        
        
client_print(victimprint_chat"You have respawn !");     
        
    }
    else if(
hp >> 1)
    {
        
//Debug message
        
client_print(victimprint_chat"Your are alive with %d hp's !"hp);             
    }    


thank's for your help man :)


All times are GMT -4. The time now is 06:42.

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