Skip to content

Examples

Filip Tomaszewski edited this page Sep 28, 2018 · 2 revisions

Contents

Perk registration and callback ^

public void OnPluginStart(){
    if(RTD2_IsRegOpen())
        RegisterPerk();
}

public void OnPluginEnd(){
    RTD2_DisableModulePerks();
}

public void RTD2_OnRegOpen(){
    RegisterPerk();
}

void RegisterPerk(){
    RTD2_ObtainPerk("mytoken")
        .SetName("My Perk Name")
        .SetGood(true)
        .SetSound("path/to/activation/sound.mp3")
        .SetClasses("2, 3, 5")
        .SetWeaponClasses("shotgun")
        .SetTags("soldier, pyro, heavy, shotgun, good")
        .SetPref("damage", "2")
        .SetCall(MyPerk_Call);
}

public void MyPerk_Call(int client, RTDPerk perk, bool bEnable){
    if(bEnable)
        PrintToChat(client, "Your shotgun damage was increased by %.2f!", perk.GetPrefFloat("damage"));
    else
        PrintToChat(client, "Your shotgun damage was set back to normal.");
}

Perk registration and callback with comments ^

public void OnPluginStart(){
    if(RTD2_IsRegOpen())
        RegisterPerk(); // if module was late-loaded, register our perk
}

public void OnPluginEnd(){
    RTD2_DisableModulePerks(); // ensures custom perks will be called for deactivation, in case this module unloads
}

public void RTD2_OnRegOpen(){
    RegisterPerk(); // Core plugin fully initialized or perks were refetched, register our perk
}

void RegisterPerk(){
    RTD2_ObtainPerk("mytoken") // create perk using unique token "mytoken"
        .SetName("My Perk Name") // set perk's name
        .SetGood(true) // make the perk good
        .SetSound("path/to/activation/sound.mp3") // set activation sound
        .SetClasses("2, 3, 5") // make the perk applicable only to Soldier, Pyro and Heavy
        .SetWeaponClasses("shotgun") // make the perk applicable only to clients holding a shotgun
        .SetTags("soldier, pyro, heavy, shotgun, good") // set perk's search tags
        .SetPref("damage", "2") // set some custom settings
        .SetCall(MyPerk_Call); // set which function should be called for activation/deactivation
}

public void MyPerk_Call(int client, RTDPerk perk, bool bEnable){
    if(bEnable)
        PrintToChat(client, "Your shotgun damage was increased by %.2f!", perk.GetPrefFloat("damage"));
    else
        PrintToChat(client, "Your shotgun damage was set back to normal.");
}