AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Coding Help (https://forums.alliedmods.net/showthread.php?t=62895)

Stars 11-06-2007 21:59

Coding Help
 
Okay, basically what i want to do, is make a plugin that runs when you take any damage.

What happens is... based on the damage taken, and your health after the damage, you will bleed for a certain time, or heal for a certain time...

Its quite simple, and Pawn is very easy to understand... im just having a lot of trouble linking in the HL commands.... such as:
-Starting a function when damage is taken
-Pauses in code (wait 1 second)
-Knowing Damage taken
-Knowing current hp
-and so on

(I first decided to look into AMX Mod X Scripting yesterday, so be nice)

I designed it below in Java, to help.







int HP;
int time;
int damage_taken;

public Bleed_Heal(int HP, damage_taken)
{
int dam_mult;

if (damage_taken > 75)
dam_mult = 2;

else if (damage_taken < 25)
dam_mult = 4;

else
dam_mult = 3;
if (50-HP > 0 )
{
time = (3(50-HP))

while (time > 0)
{
if (time%dam_mult == 0)
{
HP--;
}
wait 1 second;
time--;
}
}

else
{
time = (3(50-(100-HP)))
while (time > 0)
{
if (time%dam_mult == 0)
{
HP++;
}
wait 1 second;
time--;
}
}
}

hlstriker 11-06-2007 22:20

Re: Coding Help
 
Quote:

Originally Posted by Stars (Post 550297)
-Starting a function when damage is taken

register_event("Damage", "hook_Damage", "be", "2>0");

Quote:

Originally Posted by Stars (Post 550297)
-Knowing Damage taken

The 2nd argument of the damage message you are hooking above.

Quote:

Originally Posted by Stars (Post 550297)
-Pauses in code (wait 1 second)

set_task(1.0, "function_to_start");

Quote:

Originally Posted by Stars (Post 550297)
-Knowing current hp

new health = pev(id, pev_health);

Stars 11-06-2007 23:02

Re: Coding Help
 
Thankyou, but im still confused...

How do i implement this?
register_event("Damage", "hook_Damage", "be", "2>0");

Arkshine 11-07-2007 00:12

Re: Coding Help
 
Insert in plugin_init() function.

hlstriker 11-07-2007 00:13

Re: Coding Help
 
This is not tested but I'm pretty sure it should work.

PHP Code:

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR);
    
register_event("Damage""hook_Damage""be""2>0");
}

public 
hook_Damage(id)
{
    new 
damage read_data(2);
    new 
name[32];
    
    
get_user_name(idname31);
    
client_print(0print_chat"%s took %i damage."namedamage);



Stars 11-07-2007 02:01

Re: Coding Help
 
how would i make someone squirt out a little bit of blood.

Stars 11-07-2007 02:04

Re: Coding Help
 
moreso just drip blood to the ground below them, rather than squirt.

Stars 11-07-2007 02:08

Re: Coding Help
 
Quote:

Originally Posted by hlstriker (Post 550328)
This is not tested but I'm pretty sure it should work.

PHP Code:

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR);
    
register_event("Damage""hook_Damage""be""2>0");
}

public 
hook_Damage(id)
{
    new 
damage read_data(2);
    new 
name[32];
    
    
get_user_name(idname31);
    
client_print(0print_chat"%s took %i damage."namedamage);




PS, thanks that was really useful.

Stars 11-07-2007 02:21

Re: Coding Help
 
set_task(1.0, "function_to_start");


Does this literally just pause for one second?

Or does it go back to the start of the function in 1 second?

purple_pixie 11-07-2007 05:30

Re: Coding Help
 
It will go to that function in 1 second

Pausing wouldn't be too useful in embedded code :D


All times are GMT -4. The time now is 01:16.

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