Custom addon writing: give SmokeNade on knife lvl

Ask questions and share info about GunGame 5

Custom addon writing: give SmokeNade on knife lvl

Postby Neka » Mon Jan 23, 2012 5:36 am

Hi!
Where i can get help about writing my own "custom addon"?
I wanna simply give Smoke Grenade on knife level on spawn and lvlup, and that is all!

How i see, my addon must implement 4 methods (events?): load(), unload(), lvlup() and spawn(). In the respawn() and lvlup() i simply check the player if knife level, and if true - give SmokeNade. Is this logic right? And if it's right, how to convert it inещ Python for GG5?

Thanks for answering!
Neka

Private
Private
 
Posts: 40
Joined: Thu Sep 01, 2011 4:22 am

Postby satoon101 » Mon Jan 23, 2012 3:53 pm

I have been working on a similar addon (though a lot more features to it) for quite some time. Last I tested, some parts didn't work properly, but I haven't worked on it in a few months now.

You won't probably need load or unload. You will want to use gg_levelup and player_spawn. Also, is this just for your server? If so, and knife is the last level, you will not need gg_leveldown (otherwise I would suggest using gg_leveldown for when a player levels down off of knife level).

You will need at least 3 files for your custom addon:
  • __init__.py
      Just needs to be an empty file
  • <addon name>.py
      The file that contains all of the code to run the addon
  • <addon name>_config.py
      The file that creates the server variable for the addon, which GG51 uses to know when to load/unload the addon

For the <addon name>_config.py, take a look at some of the included addons to know how to use that file. Pretty much copy/paste and replace the addon's name that you copied from with your addon's name.

Now, onto the actual file itself. Again, use gg_levelup and player_spawn to check the weapon of the player's level in those events. Use GG51's core to get the player's current level weapon:
from gungame51.core.players.shortcuts import Player

def player_spawn(event_var):
    ggPlayer = Player(event_var['userid'])
    player_weapon = ggPlayer.weapon

def gg_levelup(event_var):
    ggPlayer = Player(event_var['leveler'])
    player_weapon = ggPlayer.weapon
Then, just check to see if player_weapon equals knife to know whether they should be give a smokegrenade.

Satoon
satoon101

Site Admin
Site Admin
 
Posts: 1055
Joined: Thu Oct 09, 2008 4:27 pm

Re: Custom addon writing: give SmokeNade on knife lvl

Postby Neka » Tue Jan 24, 2012 6:51 am

There is my code at now:
# ../scripts/custom/gg_knife_bonus/gg_knife_bonus.py

# ==================================================
# IMPORTS
# ==================================================
# Python Imports


# Eventscripts Imports
import es

# GunGame Imports
from gungame51.core.players.shortcuts import Player
from gungame51.core.addons.shortcuts import AddonInfo

# ==================================================
# ADDON REGISTRATION/INFORMATION
# ==================================================
info = AddonInfo()
info.name = 'gg_knife_bonus'
info.title = 'GG Knife Bonus'
info.author = 'Neka'
info.version = '1.0'

# ==================================================
# GAME EVENTS
# ==================================================
def player_spawn(event_var):
        ggPlayer = Player(event_var[userid])
        player_weapon = ggPlayer.weapon

        if player_weapon == "knife":
                pass

def gg_levelup(event_var)
        ggPlayer = Player(event_var[leveler])
        player_weapon = ggPlayer.weapon

        if player_weapon == "knife":
                pass
 


There is a function
void ggPlayer.give(string weapon, bool ??, bool ??)
can you give me info about this funct?

And i needn't *_config.py file, i think
Neka

Private
Private
 
Posts: 40
Joined: Thu Sep 01, 2011 4:22 am

Postby satoon101 » Tue Jan 24, 2012 8:48 am

You "do" need the *_config.py file, so that GunGame knows whether to load the addon or not. That is how it is designed to work. When GunGame loads, it searches through the Included and Custom addon directories for those *_config.py files. The base cvar is added to a set of Valid Addons. When the cvar is changed on the server, the server_cvar event is fired, and GunGame checks to see whether the specific addon needs to be loaded, unloaded, or neither.

The first bool argument is whether the player should be made to "use" the weapon you are giving them or not. The second bool argument is whether to strip the player's current weapon in that slot (which is only used for primary/secondary weapons) prior to giving the player their new weapon. You will probably want both of them to be False. That is the default value for each of them, so there is no need to pass those 2 arguments.

Satoon
satoon101

Site Admin
Site Admin
 
Posts: 1055
Joined: Thu Oct 09, 2008 4:27 pm

Postby Neka » Tue Jan 24, 2012 11:25 am

Why some addons are without *_config.py file? For example, afk.

Thanks! I'll try it soon.
Neka

Private
Private
 
Posts: 40
Joined: Thu Sep 01, 2011 4:22 am

Postby satoon101 » Tue Jan 24, 2012 11:46 am

AFK is one of a few that are a little different. All AFK settings are added in via the ../gungame51/core/cfg/files/gg_afk_settings_config.py. The same goes for all the files in that directory. All of the "punishment" Included Addons are in the gg_punishment_settings_config.py. All of the "objective" Included Addons are in the gg_objectives_settings_config.py. It makes more sense to group them together like that, so that server operators can find them easier, since the cfg files they create are in the base ../cfg/gungame51/ folder instead of the ../cfg/gungame51/included_addon_configs/ folder.

Satoon
satoon101

Site Admin
Site Admin
 
Posts: 1055
Joined: Thu Oct 09, 2008 4:27 pm

Postby Neka » Wed Jan 25, 2012 3:43 am

Thank you! It works fine, my first addon written from scratch! =)
Neka

Private
Private
 
Posts: 40
Joined: Thu Sep 01, 2011 4:22 am

Re: Custom addon writing: give SmokeNade on knife lvl

Postby $upreme » Wed Apr 04, 2012 12:32 pm

Hi there,

i tried to follow the steps Neka made for writing that pluign, but: FAIL! :)

I'd like to implement smokegrenades on knifelevel too.

@NEKA or someone else: PLEASE SHARE your pluign :)
$upreme

Recruit
Recruit
 
Posts: 3
Joined: Wed Apr 04, 2012 12:05 pm
Steam Friends Name: coochy1982

Re: Custom addon writing: give SmokeNade on knife lvl

Postby Neka » Tue May 01, 2012 2:41 pm

gg_knife_bonus.zip
(3.16 KiB) Downloaded 735 times
Here it is, but knife level MUST BE the last level, because I implemented only player_respawn and gg_levelup functions. On leveldown (leveldown to knife) smokenade will not given.
Copy this directory to /eventscripts/gungame51/scripts/custom/
Neka

Private
Private
 
Posts: 40
Joined: Thu Sep 01, 2011 4:22 am

Postby satoon101 » Tue May 01, 2012 7:40 pm

You might also try using gg_knifenade, which was released just a couple weeks ago:
viewtopic.php?f=74&t=2122

Satoon
satoon101

Site Admin
Site Admin
 
Posts: 1055
Joined: Thu Oct 09, 2008 4:27 pm



Return to General Discussion

Who is online

Users browsing this forum: No registered users and 9 guests

cron