AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [Ham Sandwich] Ham_TakeDamage Function (https://forums.alliedmods.net/showthread.php?t=192521)

Infinity 08-11-2012 02:04

[Ham Sandwich] Ham_TakeDamage Function
 
Here's a modified part of my code:
PHP Code:

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

public plugin_init(){
RegisterHam(Ham_TakeDamage"player""OnPlayerEvent_Damage"1);
}

public 
OnPlayerEvent_Damage(victimcauseattacker1.0){
SOME CODE HERE


I want the code to execute when AT LEAST 1 damage is taken/given but when I try compiling I get the following error:
<47> : error 010: invalid function or declaration
*Line 47 is where the public function "OnPlayerEvent_Damage" is

I read this and I appear to have followed the function format:
http://www.amxmodx.org/funcwiki.php?go=module&id=24

but I'm getting an error for some odd reason.

fysiks 08-11-2012 02:31

Re: [Ham Sandwich] Ham_TakeDamage Function
 
Why do you have a 1.0 in your function declaration? That doesn't even make any sense. You can't have random numbers in a function declaration. You need to follow the forward format for Ham_TakeDamage in ham_const.inc.

GordonFreeman (RU) 08-11-2012 02:36

Re: [Ham Sandwich] Ham_TakeDamage Function
 
Try this:

Code:
#include <amxmodx> #include <hamsandwich> public plugin_init(){     RegisterHam(Ham_TakeDamage, "player", "OnPlayerEvent_Damage"); } public OnPlayerEvent_Damage(this, idinflictor, idattacker, Float:damage, damagebits){     SetHamParamFloat(3,1.0) }

fysiks 08-11-2012 02:41

Re: [Ham Sandwich] Ham_TakeDamage Function
 
Quote:

Originally Posted by GordonFreeman (RU) (Post 1769029)
Try this:

Code:
#include <amxmodx> #include <hamsandwich> public plugin_init(){     RegisterHam(Ham_TakeDamage, "player", "OnPlayerEvent_Damage"); } public OnPlayerEvent_Damage(this, idinflictor, idattacker, Float:damage, damagebits){     SetHamParamFloat(3,1.0) }

He doesn't want to change the damage to 1.0. He wants to execute code when the damage is 1.0 or greater:

PHP Code:

if( damage 1.0 )
{
    
// do stuff



Infinity 08-11-2012 02:47

Re: [Ham Sandwich] Ham_TakeDamage Function
 
Quote:

Originally Posted by fysiks (Post 1769026)
Why do you have a 1.0 in your function declaration? That doesn't even make any sense. You can't have random numbers in a function declaration. You need to follow the forward format for Ham_TakeDamage in ham_const.inc.

Because I read in the Ham Sandwich docs this:
function(this, idinflictor, idattacker, Float:damage, damagebits)

So I thought I would replace the function with:
Function(victim, cause, attacker, 1.0, damagebits)

Emp` 08-11-2012 03:54

Re: [Ham Sandwich] Ham_TakeDamage Function
 
Quote:

Originally Posted by Infinity (Post 1769034)
Because I read in the Ham Sandwich docs this:
function(this, idinflictor, idattacker, Float:damage, damagebits)

So I thought I would replace the function with:
Function(victim, cause, attacker, 1.0, damagebits)

Function headers are used to just declare parameters passed to the function. If you want to change how a function is called, either play with the native that calls the function or place code within the function to only execute when certain conditions are met (see fysiks' post).

Infinity 08-11-2012 23:44

Re: [Ham Sandwich] Ham_TakeDamage Function
 
Quote:

Originally Posted by fysiks (Post 1769032)
He doesn't want to change the damage to 1.0. He wants to execute code when the damage is 1.0 or greater:

PHP Code:

if( damage 1.0 )
{
    
// do stuff



The if still triggers when I shoot a teammate or if a teammate shoots me, here's a part of my code:
PHP Code:

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

public register_init(){
    
RegisterHam(Ham_TakeDamage"player""OnPlayerEvent_Damage"1);
}


public 
OnPlayerEvent_Damage(victiminflictorattackerFloat:damagedamagebits){
    if(
damage 1.0){
        
set_user_camo(victimfalse);
        
set_user_camo(attackerfalse);
        }



fysiks 08-12-2012 00:42

Re: [Ham Sandwich] Ham_TakeDamage Function
 
Quote:

Originally Posted by Infinity (Post 1769664)
The if still triggers when I shoot a teammate or if a teammate shoots me, here's a part of my code:
PHP Code:

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

public register_init(){
    
RegisterHam(Ham_TakeDamage"player""OnPlayerEvent_Damage"1);
}


public 
OnPlayerEvent_Damage(victiminflictorattackerFloat:damagedamagebits){
    if(
damage 1.0){
        
set_user_camo(victimfalse);
        
set_user_camo(attackerfalse);
        }



Well, that sounds logical to me. Why would it not trigger when you shoot someone? Do you have a gun that does 0.5 damage? No.

Infinity 08-12-2012 01:06

Re: [Ham Sandwich] Ham_TakeDamage Function
 
Quote:

Originally Posted by fysiks (Post 1769679)
Well, that sounds logical to me. Why would it not trigger when you shoot someone? Do you have a gun that does 0.5 damage? No.

Yes, but when you get shot by a teammate you receive 0 damage. I don't want the code to execute when you get shot by a teammate while FF is off.

fysiks 08-12-2012 01:28

Re: [Ham Sandwich] Ham_TakeDamage Function
 
Quote:

Originally Posted by Infinity (Post 1769685)
Yes, but when you get shot by a teammate you receive 0 damage. I don't want the code to execute when you get shot by a teammate while FF is off.

Well, you failed to mention that part. What is the value of damage?


All times are GMT -4. The time now is 05:52.

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