AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Problem wyth respawn plugin (https://forums.alliedmods.net/showthread.php?t=252776)

Krtola 12-09-2014 08:37

Problem wyth respawn plugin
 
Can someone please help me wyth this error:
PHP Code:

[FUNInvalid player 20 (not in-game)
[
AMXXDisplaying debug trace (plugin "bio_hs.amxx")
[
AMXXRun time error 10native error (native "spawn")
[
AMXX]    [0bio_hs.sma::actual_revive (line 255)
[
FUNInvalid player 20 (not in-game)
[
AMXXDisplaying debug trace (plugin "bio_hs.amxx")
[
AMXXRun time error 10native error (native "spawn")
[
AMXX]    [0bio_hs.sma::actual_revive (line 255

This is respawn plugin:

PHP Code:

 #include <amxmodx>
 #include <amxmisc>
 #include <engine>
 #include <fun>
 #include <biohazard>

 #define PLUGNAME        "Halo Style Respawning"
 #define AUTHOR            "Emp`"
 #define VERSION        "1.31"

 #define    MAX_SPAWNS    60
 #define    MAX_SPEAK    10

 
new Float:HSRtime[33]                //countdown for the users
 
new SOrigin[33][3];

 new 
Float:g_SpawnVecs[MAX_SPAWNS][3];
 new 
Float:g_SpawnAngles[MAX_SPAWNS][3];
 new 
Float:g_SpawnVAngles[MAX_SPAWNS][3];
 new 
g_TotalSpawns;
 
 
//for pcvars
 
new sv_HSRsv_HSRspawnssv_HSRtimesv_HSRmaxtime
 
public plugin_init()
 {

    
register_plugin(PLUGNAMEVERSIONAUTHOR)

    
sv_HSR register_cvar("sv_HSR""1")
    
sv_HSRspawns register_cvar("sv_HSRspawns""0")
    
sv_HSRtime register_cvar("sv_HSRtime""1.0")
    
sv_HSRmaxtime register_cvar("sv_HSRmaxtime""10.0")

    
register_event("DeathMsg","DeathEvent","a")

    
readSpawns()
    
set_msg_block(get_user_msgid("ClCorpse"), BLOCK_SET);
 }

 
readSpawns()
 {    
    new 
Map[32], config[32],  MapFile[64];
    
    
get_mapname(Map31)
    
get_configsdir(config31 )
    
format(MapFile63"%s\csdm\%s.spawns.cfg"configMap);
    
g_TotalSpawns 0;
    
    if (
file_exists(MapFile)) 
    {
        new 
Data[124], len;
            new 
line 0;
            new 
pos[12][8];
            
        while(
g_TotalSpawns MAX_SPAWNS && (line read_file(MapFile line Data 123 len) ) != 
        {
            if (
strlen(Data)<|| Data[0] == '[')
                continue;

            
parse(Datapos[1], 7pos[2], 7pos[3], 7pos[4], 7pos[5], 7pos[6], 7pos[7], 7pos[8], 7pos[9], 7pos[10], 7);
            
            
// Origin
            
g_SpawnVecs[g_TotalSpawns][0] = str_to_float(pos[1]);
            
g_SpawnVecs[g_TotalSpawns][1] = str_to_float(pos[2]);
            
g_SpawnVecs[g_TotalSpawns][2] = str_to_float(pos[3]);
            
            
//Angles
            
g_SpawnAngles[g_TotalSpawns][0] = str_to_float(pos[4]);
            
g_SpawnAngles[g_TotalSpawns][1] = str_to_float(pos[5]);
            
g_SpawnAngles[g_TotalSpawns][2] = str_to_float(pos[6]);
            
            
//v-Angles
            
g_SpawnVAngles[g_TotalSpawns][0] = str_to_float(pos[7]);
            
g_SpawnVAngles[g_TotalSpawns][1] = str_to_float(pos[8]);
            
g_SpawnVAngles[g_TotalSpawns][2] = str_to_float(pos[9]);
            
            
//Team - ignore
            
            
g_TotalSpawns++;
        }
        
        
log_amx("Loaded %d spawn points for map %s."g_TotalSpawnsMap)
    } else {
        
log_amx("No spawn points file found (%s)"MapFile)
    }
    
    return 
1;
 }
 
 public 
spawn_Preset(id)
 {
    if (
g_TotalSpawns 2)
        return 
PLUGIN_CONTINUE
    
    
new list[MAX_SPAWNS];
    new 
num 0
    new final = -
1
    new 
total=0
    new 
players[32], n0;
    new 
Float:loc[32][3], locnum
    
    get_players
(playersnum)
    for (new 
i=0i<numi++)
    {
        if (
is_user_alive(players[i]) && players[i] != id)
        {
            
entity_get_vector(players[i], EV_VEC_originloc[locnum])
            
locnum++
        }
    }
    
    
num 0
    
while (num <= g_TotalSpawns)
    {
        if (
num == g_TotalSpawns)
            break;

        
random_num(0g_TotalSpawns-1);
        
        if (!list[
n])
        {
            list[
n] = 1;
            
num++;
        } 
        else 
        {
            
total++;
            if (
total 100
                break;
            continue;   
        }

        new 
trace  trace_hull(g_SpawnVecs[n],1);
        if (
trace)
            continue;
        
        if (
locnum 1)
        {
            final = 
n
            
break
        }
        
        final = 
n
        
for (0locnumx++)
        {
            new 
Float:distance get_distance_f(g_SpawnVecs[n], loc[x]);
            if (
distance 250.0)
            {
                
//invalidate
                
final = -1;
                break;
            }
        }
        
        if (final != -
1)
            break
    }
    
    if (final != -
1)
    {
        
entity_set_origin(idg_SpawnVecs[final]);
        
entity_set_int(idEV_INT_fixangle1);
        
entity_set_vector(idEV_VEC_anglesg_SpawnAngles[final]);
        
entity_set_vector(idEV_VEC_v_angleg_SpawnVAngles[final]);
        
entity_set_int(idEV_INT_fixangle1);
        
        return 
PLUGIN_HANDLED
    
}

    return 
PLUGIN_CONTINUE
 
}
 public 
DeathEvent()
 {
    new 
attacker read_data(1)
    new 
id read_data(2)

    if(
get_pcvar_num(sv_HSR)<1) return PLUGIN_CONTINUE
    
if(1>get_user_team(id)>2) return PLUGIN_CONTINUE

    
switch(get_pcvar_num(sv_HSR))
    {
        case 
2:{
            if(
is_user_connected(attacker)){
                if(
get_user_team(id)==get_user_team(attacker) || id==attacker){
                    
HSRtime[attacker] += get_pcvar_num(sv_HSRtime)
                    if(
HSRtime[attacker] > get_pcvar_num(sv_HSRmaxtime))
                        
HSRtime[attacker] = get_pcvar_float(sv_HSRmaxtime)
                }
            }
        }
        case 
1:{
            if(
is_user_alive(attacker)){
                
HSRtime[attacker] -= get_pcvar_num(sv_HSRtime)
                if(
HSRtime[attacker]<1.0)
                    
HSRtime[attacker] = 1.0
            
}

            
HSRtime[id] += get_pcvar_num(sv_HSRtime)
            if(
HSRtime[id] > get_pcvar_num(sv_HSRmaxtime))
                
HSRtime[id] = get_pcvar_float(sv_HSRmaxtime)
        }
        default: return 
PLUGIN_CONTINUE
    
}

    new 
time floatround(HSRtime[id]) + 1

    
new parm[2]
    
parm[0] = id
    parm
[1] = time

    set_task
(0.1,"check_respawn",0,parm,2)

    return 
PLUGIN_CONTINUE
 
}
 public 
check_respawn(parm[])
 {
    new 
id parm[0]
    
parm[1]--

    if(
is_user_alive(id) || !is_user_zombie(id) )
        return

    if(
parm[1]==0){
        
respawn(id)
    }
    else{
        if(
parm[1]<MAX_SPEAK){
            new 
speak[30]
            
num_to_word(parm[1], speak29)
            
client_cmd(id,"spk ^"fvox/%s^"",speak
        }
        
client_print(idprint_center"You will respawn in %d seconds."parm[1])
        
set_task(1.0,"check_respawn",0,parm,2)
    }
 }
 public 
respawn(id)
 {
    if( 
is_user_alive(id) ||  !is_user_connected(id)) return -1

    
if(is_user_zombie(id) ) {
        new 
parm[2]
        
parm[0] = id
        parm
[1] = 0
        set_task
0.5"actual_revive"1parm2)
        
parm[1] = 1
        set_task
0.7"actual_revive"1parm2)
        return 
1
    
}
    return 
0
 
}
 public 
actual_revive(parm[])
 {
    new 
id parm[0], parm[1]
    
spawn(id)
    if(
a==0)
        
get_user_origin(idSOrigin[id])
    else {
        if(
get_pcvar_num(sv_HSRspawns) > 0)
            
spawn_Preset(id)
        else
            
set_user_origin(idSOrigin[id])
    }
 }


 public 
client_connect(id)
 {
    
HSRtime[id] = get_pcvar_float(sv_HSRtime)
 }
 public 
client_putinserver(id)
 {
    
set_task(1.0,"first_respawn",id)
 }
 public 
first_respawn(id)
 {
    if(!
respawn(id))
        
set_task(1.0,"first_respawn",id)
 } 


Kia 12-09-2014 08:40

Re: Problem wyth respawn plugin
 
Code:
public actual_revive(parm[])  {     new id = parm[0], a = parm[1]     spawn(id)     if(a==0)         get_user_origin(id, SOrigin[id])     else {         if(get_pcvar_num(sv_HSRspawns) > 0)             spawn_Preset(id)         else             set_user_origin(id, SOrigin[id])     }  }

->

Code:
 public actual_revive(parm[])  {     new id = parm[0], a = parm[1]     if(!is_user_connected(id))         return PLUGIN_HANDLED     if(a==0)         get_user_origin(id, SOrigin[id])     else {         if(get_pcvar_num(sv_HSRspawns) > 0)             spawn_Preset(id)         else             set_user_origin(id, SOrigin[id])     }  }

Krtola 12-09-2014 09:04

Re: Problem wyth respawn plugin
 
@Kia actual_revive should return a value

I'm not sure what I should do now, or how.

But, it should be like this or not?

PHP Code:

public actual_revive(parm[])
 {
    new 
id parm[0], parm[1]

    if(!
is_user_connected(id))
        return 
PLUGIN_HANDLED

    
if(a==0)
        
get_user_origin(idSOrigin[id])
    else {
        if(
get_pcvar_num(sv_HSRspawns) > 0)
            
spawn_Preset(id)
        else
            
set_user_origin(idSOrigin[id])
    }
    return 
PLUGIN_CONTINUE
 



Kia 12-09-2014 09:25

Re: Problem wyth respawn plugin
 
The compiler wants you to return something because it always cries if you return in a case before.

Krtola 12-09-2014 11:41

Re: Problem wyth respawn plugin
 
Quote:

Originally Posted by Kia (Post 2232897)
The compiler wants you to return something because it always cries if you return in a case before.

Yes I know that,I just do not know if in this particular situation should be return PLUGIN_CONTINUE .
Tested and works nicely for now.
Thanks.

zmd94 12-09-2014 11:53

Re: Problem wyth respawn plugin
 
Yes, it should return PLUGIN_CONTINUE . ;)

YamiKaitou 12-09-2014 12:38

Re: Problem wyth respawn plugin
 
Or, you could ignore it since it is only a Warning

Krtola 12-09-2014 13:45

Re: Problem wyth respawn plugin
 
actually not working.
When I tested,I just wryte kill in console,but did not wait for the expiry of the time required for respawn.

But now I waited and it did not happen(respawn)
I can not ignore that warning because I can not compile plugin.

zmd94 12-09-2014 20:51

Re: Problem wyth respawn plugin
 
If you want the auto respawn plugin, maybe this will be more simpler:
PHP Code:

#include <amxmodx>
#include <hamsandwich>

public plugin_init()
{
    
register_plugin("Auto Respawn""1.0""zmd94")
    
    
RegisterHam(Ham_Killed"player""Ham_Killed_Post"1)
}

public 
Ham_Killed_Post(victimattackershouldgib)
{
    
set_task(5.0"iRespawn"victim)
}
    
public 
iRespawn(id)
{
    
ExecuteHamB(Ham_CS_RoundRespawnid)  


Just add the countdown if you needed. ;)

Krtola 12-10-2014 00:10

Re: Problem wyth respawn plugin
 
Quote:

Originally Posted by zmd94 (Post 2233151)
If you want the auto respawn plugin, maybe this will be more simpler:
PHP Code:

#include <amxmodx>
#include <hamsandwich>

public plugin_init()
{
    
register_plugin("Auto Respawn""1.0""zmd94")
    
    
RegisterHam(Ham_Killed"player""Ham_Killed_Post"1)
}

public 
Ham_Killed_Post(victimattackershouldgib)
{
    
set_task(5.0"iRespawn"victim)
}
    
public 
iRespawn(id)
{
    
ExecuteHamB(Ham_CS_RoundRespawnid)  


Just add the countdown if you needed. ;)

No.I need this one.
Will try this:
PHP Code:

if(!is_user_connected(id)) 
        return 
PLUGIN_HANDLED 

:arrow:
PHP Code:

if(is_user_connected(id)) 



All times are GMT -4. The time now is 15:23.

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