Archived copy of war3source.com, the War3Source forum (2009–2020), rebuilt from the Internet Archive by wc3mods.net. This page was captured on 2012-09-22 (original capture). Forum · All archived topics · Wiki · Bug tracker · Blog
Chat

War3:Source
September 21, 2012, 10:32:26 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Download: http://war3source.com/index.php?board=9.0
What is War3Source?: http://war3source.com/index.php?topic=200.0
Sample Stats: http://war3source.com/war3stats
Steam Community Group: http://steamcommunity.com/groups/war3source
War3Source SVN Checkout: http://ownageclan.com/svn/war3source/
War3Source servers: http://www.game-monitor.com/search.php?vars=war3_version=
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Making an addon  (Read 877 times)
Ownz
Developer
Administrator
Hero Member
*****
Posts: 2032



View Profile WWW Email
« 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:
#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:
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:
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:
new Handle:variable = Handle:W3GetVar(EventArg1);

Not every event will use these extra variables, some events could use other variables such as.

Code:
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:

#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 » Logged

DarkEnergy
Frenzzy
Full Member
***
Posts: 217


337905984 frenzzy@live.ru
View Profile WWW
« Reply #1 on: December 24, 2010, 09:11:03 AM »

Where can I get a full list of events and their descriptions?
Logged

O_o
Ownz
Developer
Administrator
Hero Member
*****
Posts: 2032



View Profile WWW Email
« Reply #2 on: December 24, 2010, 01:22:29 PM »

constants.inc?
Logged

DarkEnergy
Frenzzy
Full Member
***
Posts: 217


337905984 frenzzy@live.ru
View Profile WWW
« 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.
Logged

O_o
Ownz
Developer
Administrator
Hero Member
*****
Posts: 2032



View Profile WWW Email
« Reply #4 on: December 24, 2010, 02:05:06 PM »

search for when the event is fired
Logged

DarkEnergy
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!