thankyou
Donate to the B3 fund!

"even a small donation helps!"
Donate with PayPal!
Most of the plugins here are made by B3 users and the authors may not visit frequently. If you need support for plugins or if questions remain unanswered, you will have to contact the author directly. Read the full Support Disclaimer here

NOTE: Do not attach plugins to your forumtopics! Attachements are periodically removed by maintenance tasks. Upload your plugins to our Downloads section instead!

Author Topic: help with developping plugins for BF3  (Read 3381 times)

Offline Wright

  • Full Member
  • ***
  • Posts: 133
  • eliteclangaming.com
    • Elite Gaming
help with developping plugins for BF3
« on: November 18, 2011, 11:35:37 PM »
Okay, I am still running into some confusion. I have tried making a different plugin to do the same thing as before with vehicles, I understand that I can just use a config to do this with poweradmin but I am trying to learn more about developing for B3 and I do that best by just getting my hands dirty so I would rather make it work. Anyway, I am still having difficulty getting the self.console.write function to actually do anything useful. Has something changed in the way it works? I had a plugin that I wrote for Call of Duty 1 back in the day that used it just fine. Here is my code and the log from its use. It appears to me that B3 is just saying the commands in game as opposed to actually executing the changes. Any insight would be very much so appreciated. Our server is running infantry only most of the time however we are also using a config to allow vehicles to be turned on mid game. Since people are forgetful, admins sometimes forget to turn off the vehicles before they leave and vehicle exploits get out of hand without anyone to monitor it. Thus I decided to write this plugin to turn off vehicles at the end of each map to counter that problem.


Here is my code thus far:

Code: python [Select]
__version__ = '1.0.1'
__author__  = 'Wright'

import b3, thread, time, string
import b3
import b3.events
import b3.plugin

#--------------------------------------------------------------------------------------------------

class VehiclePlugin(b3.plugin.Plugin):
requiresConfigFile = False

def onStartup(self):
self.registerEvent(b3.events.EVT_GAME_ROUND_END)
self.debug('Ensuring vehicles get disabled after use...')

def onEvent(self, event):
if event.type == b3.events.EVT_GAME_ROUND_END:
s = self.abstractParser
self.console.write(('vars.vehicleSpawnAllowed 0'))
self.debug('Vehicles shut off.')


However when a round ends, it doesn't change the server variable. Vehicles remain on. Here is the log entry for it. I don't understand why nothing is getting changed.

Code: log [Select]
110914 13:19:07 VERBOSE 'Queueing event Game Round End 2'
110914 13:19:07 VERBOSE "Queueing event round player scores PlayerInfoBlock[{'squadId': '1', 'name': 'Elite-Kal', 'kills': '0', 'deaths': '2', 'teamId': '2', 'score': '11550', 'guid': 'EA_FB51EF2486F684ED22FC54BA60243B73'}]"
110914 13:19:07 VERBOSE 'Parsing Event: Game Round End: VehiclePlugin'
110914 13:19:07 DEBUG 'VehiclePlugin: Vehicles shut off.'
110914 13:19:07 DEBUG "getCommand: ('admin.say', '[b3] vars.vehicleSpawnAllowed 0', 'all')"
110914 13:19:07 VERBOSE u"RCON :\t ('admin.say', '[b3] vars.vehicleSpawnAllowed 0', 'all')"
110914 13:19:07 VERBOSE 'Parsing Event: round player scores: Poweradminbf3Plugin'
110914 13:19:08 CONSOLE "['player.onChat', 'Server', '[b3] vars.vehicleSpawnAllowed 0']"
110914 13:19:08 VERBOSE u'RCON response:\t []'
xfire: blitzwright

Offline Courgette

  • Senior Dev.
  • Hero Member
  • *
  • Posts: 4883
    • Github repository
Re: help with developping plugins for BF3
« Reply #1 on: November 19, 2011, 12:09:43 AM »
due to how the commands are sent to Frostbite engine, the self.console.write method works differently for games based on Frostbite engines.

usually you would send a rcon command (let say "/rcon say hello") with : self.console.write("say hello")

with Frostbite, if you want to send the 'vars.vehicleSpawnAllowed 0' command, you have to separate the command from its arguments. In this case, the command is "'vars.vehicleSpawnAllowed" and there is 1 parameter : "0".
To send this to the Frosbite engine, you use pile up the command and its parameters into a tuple or list python structure and you pass that structure to the self.console.write.

I.E.:

self.console.(['vars.vehicleSpawnAllowed', '0'])  # here we use a python list
or
self.console.(('vars.vehicleSpawnAllowed', '0'))  # and here a python tuple

What can be confusing is the way you write a tuple of one element in python.
Let say I want to get a tuple of the single element "foo", if I write
Code: python [Select]
myvar = ("foo")
type(myvar) will reply "str"

one correct way to make a tuple of one element is :
Code: python [Select]
myvar = tuple("foo")
and type(myvar) is 'tuple' as expected.

another way to get the same tuple is :
Code: python [Select]
myvar = ("foo",)
notice the comma just before closing the tuple

to sum up :
Code: python [Select]

assert type(("foo",)) == tuple
assert type(tuple("foo")) == tuple
assert type(("foo")) != tuple


I suggest you play a bit with tuple with dreampie

in your code :
Code: [Select]
self.console.write(('vars.vehicleSpawnAllowed 0'))
should be
Code: [Select]
self.console.write(('vars.vehicleSpawnAllowed', 0))

« Last Edit: November 19, 2011, 01:13:19 AM by Courgette »

Offline Wright

  • Full Member
  • ***
  • Posts: 133
  • eliteclangaming.com
    • Elite Gaming
Re: help with developping plugins for BF3
« Reply #2 on: November 19, 2011, 12:35:15 AM »
Thanks for your reply, this helps me a lot. I was quite frustrated because B3 was simply refusing to do what I wanted it to do. Now I understand why.

Is it a better practice to use the the python list or the tuple?

Sorry I posted that topic in the wrong location, I will be sure to place it here for development questions in the future.
xfire: blitzwright

Offline Courgette

  • Senior Dev.
  • Hero Member
  • *
  • Posts: 4883
    • Github repository
Re: help with developping plugins for BF3
« Reply #3 on: November 19, 2011, 01:11:23 AM »
Is it a better practice to use the the python list or the tuple?
My understanding is that tuples are faster than lists because they are immutable objects (hence are read-only object once created)

In that particular case it does not make any difference because we're not using thousands of them per second. I should probably have used lists to avoid confusion with plugin dev and the "strange" syntax for writing a single item tuple.

Offline Wright

  • Full Member
  • ***
  • Posts: 133
  • eliteclangaming.com
    • Elite Gaming
Re: help with developping plugins for BF3
« Reply #4 on: November 19, 2011, 06:31:25 AM »
Thanks for the explanation, I am sure I will have more questions in the future as I continue to refine my skills.
xfire: blitzwright

 


Rate this page +1 at Google Search

anything