AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   I need help with my plugin (https://forums.alliedmods.net/showthread.php?t=318472)

RayCodeCSC 09-01-2019 19:13

I need help with my plugin
 
Hi, I need help with my plugin. I have created a store in which I have a list with items such as "Power 1", "Power 2", etc.

and I need to do that when a player presses, for example, "Power 1", it sets the damage to 50.0. I'd like to do it through hamsandwich.

Originally I wanted to do this as follows:
Code:

public plugin_init()
{
        register_plugin("My first shop", "1.0", "RayCodeCSC")

        register_clcmd("say /test", "test_function")

        RegisterHam(Ham_TakeDamage, "player", "isDamaged")
}

public test_function(id)
{
        //What exactly do I write in brackets?
        isDamaged(victim, attacker, inflictor, Float:damage, damagebits)
}

public isDamaged(victim, attacker, inflictor, Float:damage, damagebits)
{
        if(get_user_weapon(attacker) == CSW_KNIFE)
        {
                SetHamParamFloat(4, damage = 30.0)
        }
}

But I can't work enough to call a function.
So the question is: How do I call a function?

When I tried it like this, it doesn't work for me:
Code:

isDamaged(victim, attacker, inflictor, Float:damage, damagebits)
So what do I write in brackets isDamaged() to make it public isDamaged()?

In a nutshell: I just want to explain how a function call works and possibly correct my code.

I apologize for my English, perhaps you'll understand what I want from you :-).

Natsheh 09-02-2019 01:21

Re: I need help with my plugin
 
What's the "damage" are you trying to change? Is It fall damage, weapon damage, etc...

Between the brackets are called parameters you have to pass digits or string depends on the parameter data type

You either can pass them as numeric values or as variables that holds a value.

As you Registered a hook to the damage event of a player through ham module and provided the callfunction which is (isDamaged), every time the player gets damaged the isDamaged function will be called.

So calling it within the plugin won't make any changes.

thEsp 09-02-2019 05:10

Re: I need help with my plugin
 
Yup, you can call those functions/hooks via ExecuteHam[B] native. For more information about ham hooks check ham_const header, which tells you how to execute or register them.

Natsheh 09-02-2019 10:00

Re: I need help with my plugin
 
Quote:

Originally Posted by thEsp (Post 2665569)
Yup, you can call those functions/hooks via ExecuteHam[B] native. For more information about ham hooks check ham_const header, which tells you how to execute or register them.

Yeah unless he used that(ExecuteHam) which I totally forgot about it.
:oops:

RayCodeCSC 09-02-2019 12:17

Re: I need help with my plugin
 
I don't understand how to use those variables. I tried it as follows and wrote these errors (when I tried to compile it)

Code:

test.sma(21) : error 088: number of arguments does not match definition
test.sma(28) : error 017: undefined symbol "damage"
test.sma(28) : warning 221: label name "float" shadows tag name
test.sma(28) : warning 215: expression has no effect
test.sma(28) : error 001: expected token: ";", but found ")"
test.sma(28) : error 029: invalid expression, assumed zero
test.sma(28) : fatal error 107: too many error messages on one line

Here's the script code:
Code:

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

new float:dmgSet = 30.0

public plugin_init()
{
        register_plugin("My first shop", "1.0", "RayCodeCSC")

        register_clcmd("say /test", "test_function")

        RegisterHam(Ham_TakeDamage, "player", "isDamaged")
}

public test_function(id)
{
        //What exactly do I write in brackets?
        isDamaged(float:dmgSet)
}

public isDamaged(victim, attacker, inflictor, float:dmgSet)
{
        if(get_user_weapon(attacker) == CSW_KNIFE)
        {
                SetHamParamFloat(4, damage * float:dmgSet)
        }
}

Can you please modify the code so that it is correct?

Natsheh 09-02-2019 12:57

Re: I need help with my plugin
 
Sorry this section is not do for me but tell me how.

RayCodeCSC 09-02-2019 13:07

Re: I need help with my plugin
 
What? I do not understand you. What am I supposed to tell you?

I just need to explain how variables work. Respectively how they are used in functions.

thEsp 09-02-2019 14:47

Re: I need help with my plugin
 
Sorry but can you be more serious please? Read carefully what I said above.

RayCodeCSC 09-02-2019 15:20

Re: I need help with my plugin
 
So I tried ExecuteHamB(), but it writes me the following errors:
Code:

test.sma(37) : error 029: invalid expression, assumed zero
test.sma(37) : warning 215: expression has no effect
test.sma(37) : error 001: expected token: ";", but found ")"
test.sma(37) : error 029: invalid expression, assumed zero
test.sma(37) : fatal error 107: too many error messages on one line

Specifically, I have the following:
Code:

ExecuteHamB(tkDamage1, victim)
script:
Code:

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

public plugin_init()
{
        register_plugin("Power Give", "1.0", "RayCodeCSC")
        register_clcmd("say /store", "store_menu")
        RegisterHam(Ham_TakeDamage, "player", "tkDamage1")
        RegisterHam(Ham_TakeDamage, "player", "tkDamage2")
}

public store_menu(id)
{
        new menu = menu_create("Choose from store:", "store_menu_selection")

        menu_additem(menu, "Power 1")
        menu_additem(menu, "Power 2")

        menu_display(id, menu)
}

public store_menu_selection(id, menu, item, victim)
{
        if(item == MENU_EXIT)
        {
                menu_destroy(menu)
                return PLUGIN_HANDLED
        }

        switch(item, victim)
        {
                case 0:
                {
                        ExecuteHamB(tkDamage1, victim)
                }

                case 1:
                {
                        ExecuteHamB(tkDamage2, victim)
                }
        }
}

public tkDamage1(victim, attacker, inflictor, Float:damage)
{
        if(get_user_flags(attacker) == ADMIN_LEVEL_A)
        {
                SetHamParamFloat(4, damage = 60.0)
        }
}

public tkDamage2(victim, attacker, inflictor, Float:damage)
{
        if(get_user_flags(attacker) == ADMIN_LEVEL_A)
        {
                SetHamParamFloat(4, damage = 120.0)
        }
}


JusTGo 09-02-2019 15:34

Re: I need help with my plugin
 
You don't need ExecuteHamB, its used only when you want to apply a custom damage for new weapon / effect, you just want to edit the current weapon damage,

First you need to create a variable to hold player power level
and then based on that level change the damage in the forward

something like this :

PHP Code:

new g_PlayerPower[MAX_PLAYERS+1]

public 
tkDamage1(victimattackerinflictorFloat:damage)
{
    if(
g_PlayerPower[attacker] == 1)
    {
        
SetHamParamFloat(450.0)
    }
    else if(
g_PlayerPower[attacker] == 2)
    {
        
SetHamParamFloat(4100.0)
    }
    
// etc ....




All times are GMT -4. The time now is 17:19.

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