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

Half Life 1 Events: Registering, Using, and Reading them


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Rolnaaba
Veteran Member
Join Date: May 2006
Old 10-09-2006 , 11:20   Half Life 1 Events: Registering, Using, and Reading them
Reply With Quote #1

Helpful Links
Half Life 1 Events and their Data
Correct use of certain Events by: VEN

Introduction

This tutorial will cover the correct ways to register, use, and read events. It is written to address beginners new to PAWN language. So lets begin:

Part 1: Registering Events

Registering events is quite easy. Just use register_event in the plugin_init() function to make that event usable in your code.


e.x.:

Code:
#include <amxmodx> #include <amxmisc> public plugin_init() {     register_plugin("Events", "1.0", "Rolnaaba")     register_event("DeathMsg", "Death", "a", "3!0") }
when using register_event the first parameter is the event to be registered (which in this case is the “DeathMsg” event, which is called whenever anyone dies) the second is the function to be called when this even happens (which in this case is “Death”), the third parameter are the flags (which in this case is flag “a” (global event), for more information on flags check your amxmodx.inc), the fourth parameter are the restrictions. In this case the restrictions are as follows: the 3 argument (which is whether the killshot was a headshot or not), Cannot (“!”) equal “0”. (this means the kill shot must be a headshot for the function to be called upon)
Here is the code from amxmodx.inc concerning register_event:
Code:
/* Registers event on which a given function will be called
* Flags:
* "a" - global event.
* "b" - specified.
* "c" - send only once when repeated to other players.
* "d" - call if is send to dead player.
* "e" - to alive.
* Examples for conditions:
* "2=c4" - 2nd parameter of message must be sting "c4".
* "3>10" - 3rd parameter must be greater then 10.
* "3!4" - 3rd must be different from 4.
* "2&Buy" - 2nd parameter of message must contain "Buy" substring.
* "2!Buy" - 2nd parameter of message can't contain "Buy" substring. */
native register_event(const event[],const function[],const flags[],cond[]="", ... );
Part 2: Using Events

Using an event is even easier than calling it. All you do is register the event you wish to use then on the function you set, then execute what you wish to do.
Lets say you want to create a chat message (sent to everybody on the server) that says “someone has died by a headshot”

e.x.:

Code:
#include <amxmodx> #include <amxmisc> public plugin_init() {     register_plugin("Events", "1.0", "Rolnaaba")     register_event("DeathMsg", "Death", "a", "3!0") } public Death() {     client_print(0, print_chat, “Someone has died by a headshot”) }

Part 3: reading the data that event collect

Most events have special data that is collected when that event occurs in game. Lets use the “DeathMsg” event as an example. This event is called whenever someone dies. The data it collects is as follows: (1) The Killer’s ID, (2) The Victim’s ID, (3) Was Kill A Headshot or Not, (4) Weapon Name that issued the Kill. (check out “HL1 Events and their data” in the Helpful Links Section at the beginning of this tutorial for more information on all events and their data). This means we can use the read_data function to get this data.
e.x.:

Code:
#include <amxmodx> #include <amxmisc> public plugin_init() {     register_plugin("Events", "1.0", "Rolnaaba")     register_event("DeathMsg", "Death", "a", “3!0) } public Death() {     new victim = read_data(2)     client_print(victim, print_chat, “You died by a headshot”) }
This would get the ID of the person killed (new victim = read_data(2)) and print “You died by a headshot” in their chat, when the “DeathMsg” event is called. You use read_data(2) since Victim ID is the second pack of data collected during this event. If we had written:

Code:
#include <amxmodx> #include <amxmisc> public plugin_init() {     register_plugin("Events", "1.0", "Rolnaaba")     register_event("DeathMsg", "Death", "a", “3!0) } public Death() {     new victim = read_data(1)     client_print(victim, print_chat, “You died by a headshot”) }
This would have printed “You died by a headshot” in the chat of the killer’s screen since we used read_data(1) to read the first pack of data, which in this event is the killers ID, and not read_data(2) (the victims ID).
__________________
DO NOT PM me about avp mod.

Last edited by Rolnaaba; 11-01-2006 at 10:19.
Rolnaaba is offline
SweatyBanana
BANNED
Join Date: Sep 2005
Location: LOL
Old 10-11-2006 , 23:15   Re: Half Life 1 Events: Registering, Using, and Reading them
Reply With Quote #2

While I enjoy seeing the events page posted somewhere, I do not think this is really that elaborate of a helping tool.

Maybe add some more to it?

What you did is very simple.

Something like this:

PHP Code:
public plugin_init()
{
    
register_event("DeathMsg""deathEvent""be");

PHP Code:
public deathEvent(id)
{
    new 
attacker read_data(1);
    if(!
attacker)
    {
        return 
PLUGIN_HANDLED;
    }
    else
    {
        
kills[attacker]+=1;
    }
    return 
PLUGIN_CONTINUE;

May confuse most beginning scriptors.

Last edited by SweatyBanana; 10-11-2006 at 23:17.
SweatyBanana is offline
Send a message via AIM to SweatyBanana Send a message via Yahoo to SweatyBanana
Rolnaaba
Veteran Member
Join Date: May 2006
Old 10-12-2006 , 09:47   Re: Half Life 1 Events: Registering, Using, and Reading them
Reply With Quote #3

thats why this is for beginners who havent used or have no idea how to use or what they are even used for... I am currently writting a more advanced Section for more advance use of events, and I will use things like this.

Once they understand the above basic ideas, things like your code can be explained.
__________________
DO NOT PM me about avp mod.
Rolnaaba is offline
Zenith77
Veteran Member
Join Date: Aug 2005
Old 10-12-2006 , 12:57   Re: Half Life 1 Events: Registering, Using, and Reading them
Reply With Quote #4

If they don't understand the code Banana posted, then I garuntee they won't understand yours.
__________________
Quote:
Originally Posted by phorelyph View Post
your retatred
Zenith77 is offline
Rolnaaba
Veteran Member
Join Date: May 2006
Old 10-13-2006 , 09:44   Re: Half Life 1 Events: Registering, Using, and Reading them
Reply With Quote #5

if you didnt know what read_data was used for where it got its information ect. you would have no idea what banana's code does, but with basic knowledge expansion is possible
__________________
DO NOT PM me about avp mod.
Rolnaaba is offline
Zenith77
Veteran Member
Join Date: Aug 2005
Old 10-13-2006 , 12:08   Re: Half Life 1 Events: Registering, Using, and Reading them
Reply With Quote #6

You use read_data, and if anything Banana's code is less complex than yours.
__________________
Quote:
Originally Posted by phorelyph View Post
your retatred
Zenith77 is offline
SweatyBanana
BANNED
Join Date: Sep 2005
Location: LOL
Old 10-13-2006 , 16:44   Re: Half Life 1 Events: Registering, Using, and Reading them
Reply With Quote #7

I am sure that your code would look and read much better if you did the following...

1.) Quit registering your plugin..It is just more to read for someone.. If they don't know how to register a plugin, they sure as hell wont know what you are talking about.

2.) Include white space..MAKE IT READABLE.

3.) Quit using K&R style braces, this is also quite anoying when reading code..Seeing an opening brace and a closing brace is very easy on the eyes.

4.) Indent your code..

5.) Fix your messages (if you still use client_prints) to read like a normal person would understand..
SweatyBanana is offline
Send a message via AIM to SweatyBanana Send a message via Yahoo to SweatyBanana
Old 10-13-2006, 19:21
Hawk552
This message has been deleted by Hawk552.
Zenith77
Veteran Member
Join Date: Aug 2005
Old 10-13-2006 , 19:27   Re: Half Life 1 Events: Registering, Using, and Reading them
Reply With Quote #8

I used to code like that :/. But as I became more experinced I became more and more irritated at how my code looked. So one day, I switched and now it looks nice and pretty ;).
__________________
Quote:
Originally Posted by phorelyph View Post
your retatred
Zenith77 is offline
k007
BANNED
Join Date: Mar 2006
Location: bacon?
Old 10-14-2006 , 01:29   Re: Half Life 1 Events: Registering, Using, and Reading them
Reply With Quote #9

nice and pretty!
k007 is offline
Send a message via MSN to k007
SweatyBanana
BANNED
Join Date: Sep 2005
Location: LOL
Old 10-14-2006 , 01:34   Re: Half Life 1 Events: Registering, Using, and Reading them
Reply With Quote #10

k007 quit spamming.
SweatyBanana is offline
Send a message via AIM to SweatyBanana Send a message via Yahoo to SweatyBanana
Reply


Thread Tools
Display Modes

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 09:00.


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