AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Ultimate Revive - problem [Solved!] (https://forums.alliedmods.net/showthread.php?t=76522)

anakin_cstrike 08-26-2008 07:19

Ultimate Revive - problem [Solved!]
 
Hi!
I'm having problems with this addition: see below.
This works well:
PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <fakemeta>

#define PLUGIN "Ultimate Revive"
#define VERSION "1.1"
#define AUTHOR "anakin_cstrike"

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR);
    
register_concmd("amx_revive","revive_cmd",ADMIN_BAN,"- <player/@/@T/@CT> <hp> <armor>");
}
public 
revive_cmd(id,level,cid)
{
    if(!
cmd_access(id,level,cid,4))
        return 
PLUGIN_HANDLED;
    new 
    
arg[32],arg2[4],arg3[4],
    
name[32],hp,armor;
    
read_argv(1,arg,31);
    
read_argv(2,arg2,3);
    
read_argv(3,arg3,3);
    
get_user_name(id,name,31);
    
hp str_to_num(arg2);
    
armor str_to_num(arg3);
    if(
arg[0] == '@')
    {
        new 
players[32],teamname[24],tname[16],num,index,i;
        if(
arg[1])
        {
            if(
arg[1] == 'T')
            {
                
copy(tname,15,"TERRORIST");
                
copy(teamname,23,"Terrorist");
            }
            if(
arg[1] == 'C' && arg[2] == 'T')
            {
                
copy(tname,15,"CT");
                
copy(teamname,23,"Counter-Terrorist");
            }
            
get_players(players,num,"be",tname);
        } else {
            
get_players(players,num);
            
copy(teamname,23,"All");
        }
        if(
num == 0)
        {
            
console_print(id,"No players in team %s",teamname);
            return 
PLUGIN_HANDLED;
        }
        for(
0;num;i++)
        {
            
index players[i];
            if(
is_user_alive(index)) continue;
            
Revive(index,hp,armor);
        }
        
log_amx("ADMIN %s: Revive %s with %i hp and %i armor",name,teamname,hp,armor);
    } else {
        new 
target cmd_target(id,arg,3);
        if(!
target)
            return 
PLUGIN_HANDLED;
        if(
is_user_alive(target))
        {
            
console_print(id,"Player is allready alive !");
            return 
PLUGIN_HANDLED;
        }
        new 
namet[32]; get_user_name(target,namet,31);
        
Revive(target,hp,armor);
        
log_amx("ADMIN %s: Revive %s with %i hp and %i armor",name,namet,hp,armor);
    }
    return 
PLUGIN_HANDLED;
}
Revive(index,hp,armor)
{
    
set_pev(index,pev_deadflag,DEAD_RESPAWNABLE);
    
set_pev(index,pev_iuser1,0);
    
dllfunc(DLLFunc_Think,index);
    
engfunc(EngFunc_SetOrigin,index,Float:{-4800.0,-4800.0,-4800.0});
    new array[
3];
    array[
0] = index;
    array[
1] = hp;
    array[
2] = armor
    set_task
(0.5,"respawn",0,array,3);
}
public 
respawn(array[3])
{
    new 
index = array[0];
    new 
hp = array[1];
    new 
armor = array[2];
    if(
is_user_connected(index))
        {
        
dllfunc(DLLFunc_Spawn,index);
        
set_pev(index,pev_health,float(hp));
        
set_pev(index,pev_armorvalue,float(armor));
        if(
get_user_team(index) == 1)
        {
            
fm_give_item(index,"weapon_knife");
            
fm_give_item(index,"weapon_glock18");
            
fm_give_item(index,"ammo_9mm");
            
fm_give_item(index,"ammo_9mm");
            
fm_give_item(index,"ammo_9mm");
            
fm_give_item(index,"ammo_9mm");
        } else if(
get_user_team(index) == 2) {
            
fm_give_item(index,"weapon_knife");
            
fm_give_item(index,"weapon_usp");
            
fm_give_item(index,"ammo_45acp");
            
fm_give_item(index,"ammo_45acp");
            
fm_give_item(index,"ammo_45acp");
            
fm_give_item(index,"ammo_45acp");
        }
        
Fade(index,0,255,0,30);
    }
}
stock fm_give_item(id,const item[])
{
    static 
ent
    ent 
engfunc(EngFunc_CreateNamedEntityengfunc(EngFunc_AllocStringitem));
    if(!
pev_valid(ent)) return;
   
    static 
Float:originF[3]
    
pev(idpev_originoriginF);
    
set_pev(entpev_originoriginF);
    
set_pev(entpev_spawnflagspev(entpev_spawnflags) | SF_NORESPAWN);
    
dllfunc(DLLFunc_Spawnent);
   
    static 
save
    save 
pev(entpev_solid);
    
dllfunc(DLLFunc_Touchentid);
    if(
pev(ent,pev_solid) != save)
        return;
      
    
engfunc(EngFunc_RemoveEntityent);
}
stock Fade(index,red,green,blue,alpha)
{
    
message_begin(MSG_ONE,get_user_msgid("ScreenFade"),{0,0,0},index);
    
write_short(1<<10);
    
write_short(1<<10);
    
write_short(1<<12);
    
write_byte(red);
    
write_byte(green);
    
write_byte(blue);
    
write_byte(alpha);
    
message_end();


But his, doesn't revive me:
PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <fakemeta>

#define PLUGIN "Ultimate Revive"
#define VERSION "1.0"
#define AUTHOR "anakin_cstrike"

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR);
    
register_concmd("amx_revive","revive_cmd",ADMIN_BAN,"- <player/@/@T/@CT> <hp> <armor>");
}
public 
revive_cmd(id,level,cid)
{
    if(!
cmd_access(id,level,cid,4))
        return 
PLUGIN_HANDLED;
    new 
    
arg[32],arg2[4],arg3[4],
    
name[32],hp,armor;
    
read_argv(1,arg,31);
    
read_argv(2,arg2,3);
    
read_argv(3,arg3,3);
    
get_user_name(id,name,31);
    new 
argc read_argc();
    switch(
argc)
    {
        case 
1: {hp 100;armor 0;print(id,"Using default values: %dhp, %darmor",hp,armor);}
        case 
2: {hp str_to_num(arg2);armor 0;print(id,"Hp: %d, default armor value: %d",armor);}
        case 
3: {hp str_to_num(arg2);armor str_to_num(arg3);print(id,"Hp: %d, Armor: %d",hp,armor); }
    }
    if(
arg[0] == '@')
    {
        new 
players[32],teamname[24],tname[16],num,index,i;
        if(
arg[1])
        {
            if(
arg[1] == 'T')
            {
                
copy(tname,15,"TERRORIST");
                
copy(teamname,23,"Terrorist");
            }
            if(
arg[1] == 'C' && arg[2] == 'T')
            {
                
copy(tname,15,"CT");
                
copy(teamname,23,"Counter-Terrorist");
            }
            
get_players(players,num,"be",tname);
        } else {
            
get_players(players,num);
            
copy(teamname,23,"All");
        }
        if(
num == 0)
        {
            
console_print(id,"No players in team %s",teamname);
            return 
PLUGIN_HANDLED;
        }
        for(
0;num;i++)
        {
            
index players[i];
            if(
is_user_alive(index)) continue;
            
Revive(index,hp,armor);
        }
        
log_amx("ADMIN %s: Revive %s with %i hp and %i armor",name,teamname,hp,armor);
    } else {
        new 
target cmd_target(id,arg,3);
        if(!
target)
        return 
PLUGIN_HANDLED;
        if(
is_user_alive(target))
        {
            
console_print(id,"Player is allready alive !");
            return 
PLUGIN_HANDLED;
        }
        new 
namet[32]; get_user_name(target,namet,31);
        
Revive(target,hp,armor);
        
log_amx("ADMIN %s: Revive %s with %i hp and %i armor",name,namet,hp,armor);
    }
    return 
PLUGIN_HANDLED;
}
Revive(index,hp,armor)
{
    
set_pev(index,pev_deadflag,DEAD_RESPAWNABLE);
    
set_pev(index,pev_iuser1,0);
    
dllfunc(DLLFunc_Think,index);
    
engfunc(EngFunc_SetOrigin,index,Float:{-4800.0,-4800.0,-4800.0});
    new array[
3];
    array[
0] = index;
    array[
1] = hp;
    array[
2] = armor
    set_task
(0.5,"respawn",0,array,3);
}
public 
respawn(array[3])
{
    new 
index = array[0];
    new 
hp = array[1];
    new 
armor = array[2];
    if(
is_user_connected(index))
    {
        
dllfunc(DLLFunc_Spawn,index);
        
set_pev(index,pev_health,float(hp));
        
set_pev(index,pev_armorvalue,float(armor));
        if(
get_user_team(index) == 1)
        {
        
fm_give_item(index,"weapon_knife");
        
fm_give_item(index,"weapon_glock18");
        
fm_give_item(index,"ammo_9mm");
        
fm_give_item(index,"ammo_9mm");
        
fm_give_item(index,"ammo_9mm");
        
fm_give_item(index,"ammo_9mm");
        } else if(
get_user_team(index) == 2) {
        
fm_give_item(index,"weapon_knife");
        
fm_give_item(index,"weapon_usp");
        
fm_give_item(index,"ammo_45acp");
        
fm_give_item(index,"ammo_45acp");
        
fm_give_item(index,"ammo_45acp");
        
fm_give_item(index,"ammo_45acp");
        }
        
Fade(index,0,255,0,30);
    }
}
stock fm_give_item(id,const item[])
{
    static 
ent
    ent 
engfunc(EngFunc_CreateNamedEntityengfunc(EngFunc_AllocStringitem));
    if(!
pev_valid(ent)) return;
   
    static 
Float:originF[3]
    
pev(idpev_originoriginF);
    
set_pev(entpev_originoriginF);
    
set_pev(entpev_spawnflagspev(entpev_spawnflags) | SF_NORESPAWN);
    
dllfunc(DLLFunc_Spawnent);
   
    static 
save
    save 
pev(entpev_solid);
    
dllfunc(DLLFunc_Touchentid);
    if(
pev(ent,pev_solid) != save)
        return;
      
    
engfunc(EngFunc_RemoveEntityent);
}
stock Fade(index,red,green,blue,alpha)
{
    
message_begin(MSG_ONE,get_user_msgid("ScreenFade"),{0,0,0},index);
    
write_short(1<<10);
    
write_short(1<<10);
    
write_short(1<<12);
    
write_byte(red);
    
write_byte(green);
    
write_byte(blue);
    
write_byte(alpha);
    
message_end();
}
stock print(index,const message[],{Float,Sql,Result,_}:...)
{
    new 
Buffer[64];
    
formatex(Buffer,63,"%s",message);
    
console_print(index,"%s",Buffer);


And the problem is here:
Quote:

new argc = read_argc();
switch(argc)
{
case 1: {hp = 100;armor = 0;print(id,"Using default values: %dhp, %darmor",hp,armor);}
case 2: {hp = str_to_num(arg2);armor = 0;print(id,"Hp: %d, default armor value: %d",armor);}
case 3: {hp = str_to_num(arg2);armor = str_to_num(arg3);print(id,"Hp: %d, Armor: %d",hp,armor); }
}
If i remove this part...the plugin works.

Can you help me ?
Image: [IMG]http://img253.**************/img253/1091/26534552tq8.th.png[/IMG]

xPaw 08-26-2008 07:23

Re: Ultimate Revive - problem
 
i dont know but try like this
PHP Code:

switch(argc)
{
case 
1: {
   
hp 100;
   
armor 0;
   print(
id,"Using default values: %dhp, %darmor",hp,armor);
}
case 
2: {
   
hp str_to_num(arg2);
   
armor 0;
   print(
id,"Hp: %d, default armor value: %d",armor);
}
case 
3: {
  
hp str_to_num(arg2);
  
armor str_to_num(arg3);
  print(
id,"Hp: %d, Armor: %d",hp,armor);
}



anakin_cstrike 08-26-2008 07:32

Re: Ultimate Revive - problem
 
Is the same thing..i've tried with if statements but the same result:cry:

xPaw 08-26-2008 07:37

Re: Ultimate Revive - problem
 
when you made screen, what method you used ? 1/2/3 ?

anakin_cstrike 08-26-2008 07:41

Re: Ultimate Revive - problem
 
Quote:

Originally Posted by xPaw (Post 675919)
when you made screen, what method you used ? 1/2/3 ?

What ?! the screenshot or my cs with software is not important...the plugin's functionality is important right now.

Prajch 08-26-2008 10:07

Re: Ultimate Revive - problem
 
read_argc() returns the number of arguments in a command, including the command itself. In your case, that'll usually be 4. So your switch never actually does anything, and the "hp" value stays at its initial value, 0. When you set someone's hp to anything below 1, that's what happens to their camera.

[edit] I see what you're trying to do now. I think it was only breaking because you were using the 3 argument version (name, hp, armor) which sets the total parameters to 4 (command, name, hp, armor). Is that right?

anakin_cstrike 08-26-2008 11:02

Re: Ultimate Revive - problem
 
I was trying to do: if you use the command like this:
PHP Code:

amx_revive player 50 

- the 3rd argument is missing, so ...using the default value: 0 (armor).
If:
PHP Code:

amx_revive player 

the 2nd and the 3rd argument are missing, os...using the default values: 100 hp and 0 armor.
Now you understand what i'm trying to do ?:)...

However, the first argument is the command ? like cmd_access ? so, if i write 4 arguments it will be ok ?

Emp` 08-26-2008 12:44

Re: Ultimate Revive - problem
 
Code:

new argc = read_argc();
switch(argc)
{
case 3: {hp = str_to_num(arg2);armor = 0;print(id,"Hp: %d, default armor value: %d",armor);}
case 4: {hp = str_to_num(arg2);armor = str_to_num(arg3);print(id,"Hp: %d, Armor: %d",hp,armor); }
default: {hp = 100;armor = 0;print(id,"Using default values: %dhp, %darmor",hp,armor);}
}


danielkza 08-26-2008 13:02

Re: Ultimate Revive - problem
 
Quote:

Originally Posted by Emp` (Post 676063)
Code:

new argc = read_argc();
switch(argc)
{
case 3: {hp = str_to_num(arg2);armor = 0;print(id,"Hp: %d, default armor value: %d",armor);}
case 4: {hp = str_to_num(arg2);armor = str_to_num(arg3);print(id,"Hp: %d, Armor: %d",hp,armor); }
default: {hp = 100;armor = 0;print(id,"Using default values: %dhp, %darmor",hp,armor);}
}


This is a bit wrong, if the users sends more than 4 arguments, the health and armor values will be ignored. It's better to
Code:

if(argc < 2) {default values}
else if(argc == 3) {default hp}
else {read hp and armor}


anakin_cstrike 08-26-2008 14:20

Re: Ultimate Revive - problem
 
Quote:

Originally Posted by danielkza (Post 676077)
This is a bit wrong, if the users sends more than 4 arguments, the health and armor values will be ignored. It's better to
Code:

if(argc < 2) {default values}
else if(argc == 3) {default hp}
else {read hp and armor}


If none of the cases writen are true...then the default is evalueted.


All times are GMT -4. The time now is 03:17.

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