AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [HOW TO] Frag count (https://forums.alliedmods.net/showthread.php?t=189853)

recimo 07-11-2012 18:56

[HOW TO] Frag count
 
I searched and i found something, but not exactly what i need. I tried to improvise and when i compile code it register these warnings:
/tmp/textQvOx9E.sma(8) : error 017: undefined symbol "register_plugin"
/tmp/textQvOx9E.sma(8) : warning 215: expression has no effect
/tmp/textQvOx9E.sma(8) : warning 215: expression has no effect
/tmp/textQvOx9E.sma(8) : error 001: expected token: ";", but found ")"
/tmp/textQvOx9E.sma(8) : error 029: invalid expression, assumed zero

Im learning pawn. So, for practise Im trying to make plugin which will count user frags/kills. If number of frags/kills isn't bigger than 5 plugin will stop further action and if is opposite, hud message will be activated.

This is code:
Code:

#include <amxmodx>

#define PLUGIN "Test123"
#define VERSION "1.0"
#define AUTHOR "recimo"

new numfrags[17]

public plugin_init()
{
        register_plugin(PLUGIN, VERSION, AUTHOR)
        register_event("DeathMsg", "num_of_frags", "a")
}
public num_of_frags(id)
{
        numfrags[id] = get_user_frags(id)
        numfrags[id]++
        if(!get_user_frags(id) > 5)
        {
        return PLUGIN_HANDLED
        }
        else (!get_user_frags(id) < 5)
        {
        set_hudmessage ( 150, 120, 30, -2.0, 0.45, 0, 6.0, 100.0, 0.1, 0.2, 4)
        show_hudmessage(id, "YOU ARE NOOB!")
        return PLUGIN_CONTINUE
        }
}

Im hoping that someone will tell me where im wrong and how to make it right. :)

fysiks 07-11-2012 19:06

Re: [HOW TO] Frag count
 
1. It looks like you are not using correct include files.
2. I didn't get any of the errors you had. Only different ones.
3. Your global array is too small.
4. Your global array is never used.
5. There is no point to adding one to a variable that is set immediately before it.
6. For the other advice, I will suggest you see how I would do it:

PHP Code:

#include <amxmodx>

public plugin_init() 
{
    
register_plugin("Test123""1.0""recimo")
    
register_event("DeathMsg""num_of_frags""a")
}
public 
num_of_frags(id)
{
    if( 
get_user_frags(id) > )
    {
        
set_hudmessage 15012030, -2.00.4506.0100.00.10.24)
        
show_hudmessage(id"YOU ARE NOOB!")
    }



recimo 07-11-2012 19:17

Re: [HOW TO] Frag count
 
Tnx. I think i understand.
What if i want to make plugin. For example: I want to plugin check something and if statement isnt met, plugin will stop. If statement is met, plugin will continue with further action.
Something like this:
Code:

if(test1 != test2)
{
plugin stops
}
if(test5 == test 6)
{
// do something
}

Edit: I tested your code and its not working. amx_plugins says its running, but hud message wasn't s activated (it didn't show on screen).

fysiks 07-11-2012 23:12

Re: [HOW TO] Frag count
 
Quote:

Originally Posted by recimo (Post 1748367)
Tnx. I think i understand.
What if i want to make plugin. For example: I want to plugin check something and if statement isnt met, plugin will stop. If statement is met, plugin will continue with further action.
Something like this:
Code:

if(test1 != test2)
{
plugin stops
}
if(test5 == test 6)
{
// do something
}


You can't "stop" the plugin. You simply just don't do anything if the condition is not met.

Quote:

Originally Posted by recimo (Post 1748367)
Edit: I tested your code and its not working. amx_plugins says its running, but hud message wasn't s activated (it didn't show on screen).

I didn't check to see if the event was registered correctly nor did I check the hud message stuff because I rarely do stuff with HUD messages. The first thing you need to do is check if the function is actually being executed.

Bugsy 07-11-2012 23:22

Re: [HOW TO] Frag count
 
The players id is not passed to the DeathMsg forward that way. If you need to, you can also determine if the kill was via headshot and you can get the weapon used.
PHP Code:

register_event"DeathMsg" "fw_EvDeathMsg" "a" "1>0" ); 

public 
fw_EvDeathMsg()
{
    new 
iKiller read_data);
    new 
iVictim read_data);



Instead of two separate statements you can do this in one.
PHP Code:

numfrags[id] = get_user_frags(id)
numfrags[id]++
...
numfrags[id] = get_user_frags(id) + 

If you are checking a condition and also using the opposite result, then just use "else" with no condition.
PHP Code:

if(!get_user_frags(id) > 5)
else (!
get_user_frags(id) < 5)
...
if( 
get_user_frags(id) > 5
    
//has more than 5 frags
else
   
//has less than 5 frags 

Using if ( !get_user_frags(id) > 5 ) will give you an inaccurate result. !get_user_frags(id) will return whether or not the function value is zero; it'll return 1 if player has 0 frags, and 0 if non-zero frags.
PHP Code:

Player has 5 frags
if( 5)

Player has -10 frags
if( 5)

Player has 0 frags
if( 5

To properly use the statement that way, you need to enclose the entire condition in parenthesis then use ! on it.
PHP Code:

if ( !( get_user_frags(id) > ) ) 



All times are GMT -4. The time now is 15:21.

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