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

Code not working, simple


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
joeyeyey
Junior Member
Join Date: Jun 2015
Location: Sweden
Old 06-20-2015 , 19:29   Code not working, simple
Reply With Quote #1

Hey! I am new to plugincoding. This plugin does its work, in the chat atleast. The actual damage is not reducted. I know there are plugins done for this already. But I am trying to learn. What am I doing wrong? Since the compiling works fine. Thanks in advance!
(It is for CS:GO)

PHP Code:
#include <sourcemod>
#include <sdkhooks>
#include <sdktools>

public OnPluginStart() {
    
HookEvent("player_falldamage"Event_PlayerFallDamageEventHookMode_Pre);
}

public 
Action:Event_PlayerFallDamage(Handle:hEvent, const String:sName[], bool:bDontBroadcast) {
    new 
damage GetEventInt(hEvent"damage");
    
PrintToChatAll("Damage taken from fall BEFORE reduction: %i"damage);
    
damage -= 10;
    
SetEventInt(hEvent"damage"damage); // Should not be neccesary right?
    
PrintToChatAll("Damage taken from fall: %i"damage);
    return 
Plugin_Changed;

joeyeyey is offline
Darkness_
Veteran Member
Join Date: Nov 2014
Old 06-20-2015 , 19:35   Re: Code not working, simple
Reply With Quote #2

You need to use SDKHook_OnTakeDamage. If the damagetype is DMG_FALL (1 << 5) then get the damage and reduce it by 10 like you did above and return Plugin_Changed.
Darkness_ is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 06-20-2015 , 20:28   Re: Code not working, simple
Reply With Quote #3

PHP Code:
#include <sourcemod>
#include <sdkhooks>

public void OnMapStart()
{
    for (
int i 1<= MaxClientsi++)
    {
        if (
IsClientInGame(i))
            
SDKHook(iSDKHook_OnTakeDamageOnTakeDamage);
    }
}

public 
void OnClientPutInServer(int client)
{
    
SDKHook(clientSDKHook_OnTakeDamageOnTakeDamage);
}

public 
Action OnTakeDamage(int victimint &attackerint &inflictorfloat &damageint &damagetypeint &weaponfloat damageForce[3], float damagePosition[3], int damagecustom)
{
    if (
damagetype DMG_FALL)
    {
        
damage -= 10.0;
        return 
Plugin_Changed;
    }
    return 
Plugin_Continue;

__________________

Last edited by WildCard65; 06-21-2015 at 14:01.
WildCard65 is offline
Impact123
Veteran Member
Join Date: Oct 2011
Location: Germany
Old 06-21-2015 , 09:19   Re: Code not working, simple
Reply With Quote #4

@joeyeyey
The reason you need to use SDKHooks is because an event hook is usually called after something happens. You can block the event, but not what triggered it.

@WildCard65
You should hook clients that join during the game.
__________________

Last edited by Impact123; 06-21-2015 at 17:48.
Impact123 is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 06-21-2015 , 14:01   Re: Code not working, simple
Reply With Quote #5

Quote:
Originally Posted by Impact123 View Post
@WildCard65
You should hook clients that join during the game.
Forgot.
__________________
WildCard65 is offline
joeyeyey
Junior Member
Join Date: Jun 2015
Location: Sweden
Old 06-22-2015 , 08:27   Re: Code not working, simple
Reply With Quote #6

Quote:
Originally Posted by Impact123 View Post
@joeyeyey
The reason you need to use SDKHooks is because an event hook is usually called after something happens. You can block the event, but not what triggered it.

@WildCard65
You should hook clients that join during the game.
Thanks man!
joeyeyey 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 00:01.


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