Author Topic: Making an addon  (Read 2926 times)

Ownz

  • Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 2437
  • chmod -R 777 *
    • View Profile
    • OwnageClan
Making an addon
« on: December 21, 2010, 06:35:42 PM »
Making an addon:

Addons extend the functionality of war3source or allows you to modify war3source in some ways.

The plugin will interact with war3source through natives and forwards (+events which are forwards).

The usual is included a plugin:
Code: [Select]
#include <sourcemod>
#include "W3SIncs/War3Source_Interface"

public Plugin:myinfo =
{
    name = "War3Source - Addon - Example",
    author = "Ownz",
    description = "Example war3source addon",
    version = "1.1",
};
public OnPluginStart()
{
//your usual stuff
}

The addon usually performs some action at some event, it can be a regular sourcemod hooked event, or a forward, or a "war3source event"

War3source events are events fired by the main plugin, they are passed to a forward, so when the plugin implements it, your function is automatically called. They are same as if each event was it's own forward, such as OnRaceSelected(...) is its own forward because it is used so often.
OnWar3Event passes a number "tagged" W3EVENT, and passes a 'client' if there is any for convenience.
See constants.inc for all W3EVENT values. Not all W3EVENT are implemented (request us to implement them)
Code: [Select]
public OnWar3Event(W3EVENT:event,client)
{
  
       if(event==OnPreGiveXPGold)
       {
              //do something
       }
}
Return values in this function is ignored.

Because the number of parameters passed for each event is different, the actual variables are passed through war3 global variables (war3 global variables are the "enum W3Var" in constants.inc which are get/set by W3GetVar and W3SetVar).
Equivalent to Sourcemods's GetEventInt(event,"someparam");
Code: [Select]
new variable = W3GetVar(EventArg1);
 new variable2 = W3GetVar(EventArg2);
YOU MUST KNOW WHAT VARIABLES ARE USED FOR THE EVENT YOU USE.
Each event sets these variables before the event is actually fired. Retrieving a variable that is not used by the event could be dangerous. Which variables these events actually use depends on the implementation, the best to do is ask on the forums when it is not obvious.
Variables are not cleared after the event, so you are retrieving "garbage" if the event doesn't use that event variable.

Advanced variables may be passed by Handles / datapacks.
Code: [Select]
new Handle:variable = Handle:W3GetVar(EventArg1);
Not every event will use these extra variables, some events could use other variables such as.

Code: [Select]
TheItemBoughtOrLost,
RaceinfoRaceToShow,

Addons don't have to use OnWar3Event, they can use usual sourcemod events, or other forwards by war3source.



Now the full addon for give extra XP for medics assists in TF2
Code: [Select]

#undef REQUIRE_EXTENSIONS
#undef AUTOLOAD_EXTENSIONS
#include <tf2_stocks>

#include "W3SIncs/War3Source_Interface"  

new Handle:XPMultiplierCVar;
new Handle:GoldMultiplierCVar;

public Plugin:myinfo =
{
    name = "W3S - Addon - Additional Medic XP/Gold",
    author = "Ted Theodore Logan",
    description = "Give medics more XP and gold when they assist someone",
    version = "1.2",
};

public OnPluginStart()
{

    if(War3_GetGame() == Game_TF){
    
     XPMultiplierCVar = CreateConVar("war3_tf2_medic_xp_muli","1.0","XP multiplier when a medic assists in a kill");
     GoldMultiplierCVar = CreateConVar("war3_tf2_medic_gold_muli","1.0","Gold multiplier when a medic assists in a kill");
    }
}

public OnWar3Event(W3EVENT:event,client)
{
    if(War3_GetGame()==Game_TF)
    {
        if(event==OnPreGiveXPGold)
        {
            new W3XPAwardedBy:awardevent = W3GetVar(EventArg1);
            new xp = W3GetVar(EventArg2);
            new gold = W3GetVar(EventArg3);
            
            if((awardevent==XPAwardByAssist)&&(TF2_GetPlayerClass(client) == TFClass_Medic))
            {
                W3SetVar(EventArg2,RoundToFloor(xp * GetConVarFloat(XPMultiplierCVar)));
                W3SetVar(EventArg3,RoundToFloor(gold * GetConVarFloat(GoldMultiplierCVar)));
            }
        }
    }
}

« Last Edit: December 24, 2010, 01:23:34 PM by Ownz »

Frenzzy

  • Full Member
  • ***
  • Posts: 218
    • ICQ Messenger - 337905984
    • MSN Messenger - frenzzy@live.ru
    • View Profile
    • http://css.vsevnet.ru/
Re: Making an addon
« Reply #1 on: December 24, 2010, 09:11:03 AM »
Where can I get a full list of events and their descriptions?
O_o

Ownz

  • Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 2437
  • chmod -R 777 *
    • View Profile
    • OwnageClan
Re: Making an addon
« Reply #2 on: December 24, 2010, 01:22:29 PM »
constants.inc?

Frenzzy

  • Full Member
  • ***
  • Posts: 218
    • ICQ Messenger - 337905984
    • MSN Messenger - frenzzy@live.ru
    • View Profile
    • http://css.vsevnet.ru/
Re: Making an addon
« Reply #3 on: December 24, 2010, 01:56:43 PM »
Oh, yes, but there are no descriptions of events and information about what options are available to them.
O_o

Ownz

  • Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 2437
  • chmod -R 777 *
    • View Profile
    • OwnageClan
Re: Making an addon
« Reply #4 on: December 24, 2010, 02:05:06 PM »
search for when the event is fired