AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How to use get_players? (https://forums.alliedmods.net/showthread.php?t=110228)

byetovice 11-27-2009 03:00

How to use get_players?
 
how can i use get_players?i get this error "invalid player x"

code :
Code:

/* Plugin generated by AMXX-Studio */
#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <hamsandwich>
#include <cstrike>
#include <fakemeta>
#include <engine>
#define PLUGIN "Heal on See"
#define VERSION "1.0"
#define AUTHOR "author"

public plugin_init() {
 register_plugin(PLUGIN, VERSION, AUTHOR)
 RegisterHam(Ham_Spawn,"player","FwdHamPlayerSpawn",1);
 
}
public FwdHamPlayerSpawn(id)
{
set_task(1.0,"healonsee",id,"",0,"b")
}
public healonsee(id)
{
new players[32],num;
get_players(players,num)
new i;
for(i=0;i<num;i++)
{
if(num!=0)
{
if(is_user_alive(players[i]))
{
new origin1[3],origin2[3];
get_user_origin(id,origin1,0)
get_user_origin(players[i],origin2,0)
new distance = get_distance(origin1,origin2)
if(distance <=40.0)
{
set_user_health(id,get_user_health(id)+1)
}
}
}
}
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ ansicpg1254\\ deff0\\ deflang1055{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ f0\\ fs16 \n\\ par }
*/

what's wrong? please helpme

Bugsy 11-27-2009 23:27

Re: How to use get_players?
 
The code works now but it constantly increases hp every second when you are within the specified distance from another player, is this what you intended?. The reason I ask is I see your plugin title is "Heal on See"; were you trying to make it so if players can see each other it restores health? Or just if they are close to each other? If the latter then you may need to increase the distance of 40 a little bit.

PHP Code:

#include <amxmodx>
#include <hamsandwich>
#include <fun>

#define PLUGIN   "Heal on See"
#define VERSION  "1.0"
#define AUTHOR   "author"

public plugin_init() 
{
    
register_pluginPLUGIN VERSION AUTHOR );
    
    
register_event"DeathMsg" "fw_EvDeathMsg" "a" "2>0" );
    
    
RegisterHamHam_Spawn "player" "FwdHamPlayerSpawn_Post" );
}

public 
FwdHamPlayerSpawn_Postid )
{
    if ( 
is_user_aliveid ) )
        
set_task1.0 "healonsee" id "b" );
}

public 
fw_EvDeathMsg()
{
    
remove_taskread_data) );
}

public 
healonsee(id)
{
    new 
players[32] , num iPlayer;
    new 
origin1] , origin2];
    
    
get_playersplayers num ); 
    
    for( new 
num i++ )
    {
        
iPlayer players];
        
        if( ( 
id != iPlayer ) && is_user_aliveiPlayer ) )
        {
            
get_user_originid origin1 );
            
get_user_originiPlayer origin2 );
            
            if( 
get_distanceorigin1 origin2 ) <= 40 )
            {
                
set_user_healthid get_user_healthid ) + );
            }
        }
    }




All times are GMT -4. The time now is 13:41.

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