Jump to content
Korean Random
pipje2001

some questions about modmaking

Recommended Posts

I just started trying to make my own mod, but i have absolutely no experience with modding for any game. I do know the basics of python so that shouldn't be a big problem. So far i tried to follow this short tutorial https://bitbucket.org/_vb_/wot.mods/wiki/GettingStarted with the help of google translate.

 

# -*- coding: utf-8-sig -*-

import BigWorld
from gui import SystemMessages
from Account import Account

#file for using philips hue in python
from mod_phue import Bridge

#some stuff needed for philips hue
b = Bridge('192.168.1.101')
listOfLight = b.lights

def hello(self):

    parent(self)

    SystemMessages.pushMessage('Hello WoT!', type=SystemMessages.SM_TYPE.Warning)

    #sets the ligt red
    b.set_light(4, 'xy', [0.1938, 0.6821], transitiontime=10)
    b.set_light(5, 'xy', [0.1938, 0.6821], transitiontime=10)

    #sets the ligt on max brightness
    b.set_light(4, 'bri', 254, transitiontime=10)
    b.set_light(5, 'bri', 254, transitiontime=10)
    
    Account.onBecomePlayer = parent


parent = Account.onBecomePlayer

Account.onBecomePlayer = hello

with some modifications i got the lights to change to red and on max brightness, so it is possible to control the lights with a mod, but i am trying to make the lights flash when i get hit. But i guess i have to use onHealthChanged but i have no idea how.

 

If somebody could help me it would be appreciated

Share this post


Link to post

Short link
Share on other sites
1 hour ago, pipje2001 said:

But i guess i have to use onHealthChanged but i have no idea how.

Like this:

from Vehicle import Vehicle
from random import randint
from time import sleep

def _set_brightness(value):
    b.set_light(4, 'bri', value, transitiontime=10)
    b.set_light(5, 'bri', value, transitiontime=10)

def new_onHealthChanged(self, newHealth, attackerID, attackReasonID):
    old_onHealthChanged(self, newHealth, attackerID, attackReasonID)
    
    if not self.isPlayerVehicle:
        return
    
    #make light randomly flashes for 10 times
    for _ in range(10):
        _set_brightness(randint(0, 254))
        sleep(0.1)
    
    #restore brightness to default
    _set_brightness(254)

old_onHealthChanged = Vehicle.onHealthChanged
Vehicle.onHealthChanged = new_onHealthChanged

 

Edited by Kotyarko_O

Share this post


Link to post

Short link
Share on other sites

@Kotyarko_O Awesome, that really helped me, although i still have some more questions though. is it possible to get the currunt hp and max hp of the tank you are playing at that moment? and is there somewhere where i can find information about an ingame settings window for my own mod? like some populair mods have?

Share this post


Link to post

Short link
Share on other sites
29 minutes ago, pipje2001 said:

is it possible to get the currunt hp and max hp of the tank you are playing at that moment?

Sure:

from BigWorld import player
from PlayerEvents import g_playerEvents
from Vehicle import Vehicle

maxHp = None
curHp = None

def setMaxHp():
    global maxHp
    plVeh = player().getVehicleAttached()
    maxHp = plVeh.typeDescriptor.maxHealth

def new_onHealthChanged(self, newHealth, attackerID, attackReasonID):
    old_onHealthChanged(self, newHealth, attackerID, attackReasonID)
    
    if not self.isPlayerVehicle:
        return
    
    global curHp
    curHp = newHealth

def reset():
    global maxHp, curHp
    maxHp = None
    curHp = None

g_playerEvents.onAvatarBecomePlayer += setMaxHp
#
old_onHealthChanged = Vehicle.onHealthChanged
Vehicle.onHealthChanged = new_onHealthChanged
#
g_playerEvents.onAvatarBecomeNonPlayer += reset

May be mistakes\errors, didn`t test it.

 

29 minutes ago, pipje2001 said:

is there somewhere where i can find information about an ingame settings window for my own mod? like some populair mods have?

https://bitbucket.org/P0LIR0ID/wot-modslist/src/master/

https://bitbucket.org/The_IzeBerg/modssettingsapi/src/master/ (https://kr.cm/f/t/48259/)

https://kr.cm/f/t/25477/c/279913/

 

Almost all of this utils have only russian description, unfortunasdljsklfjdfkh (can`t remember all letters in this word).

Edited by Kotyarko_O

Share this post


Link to post

Short link
Share on other sites

I looked trough the links you send but i dont understand shit about how it works XD, for example if i want to set the ip of the bridge in the game.

b = Bridge('192.168.1.101')

what would i need to make this possible?

 

And how do you get the playerid of the player which i am playing with? never mind already found it (BigWorld.player().playerVehicleID)

Edited by pipje2001

Share this post


Link to post

Short link
Share on other sites

@Kotyarko_O  the code you send doesn't seem to be working, although i changed some of it i can't find what is wrong

import BigWorld
from PlayerEvents import g_playerEvents
from Vehicle import Vehicle
from random import randint
import time
import threading

#file for using philips hue in python
from mod_phue import Bridge

#some stuff needed for philips hue
b = Bridge('192.168.1.101')
listOfLight = b.lights

maxHp = None
curHp = None

def DamageRecievedSmall():
    b.set_light(4, 'xy', [0.678, 0.3168], transitiontime=0)
    b.set_light(4, 'bri', 254, transitiontime=0)
    
    time.sleep(0.2)

    b.set_light(4, 'bri', 0, transitiontime=3)

    print("DRS_Done")

def DamageRecievedLarge():
    b.set_light(4, 'xy', [0.678, 0.3168], transitiontime=0)
    b.set_light(4, 'bri', 254, transitiontime=0)
    
    time.sleep(0.6)

    b.set_light(4, 'bri', 0, transitiontime=3)

    print("DRL_Done")

def setMaxHp():
    global maxHp
    plVeh = BigWorld.player().getVehicleAttached()
    maxHp = plVeh.typeDescriptor.maxHealth



def new_onHealthChanged(self, newHealth, attackerID, attackReasonID):
    old_onHealthChanged(self, newHealth, attackerID, attackReasonID)

    print(attackerID)
    print(attackReasonID)
    print(BigWorld.player().playerVehicleID)

    if not self.isPlayerVehicle:
        if attackerID != BigWorld.player().playerVehicleID:
            return
    
    global curHp
    curHp = newHealth

    # if attackerID == BigWorld.player().playerVehicleID:
    #     t3 = threading.Thread(target=hue3)
    #     t4 = threading.Thread(target=hue4)

    #     if t3.isAlive()==False:
    #         print("hue3start")
    #         t3.start()
    #     if t4.isAlive()==False:
    #         print("hue4start")
    #         t4.start()
    
    if attackerID != BigWorld.player().playerVehicleID:

        if curHp/maxHp <= 0.2:
            DRS = threading.Thread(target=DamageRecievedSmall)
            if DRS.isAlive()==False:
                DRS.start()
                print("DRS_Start")
        if curHp/maxHp > 0.2:
            DRL = threading.Thread(target=DamageRecievedLarge)
            if DRL.isAlive()==False:
                DRL.start()
                print("DRL_Start")

def reset():
    global maxHp, curHp
    maxHp = None
    curHp = None

g_playerEvents.onAvatarBecomePlayer += setMaxHp

old_onHealthChanged = Vehicle.onHealthChanged
Vehicle.onHealthChanged = new_onHealthChanged

g_playerEvents.onAvatarBecomeNonPlayer += reset

 

Share this post


Link to post

Short link
Share on other sites

@Kotyarko_Oo i see i forgot to add them

 

Traceback (most recent call last):
  File "scripts/common/Event.py", line 44, in __call__
  File "mod_hello", line 40, in setMaxHp
  File "scripts/client/avatar_components/AvatarObserver.py", line 260, in getVehicleAttached
AttributeError: 'PlayerAvatar' object has no attribute 'playerVehicleID'
 

Share this post


Link to post

Short link
Share on other sites
14 minutes ago, pipje2001 said:

AttributeError: 'PlayerAvatar' object has no attribute 'playerVehicleID'

My bad. Try to use "onAvatarReady" instead of "onAvatarBecomePlayer".

Share this post


Link to post

Short link
Share on other sites
3 minutes ago, pipje2001 said:

onAvatarBecomeNonPlayer

It`s ok. This is "leave battle" event.

Share this post


Link to post

Short link
Share on other sites

@Kotyarko_O Awesome, i got one more problem though, i try to run this code in a loop:

def LowHp():
    while curHp > 0:
        b.set_light(1, 'xy', [0.678, 0.3168], transitiontime=0)
        b.set_light(1, 'bri', 254, transitiontime=10)

        time.sleep(1)

        b.set_light(1, 'bri', 0, transitiontime=10)

        time.sleep(1)
    
    print("LH_Done")

But i only want this function to run once at a time so i use this method to check if the tread is already running but it "forgets" that its running so the next time i get shot it just runs it again which kinda breaks my lights XD

 

if fcurHp/fmaxHp <= 0.1:
	LH = threading.Thread(target=LowHp)
	print(LH.is_alive())
	if not LH.is_alive():
    	LH.start()
    	print("LH_Start")

 

mod_hello.py

Share this post


Link to post

Short link
Share on other sites
11 hours ago, pipje2001 said:

But i only want this function to run once at a time so i use this method to check if the tread is already running but it "forgets" that its running so the next time i get shot it just runs it again which kinda breaks my lights XD

Because every time you get damaged in this condition (fcurHp/fmaxHp <= 0.1), you create another thread and checks it.

First of all, "LH" must be a global var. So the code must be like:

LH = None

...

if fcurHp/fmaxHp <= 0.1:
    global LH
    if not (LH and LH.is_alive()):
        LH = threading.Thread(target=LowHp)
        LH.start()
        print("LH_Start")

 

Edited by Kotyarko_O

Share this post


Link to post

Short link
Share on other sites

@Kotyarko_O Thanks, that did the trick, do you mind if i ask you some more questions? 

- how do you know if the tank is on fire?

- how do you know if modules are hit? and which module is hit?

- and how can you make a settings window in the game?

 

I tried to search for answers but because most stuff is in russian searching is kinda difficult  

Share this post


Link to post

Short link
Share on other sites
1 hour ago, pipje2001 said:

- how do you know if the tank is on fire?

from gui.Scaleform.daapi.view.meta.DamagePanelMeta import DamagePanelMeta

isVehInFire = False

old_setFireInVehicleS = DamagePanelMeta.as_setFireInVehicleS

def new_setFireInVehicleS(self, isInFire):
    global isVehInFire
    isVehInFire = isInFire

DamagePanelMeta.as_setFireInVehicleS = new_setFireInVehicleS

 

2 hours ago, pipje2001 said:

- how do you know if modules are hit? and which module is hit?

Example: https://bitbucket.org/Kotyarko_O/xvm.py_macro/src/19fbaa0b1c298ccc87bd20a2b0dfce320ef981e4/repairControl/repairControl.py#lines-260

 

2 hours ago, pipje2001 said:

- and how can you make a settings window in the game?

Guide: https://kr.cm/f/t/25477/c/279913/ (a bit outdated).

Example: https://bitbucket.org/Kotyarko_O/modpack_updatesannouncer-moder/src/master/

Share this post


Link to post

Short link
Share on other sites

@Kotyarko_O I tried using https://bitbucket.org/The_IzeBerg/modssettingsapi/src and https://bitbucket.org/P0LIR0ID/wot-modslist/src/ce1e5c1d2662?at=master, but i can't find where the settings are saved and how is can access them from my own mod...  

for example i want to be able to set the ip adress of the hub in the settings menu, but i have no idea how

mod_hello.py

mod_modsettings.py

Edited by pipje2001
added some files

Share this post


Link to post

Short link
Share on other sites

@Kotyarko_O still don't understand it though, how do i get the value from the textinput into my own mod? and how can i run a function in my mod when i press apply in the settings menu?

Share this post


Link to post

Short link
Share on other sites
8 minutes ago, pipje2001 said:

how do i get the value from the textinput into my own mod? and how can i run a function in my mod when i press apply in the settings menu?

When apply button pressed, event "onModSettingsChanged" is performed. In thatfunction you can do what you need to do. For example:

def onModSettingsChanged(linkage, newSettings):    
    if linkage == modLinkage:
        setNewSettings(newSettings)

def setNewSettings(settings):
    print settings['textInput']

I`m not sure that "settings['textInput']" is correct. You need to test it. I don`t know what exactly contains "newSettings"-argument.

Edited by Kotyarko_O

Share this post


Link to post

Short link
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...