Raised This Month: $51 Target: $400
 12% 

Confused about using functions including "health"


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
groofshark
Member
Join Date: Jul 2013
Old 05-19-2015 , 15:54   Confused about using functions including "health"
Reply With Quote #1

Hello, I am trying to fix this code, but I am confused about everything continuing 2-3 days
So, I am trying to combine health regeneration with receiving more health after spawn...

1. g_iSpawnHealth - get spawn health, it can be also more than 100
2. type /regen and regenerate health until g_iSpawnHealth
3. type /buyhealth after spawn - add +50 health to g_iSpawnHealth and I want automatically g_iSpawnHealth to be transfered into g_iSpawnHealth + 50 (new max health) and +50 health to player only
4. regen to continue halth regeneration already until "g_iSpawnHealth + 50" (the new max health)

That's I want but can't make it... That's the code which I made. I would like to help me, thanks!

Code

Last edited by groofshark; 05-19-2015 at 15:56.
groofshark is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 05-22-2015 , 16:17   Re: Confused about using functions including "health"
Reply With Quote #2

i dont understand exactly what you want to do.. could you please explain better?
you want the regen hp limit to increase by 50hp for everytime the player is respawned?
Depresie is offline
groofshark
Member
Join Date: Jul 2013
Old 05-23-2015 , 11:17   Re: Confused about using functions including "health"
Reply With Quote #3

I just want HP regen, until spawn health(it can be 100, 120 etc...) and if I buy more health HP regen if I have spawn health 120 and HP Buy +50 = 170. So I want HP regen to be until 170. That's all.
groofshark is offline
!Morte
Veteran Member
Join Date: May 2010
Old 05-23-2015 , 14:18   Re: Confused about using functions including "health"
Reply With Quote #4

PHP Code:
/* Plugin generated by AMXX-Studio */

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

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"

const TASK_REGEN 7777;

#define ID_REGEN        ( taskid - TASK_REGEN )

new g_SpawnHealth33 ];
new 
g_MaxPlayers;

public 
plugin_init() 
{
    
register_pluginPLUGINVERSIONAUTHOR );
    
    
register_logevent("logevent_round_end"2"1=Round_End")
    
    
register_clcmd"say /buyhealth""clcmd_buyheatlh" );
    
register_clcmd"say /regen""clcmd_regen" );
    
    
RegisterHamHam_Killed"player""fw_PlayerKilled" );
    
RegisterHamHam_Spawn"player""fw_PlayerSpawn_Post");
    
    
g_MaxPlayers get_maxplayers( );
}

public 
client_putinserverid )
{
    
g_SpawnHealthid ] = 100;
}

public 
client_disconnectid )
{
    
remove_taskid+TASK_REGEN );
}

public 
logevent_round_end( )
{
    for( new 
id 1id <= g_MaxPlayersid++ )
        
remove_taskid+TASK_REGEN );
}

public 
clcmd_buyheatlhid )
{
    
g_SpawnHealthid ] += 50;
    
set_user_healthidget_user_healthid ) + 50 );
    
client_printidprint_chat"You bought +50 HP and you healed +50 HP too." );
    return 
PLUGIN_HANDLED;
}

public 
clcmd_regenid )
{
    if( 
task_existsid+TASK_REGEN ) )
    {
        
client_printidprint_chat"HP Regeneration is on." );
        return 
PLUGIN_HANDLED;
    }
    
    
set_task1.0"task_hp_regen"id+TASK_REGEN__"b" );
    
    return 
PLUGIN_HANDLED;
}

public 
task_hp_regentaskid )
{
    if( !
is_user_aliveID_REGEN ) )
        
remove_taskID_REGEN );

    if( 
get_user_healthID_REGEN ) < g_SpawnHealthID_REGEN ] )
        
set_user_healthID_REGENget_user_healthID_REGEN ) + );
}

public 
fw_PlayerSpawn_Postid )
{
    if( !
is_user_aliveid ) )
        return;
    
    
remove_taskid+TASK_REGEN );
    
set_user_healthidg_SpawnHealthid ] );
}

public 
fw_PlayerKilledvictimattackershouldgib )
{
    if( 
task_existsvictim+TASK_REGEN ) )
        
remove_taskvictim+TASK_REGEN );

__________________
First Zombie Class
[ZP] Zombie Class: Houndeye Zombie
Quote:
Originally Posted by lucas_7_94 View Post
tenes que saber pawn antes de intentar hacer algo digno.

Last edited by !Morte; 05-23-2015 at 14:19.
!Morte is offline
Send a message via MSN to !Morte Send a message via Skype™ to !Morte
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-23-2015 , 16:24   Re: Confused about using functions including "health"
Reply With Quote #5

My only suggestion would be to use a single thinking entity that regenerates all players via a loop. With your method, you are constantly re-creating tasks for each player and it is an expensive operation to create tasks. Also, when you call remove_task(), you do not need to check if the task exists first..it will remove it if it exists without checking first.

Edit: Made entity only think during round when player(s) have regen on. Added macros for bit operations.
PHP Code:
#include <amxmodx>
#include <engine>
#include <fun>
#include <hamsandwich>

#define CheckBit(%1)    (g_RegenStatus & (1<<(%1 & 31)))
#define SetBit(%1)    (g_RegenStatus = (1<<(%1 & 31)))
#define RemoveBit(%1)    (g_RegenStatus &= ~(1<<(%1 & 31)))

new g_SpawnHealth33 ];
new 
g_MaxPlayers;
new 
g_RegenStatus;
new 
g_iRegenEntity;

public 
plugin_init() 
{
    
register_logevent("logevent_round_end"2"1=Round_End")
    
    
register_clcmd"say /buyhealth""clcmd_buyheatlh" );
    
register_clcmd"say /regen""clcmd_regen" );
    
    
RegisterHamHam_Spawn"player""fw_PlayerSpawn_Post");
    
    
g_iRegenEntity create_entity"info_target" );
    
entity_set_stringg_iRegenEntity EV_SZ_classname "regenhealth_entity" );
    
register_think"regenhealth_entity" "fw_EntThink" );
    
    
g_MaxPlayers get_maxplayers( );
}

public 
client_putinserverid )
{
    
g_SpawnHealthid ] = 100;
}

public 
client_disconnectid )
{
    
RemoveBitid );
}

public 
clcmd_buyheatlhid )
{
    
g_SpawnHealthid ] += 50;
    
    
set_user_healthidget_user_healthid ) + 50 );
    
client_printidprint_chat"* You bought +50 HP and you healed +50 HP too." );
    
    return 
PLUGIN_HANDLED;
}

public 
clcmd_regenid )
{
    if ( !
is_user_aliveid ) )
    {
        
client_printidprint_chat"* You must be alive to use HP Regeneration." );
    }
    else if ( 
CheckBitid ) )
    {
        
client_printidprint_chat"* HP Regeneration is already on!" );
    }
    else
    {
        if ( !
g_RegenStatus )
        {
            
entity_set_floatg_iRegenEntity EV_FL_nextthink , ( get_gametime() + 1.0 ) );
        }
        
        
SetBitid );
        
client_printidprint_chat"* Your health regeneration has been activated.");
    }

    return 
PLUGIN_HANDLED;
}

public 
fw_PlayerSpawn_Postid )
{
    if( 
is_user_aliveid ) )
    {
        
set_user_healthid g_SpawnHealthid ] );
    }
}

public 
logevent_round_end( )
{
    
g_RegenStatus 0;
}

public 
fw_EntThinkiEntity )
{
    if ( 
g_RegenStatus )
    {
        for ( new 
id id <= g_MaxPlayers id++ )
        {
            if ( 
CheckBitid ) && ( get_user_healthid ) < g_SpawnHealthid ] ) )
            {
                
set_user_healthid get_user_healthid ) + );    
            }
        }
    
        
entity_set_floatg_iRegenEntity EV_FL_nextthink , ( get_gametime() + 1.0 ) );
    }

__________________

Last edited by Bugsy; 05-23-2015 at 19:01.
Bugsy is offline
groofshark
Member
Join Date: Jul 2013
Old 05-23-2015 , 17:44   Re: Confused about using functions including "health"
Reply With Quote #6

Thank you @!Morte, thank you Bugsy - your code is everything which I want... I only made g_SpawnHealth to be checked at player's spawn with get_user_health. That was all. Thank you for helping me!
groofshark is offline
Old 05-24-2015, 06:48
HamletEagle
This message has been deleted by HamletEagle.
aron9forever
Veteran Member
Join Date: Feb 2013
Location: Rromania
Old 05-24-2015 , 08:04   Re: Confused about using functions including "health"
Reply With Quote #7

Quote:
Originally Posted by Bugsy View Post
when you call remove_task(), you do not need to check if the task exists first..it will remove it if it exists without checking first.
I'm gonna partially hijack this thread and ask, because I have task_exists before every remove_task in every plugin I've ever made

Is there no error, warning, nothing when removing a task that doesn't exist? I went with the idea that it could spout warnings like executing on non valid clients does
__________________
Meanwhile, in 2050:
Quote:
Originally Posted by aron9forever
useless small optimizations
Quote:
Originally Posted by Black Rose View Post
On a map that is 512x512x128 units you end up with 3,355,443,200,000 different "positions". To store each one of those positions individually in the variable "user_or" you need 12 terabytes of memory.
aron9forever is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-24-2015 , 09:07   Re: Confused about using functions including "health"
Reply With Quote #8

Quote:
Originally Posted by aron9forever View Post
I'm gonna partially hijack this thread and ask, because I have task_exists before every remove_task in every plugin I've ever made

Is there no error, warning, nothing when removing a task that doesn't exist? I went with the idea that it could spout warnings like executing on non valid clients does
There are no issues/errors/warnings with calling remove_task() without checking task_exists() first.
__________________
Bugsy is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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