Jump to content
Korean Random
goodman

Динамические макросы в Python

Recommended Posts

Парни,есть старенький скриптик с таким кодом:

import BigWorld

@xvm.export('shell_damage.shell_damage', deterministic=False)
def shell_damage():
    vehicle = BigWorld.player()
    shotDescr = vehicle.vehicleTypeDescriptor.shot
    if shotDescr['shell']['kind'] == 'HIGH_EXPLOSIVE':
        return "%i" % (shotDescr['shell']['damage'][0] // 2)
    else:
        return "%i" % (shotDescr['shell']['damage'][0]) 

Работал нормально,но в этом патче в логе ошибки посыпались:

2017-08-30 02:47:17: [ERROR] Traceback (most recent call last):

  File "./res_mods/mods/packages\xvm_main\python\python_macro.py", line 157, in process_python_macro

    return (func(), deterministic)

  File "./res_mods/mods/packages\xvm_main\python\python_macro.py", line 150, in <lambda>

    return (lambda: func(*args), deterministic)

  File "res_mods/configs/xvm/py_macro\shell_damage.py", line 7, in shell_damage

    if shotDescr['shell']['kind'] == 'HIGH_EXPLOSIVE':

  File "scripts/common/items/components/legacy_stuff.py", line 56, in __getitem__

AssertionError: Operation is not allowed

arg='shell_damage.shell_damage()'

Помогите поправить,моих знаний недостаточно(((

Попробуй вот так:

import BigWorld

@xvm.export('shell_damage.shell_damage', deterministic=False)
def shell_damage():
    vehicle = BigWorld.player()
    shotDescr = vehicle.vehicleTypeDescriptor.shot
    if shotDescr.shell.kind == SHELL_TYPES.HIGH_EXPLOSIVE:
        return "%i" % (shotDescr.shell.damage[0] // 2)
    else:
        return "%i" % (shotDescr.shell.damage[0])

Share this post


Link to post

Short link
Share on other sites

Попробуй вот так:

import BigWorld

@xvm.export('shell_damage.shell_damage', deterministic=False)
def shell_damage():
    vehicle = BigWorld.player()
    shotDescr = vehicle.vehicleTypeDescriptor.shot
    if shotDescr.shell.kind == SHELL_TYPES.HIGH_EXPLOSIVE:
        return "%i" % (shotDescr.shell.damage[0] // 2)
    else:
        return "%i" % (shotDescr.shell.damage[0])

Не помогло к сожалению,не работает и в логе вот что:

2017-08-30 23:20:15: [ERROR] Traceback (most recent call last):

File "./res_mods/mods/packages\xvm_main\python\python_macro.py", line 157, in process_python_macro

return (func(), deterministic)

File "./res_mods/mods/packages\xvm_main\python\python_macro.py", line 150, in

return (lambda: func(*args), deterministic)

File "res_mods/configs/xvm/py_macro\shell_damage.py", line 7, in shell_damage

if shotDescr.shell.kind == SHELL_TYPES.HIGH_EXPLOSIVE:

NameError: global name 'SHELL_TYPES' is not defined

arg='shell_damage.shell_damage()'

Это скриптик для того,что показывало шотные для твоего урона танки(для фугасов дамаг поделен на два,пробой редко проходит).Код в конфиге такой,мало ли:

"killEnemy": {
      "name": "killEnemy",
      "enabled": true,
      "x": 0,
      "y": "{{battletype?-73|{{squad?-73|-60}}}}",
      "alpha": "{{hp<{{py:shell_damage.shell_damage()}}?80|0}}",
      "color": "0xFFFF00",
      "align": "center",
	  "textFormat": {
        "font": "$FieldFont",
        "size": 13,
        "bold": false,
        "italic": false
      },
      "shadow": {
	  	// false - no shadow
        // false - без тени
        "enabled": true,
        "distance": 0,
        "angle": 90,
        "color": null,
        "alpha": 30,
        "blur": 6,
        "strength": 2
      },
      "format": "<img src='xvm://res/icons/killEnemy/{{vtype-key}}.png' width='23' height='23'>" // формат текста. См. описание макросов в macros.txt
	} 

  • Downvote 1

Share this post


Link to post

Short link
Share on other sites

Не помогло к сожалению,не работает и в логе вот что:

2017-08-30 23:20:15: [ERROR] Traceback (most recent call last):

File "./res_mods/mods/packages\xvm_main\python\python_macro.py", line 157, in process_python_macro

return (func(), deterministic)

File "./res_mods/mods/packages\xvm_main\python\python_macro.py", line 150, in

return (lambda: func(*args), deterministic)

File "res_mods/configs/xvm/py_macro\shell_damage.py", line 7, in shell_damage

if shotDescr.shell.kind == SHELL_TYPES.HIGH_EXPLOSIVE:

NameError: global name 'SHELL_TYPES' is not defined

arg='shell_damage.shell_damage()'

Это скриптик для того,что показывало шотные для твоего урона танки(для фугасов дамаг поделен на два,пробой редко проходит).Код в конфиге такой,мало ли:

"killEnemy": {
      "name": "killEnemy",
      "enabled": true,
      "x": 0,
      "y": "{{battletype?-73|{{squad?-73|-60}}}}",
      "alpha": "{{hp<{{py:shell_damage.shell_damage()}}?80|0}}",
      "color": "0xFFFF00",
      "align": "center",
	  "textFormat": {
        "font": "$FieldFont",
        "size": 13,
        "bold": false,
        "italic": false
      },
      "shadow": {
	  	// false - no shadow
        // false - без тени
        "enabled": true,
        "distance": 0,
        "angle": 90,
        "color": null,
        "alpha": 30,
        "blur": 6,
        "strength": 2
      },
      "format": "<img src='xvm://res/icons/killEnemy/{{vtype-key}}.png' width='23' height='23'>" // формат текста. См. описание макросов в macros.txt
	} 

Похоже нехватало импорта, вот так вроде как работает:

import BigWorld
from constants import SHELL_TYPES

@xvm.export('shell_damage.shell_damage', deterministic=False)
def shell_damage():
    vehicle = BigWorld.player()
    shotDescr = vehicle.vehicleTypeDescriptor.shot
    if shotDescr.shell.kind == SHELL_TYPES.HIGH_EXPLOSIVE:
        return "%i" % (shotDescr.shell.damage[0] // 2)
    else:
        return "%i" % (shotDescr.shell.damage[0])

  • Upvote 1

Share this post


Link to post

Short link
Share on other sites

Похоже нехватало импорта, вот так вроде как работает:

import BigWorld
from constants import SHELL_TYPES

@xvm.export('shell_damage.shell_damage', deterministic=False)
def shell_damage():
    vehicle = BigWorld.player()
    shotDescr = vehicle.vehicleTypeDescriptor.shot
    if shotDescr.shell.kind == SHELL_TYPES.HIGH_EXPLOSIVE:
        return "%i" % (shotDescr.shell.damage[0] // 2)
    else:
        return "%i" % (shotDescr.shell.damage[0])

Спасибо тебе добрый человек,теперь все работает и лог чистый;)

Share this post


Link to post

Short link
Share on other sites

 

I write a python macro to show the friendly arty's aiming position.

It will display as white points in the minimap and white circle in the battle view.

from xvm import aimingposition
@ Xvm.export ( 'xvm.aimpos', deterministic = False)
def refreshAimPos ():
	aimingposition.posManager.refreshList ()
	return ''
{
   "AimPos": {
      "Enabled": true,
      "UpdateEvent": "ON_EVERY_FRAME",
      "Alpha": 0,
      "Format": "{{py: xvm.aimpos ()}}"
	}
}

Если кто умеет, пофиксите вот этот скрипт, пожалуйста.

 

Сыпет в лог

2017-09-03 16:57:34.425: INFO: 2017-09-03 16:57:34: [ERROR] 79 aimpos|Operation is not allowed
2017-09-03 16:57:35.423: INFO: 2017-09-03 16:57:35: [ERROR] 79 aimpos|Operation is not allowed

Свежайшее, что есть у меня в аттаче

aimingposition21122016.zip

 

Спасибо.

Share this post


Link to post

Short link
Share on other sites

Если кто умеет, пофиксите вот этот скрипт, пожалуйста.

 

Сыпет в лог

2017-09-03 16:57:34.425: INFO: 2017-09-03 16:57:34: [ERROR] 79 aimpos|Operation is not allowed
2017-09-03 16:57:35.423: INFO: 2017-09-03 16:57:35: [ERROR] 79 aimpos|Operation is not allowed

Свежайшее, что есть у меня в аттаче

attachicon.gifaimingposition21122016.zip

 

Спасибо.

Вот, поправил дескрипторы. Сам не проверял, возможно что то еще надо будет править.

aimingposition.zip

Edited by xenus
  • Upvote 2

Share this post


Link to post

Short link
Share on other sites

@overrideClassMethod(cls, method)

Спасибо, что-то я не замечал его раньше.

Share this post


Link to post

Short link
Share on other sites
В 13.11.2016 в 12:21, ktulho сказал:

@Slava7572,@Kapany3uk,


    "sixthSenseTimer": { 
      "enabled": true,
      "updateEvent": "PY(ON_SIXTH_SENSE_SHOW)",
      "x": 0,
      "y": 260,
      "width": 60,
      "height": 50,
      "screenHAlign": "center",
      "shadow": { "distance": 1, "angle": 90, "alpha": 80, "blur": 5, "strength": 1.5 },
      "textFormat": {"align": "center", "size": 40 },
      "format": "{{py:xvm.sixthSenseTimer(10)%01.1f}}<font size='18'>{{py:xvm.sixthSenseTimer(10)?с.}}</font>"
    },   

sixthSense.rar

 

Други,подскажите пожалуйста .. Что я делаю не так?? беру этот файл,кидаю его в папку по назначению,но ничего не происходит,таймера нет.(( помогите. спасибо

Share this post


Link to post

Short link
Share on other sites

ссылку в battleLabels.xc дописать нужно

${"battleLabelsTemplates.xc":"def.sixthSenseTimer"},

 

@Rancunier   без ссылки не будет работать

 

Share this post


Link to post

Short link
Share on other sites

@Rancunier  а само поле "sixthSenseTimer" хоть написано в battleLabels Templates.xc ?  Поле тоже вписать нужно.

    "sixthSenseTimer": { 
      "enabled": true,
      "updateEvent": "PY(ON_SIXTH_SENSE_SHOW)",
      "x": 0,
      "y": 260,
      "width": 60,
      "height": 50,
      "screenHAlign": "center",
      "shadow": { "distance": 1, "angle": 90, "alpha": 80, "blur": 5, "strength": 1.5 },
      "textFormat": {"align": "center", "size": 40 },
      "format": "{{py:xvm.sixthSenseTimer(10)%01.1f}}<font size='18'>{{py:xvm.sixthSenseTimer(10)?с.}}</font>"
    },   

Share this post


Link to post

Short link
Share on other sites

@ktulho Посмотрите, пожалуйста, правильно ли макрос 

def invis_stand():
    return "%.1f" % (_typeDescriptor.type.invisibility[1] * 50)

отдает значения маскировки в покое? Например, Leo по ТТХ имеет показатель 15,69, а макрос отдает 13,7

Маскировка в движении и при выстрелах тоже не совпадают с ТТХ.

Edited by ddar

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...