Call script in other entity

For my current project I need to call scripts from one entity inside another and came up with an easy scalable way.
I hope that will be useful for someone who needs the same in their game.

You’ll need following entity variables:
“eventArray” datatype string: “[ ]”
“eventPackage” datatype string: “[ ]”
also attribute:
“eventTrigger” max value 1, default value 1 and 0 regeneration.

For the sender you just need to pack the event in an array and add it to the event Array

Send Event
     "triggers": [],
     "conditions": [
          {
               "operator": "==",
               "operandType": "boolean"
          },
          true,
          true
     ],
     "actions": [
          {
               "type": "setEntityVariable",
               "entity": {
                    "function": "thisEntity"
               },
               "variable": {
                    "function": "getEntityVariable",
                    "variable": {
                         "text": "eventPackage",
                         "dataType": "string",
                         "entity": "kGLw70K50k",
                         "key": "eventPackage"
                    }
               },
               "value": "[]",
               "comment": ""
          },
          {
               "type": "setEntityVariable",
               "entity": {
                    "function": "thisEntity"
               },
               "variable": {
                    "function": "getEntityVariable",
                    "variable": {
                         "text": "eventPackage",
                         "dataType": "string",
                         "entity": "kGLw70K50k",
                         "key": "eventPackage"
                    }
               },
               "value": {
                    "function": "insertStringArrayElement",
                    "value": "damage",
                    "string": {
                         "function": "getValueOfEntityVariable",
                         "variable": {
                              "function": "getEntityVariable",
                              "variable": {
                                   "text": "eventPackage",
                                   "dataType": "string",
                                   "entity": "kGLw70K50k",
                                   "key": "eventPackage"
                              }
                         },
                         "entity": {
                              "function": "thisEntity"
                         }
                    }
               },
               "comment": ""
          },
          {
               "type": "setEntityVariable",
               "entity": {
                    "function": "thisEntity"
               },
               "variable": {
                    "function": "getEntityVariable",
                    "variable": {
                         "text": "eventPackage",
                         "dataType": "string",
                         "entity": "kGLw70K50k",
                         "key": "eventPackage"
                    }
               },
               "value": {
                    "function": "insertStringArrayElement",
                    "value": {
                         "function": "getUnitId",
                         "unit": {
                              "function": "thisEntity"
                         }
                    },
                    "string": {
                         "function": "getValueOfEntityVariable",
                         "variable": {
                              "function": "getEntityVariable",
                              "variable": {
                                   "text": "eventPackage",
                                   "dataType": "string",
                                   "entity": "kGLw70K50k",
                                   "key": "eventPackage"
                              }
                         },
                         "entity": {
                              "function": "thisEntity"
                         }
                    }
               },
               "comment": ""
          },
          {
               "type": "setEntityVariable",
               "entity": {
                    "function": "thisEntity"
               },
               "variable": {
                    "function": "getEntityVariable",
                    "variable": {
                         "text": "eventPackage",
                         "dataType": "string",
                         "entity": "kGLw70K50k",
                         "key": "eventPackage"
                    }
               },
               "value": {
                    "function": "insertStringArrayElement",
                    "value": "5",
                    "string": {
                         "function": "getValueOfEntityVariable",
                         "variable": {
                              "function": "getEntityVariable",
                              "variable": {
                                   "text": "eventPackage",
                                   "dataType": "string",
                                   "entity": "kGLw70K50k",
                                   "key": "eventPackage"
                              }
                         },
                         "entity": {
                              "function": "thisEntity"
                         }
                    }
               },
               "comment": ""
          },
          {
               "type": "setEntityVariable",
               "entity": {
                    "function": "getValueOfEntityVariable",
                    "variable": {
                         "function": "getEntityVariable",
                         "variable": {
                              "text": "other",
                              "dataType": "unit",
                              "entity": "2VTUGBBYsm",
                              "key": "other"
                         }
                    },
                    "entity": {
                         "function": "thisEntity"
                    }
               },
               "variable": {
                    "function": "getEntityVariable",
                    "variable": {
                         "text": "EventArray",
                         "dataType": "string",
                         "entity": "kGLw70K50k",
                         "key": "EventArray"
                    }
               },
               "value": {
                    "function": "insertStringArrayElement",
                    "value": {
                         "function": "getValueOfEntityVariable",
                         "variable": {
                              "function": "getEntityVariable",
                              "variable": {
                                   "text": "eventPackage",
                                   "dataType": "string",
                                   "entity": "kGLw70K50k",
                                   "key": "eventPackage"
                              }
                         },
                         "entity": {
                              "function": "thisEntity"
                         }
                    },
                    "string": {
                         "function": "getValueOfEntityVariable",
                         "variable": {
                              "function": "getEntityVariable",
                              "variable": {
                                   "text": "EventArray",
                                   "dataType": "string",
                                   "entity": "kGLw70K50k",
                                   "key": "EventArray"
                              }
                         },
                         "entity": {
                              "function": "getValueOfEntityVariable",
                              "variable": {
                                   "function": "getEntityVariable",
                                   "variable": {
                                        "text": "other",
                                        "dataType": "unit",
                                        "entity": "2VTUGBBYsm",
                                        "key": "other"
                                   }
                              },
                              "entity": {
                                   "function": "thisEntity"
                              }
                         }
                    }
               },
               "comment": ""
          },
          {
               "type": "setEntityAttribute",
               "attribute": "r7Iy9IoF2i",
               "entity": {
                    "function": "getValueOfEntityVariable",
                    "variable": {
                         "function": "getEntityVariable",
                         "variable": {
                              "text": "other",
                              "dataType": "unit",
                              "entity": "2VTUGBBYsm",
                              "key": "other"
                         }
                    },
                    "entity": {
                         "function": "thisEntity"
                    }
               },
               "value": 0
          },
          {
               "type": "setEntityAttribute",
               "attribute": "r7Iy9IoF2i",
               "entity": {
                    "function": "getValueOfEntityVariable",
                    "variable": {
                         "function": "getEntityVariable",
                         "variable": {
                              "text": "other",
                              "dataType": "unit",
                              "entity": "2VTUGBBYsm",
                              "key": "other"
                         }
                    },
                    "entity": {
                         "function": "thisEntity"
                    }
               },
               "value": 1
          }
     ],
     "name": "send event",
     "parent": null,
     "key": "2EC4Ion977",
     "order": 8
}

On the receiver you need two main scripts to handle with the events.

On Attribute Min
{
     "triggers": [
          {
               "type": "entityAttributeBecomesZero"
          }
     ],
     "conditions": [
          {
               "operator": "==",
               "operandType": "boolean"
          },
          true,
          true
     ],
     "actions": [
          {
               "type": "condition",
               "conditions": [
                    {
                         "operandType": "attributeType",
                         "operator": "=="
                    },
                    {
                         "function": "getAttributeTypeOfAttribute",
                         "entity": {
                              "function": "getTriggeringAttribute"
                         }
                    },
                    "r7Iy9IoF2i"
               ],
               "then": [
                    {
                         "type": "runScript",
                         "scriptName": "ntgZCN5tf7",
                         "isEntityScript": true
                    }
               ],
               "else": [],
               "isExpanded": {
                    "self": false
               }
          }
     ],
     "name": "on attribute min",
     "parent": null,
     "key": "2WOr5nYIAK",
     "order": 8
}```
Call Event
{
     "triggers": [],
     "conditions": [
          {
               "operator": "==",
               "operandType": "boolean"
          },
          true,
          true
     ],
     "actions": [
          {
               "type": "repeat",
               "count": {
                    "function": "getStringArrayLength",
                    "string": {
                         "function": "getValueOfEntityVariable",
                         "variable": {
                              "function": "getEntityVariable",
                              "variable": {
                                   "text": "EventArray",
                                   "dataType": "string",
                                   "entity": "kGLw70K50k",
                                   "key": "EventArray"
                              }
                         },
                         "entity": {
                              "function": "thisEntity"
                         }
                    }
               },
               "actions": [
                    {
                         "type": "setEntityVariable",
                         "entity": {
                              "function": "thisEntity"
                         },
                         "variable": {
                              "function": "getEntityVariable",
                              "variable": {
                                   "text": "eventPackage",
                                   "dataType": "string",
                                   "entity": "kGLw70K50k",
                                   "key": "eventPackage"
                              }
                         },
                         "value": {
                              "function": "getStringArrayElement",
                              "number": 0,
                              "string": {
                                   "function": "getValueOfEntityVariable",
                                   "variable": {
                                        "function": "getEntityVariable",
                                        "variable": {
                                             "text": "EventArray",
                                             "dataType": "string",
                                             "entity": "kGLw70K50k",
                                             "key": "EventArray"
                                        }
                                   },
                                   "entity": {
                                        "function": "thisEntity"
                                   }
                              }
                         }
                    },
                    {
                         "type": "condition",
                         "conditions": [
                              {
                                   "operandType": "string",
                                   "operator": "=="
                              },
                              {
                                   "function": "getStringArrayElement",
                                   "number": 0,
                                   "string": {
                                        "function": "getValueOfEntityVariable",
                                        "variable": {
                                             "function": "getEntityVariable",
                                             "variable": {
                                                  "text": "eventPackage",
                                                  "dataType": "string",
                                                  "entity": "kGLw70K50k",
                                                  "key": "eventPackage"
                                             }
                                        },
                                        "entity": {
                                             "function": "thisEntity"
                                        }
                                   }
                              },
                              "damage"
                         ],
                         "then": [
                              {
                                   "type": "runScript",
                                   "scriptName": "D8IK5bGLg3",
                                   "isEntityScript": true
                              }
                         ],
                         "else": [],
                         "isExpanded": {
                              "self": false
                         }
                    },
                    {
                         "type": "condition",
                         "conditions": [
                              {
                                   "operandType": "string",
                                   "operator": "=="
                              },
                              {
                                   "function": "getStringArrayElement",
                                   "number": 0,
                                   "string": {
                                        "function": "getValueOfEntityVariable",
                                        "variable": {
                                             "function": "getEntityVariable",
                                             "variable": {
                                                  "text": "eventPackage",
                                                  "dataType": "string",
                                                  "entity": "kGLw70K50k",
                                                  "key": "eventPackage"
                                             }
                                        },
                                        "entity": {
                                             "function": "thisEntity"
                                        }
                                   }
                              },
                              "hide"
                         ],
                         "then": [
                              {
                                   "type": "runScript",
                                   "scriptName": "C9TayLfVcH",
                                   "isEntityScript": true
                              }
                         ],
                         "else": [],
                         "isExpanded": {
                              "self": false
                         }
                    },
                    {
                         "type": "setEntityVariable",
                         "entity": {
                              "function": "thisEntity"
                         },
                         "variable": {
                              "function": "getEntityVariable",
                              "variable": {
                                   "text": "EventArray",
                                   "dataType": "string",
                                   "entity": "kGLw70K50k",
                                   "key": "EventArray"
                              }
                         },
                         "value": {
                              "function": "removeStringArrayElement",
                              "number": 0,
                              "string": {
                                   "function": "getValueOfEntityVariable",
                                   "variable": {
                                        "function": "getEntityVariable",
                                        "variable": {
                                             "text": "EventArray",
                                             "dataType": "string",
                                             "entity": "kGLw70K50k",
                                             "key": "EventArray"
                                        }
                                   },
                                   "entity": {
                                        "function": "thisEntity"
                                   }
                              }
                         }
                    }
               ]
          }
     ],
     "name": "call events",
     "parent": null,
     "key": "cCDk3VGl7y",
     "order": 5
}

example:

Event Damage
     "triggers": [],
     "conditions": [
          {
               "operator": "==",
               "operandType": "boolean"
          },
          true,
          true
     ],
     "actions": [
          {
               "type": "setEntityVariable",
               "entity": {
                    "function": "thisEntity"
               },
               "variable": {
                    "function": "getEntityVariable",
                    "variable": {
                         "text": "lastDamagingUnit",
                         "dataType": "unit",
                         "entity": "kGLw70K50k",
                         "key": "lastDamagingUnit"
                    }
               },
               "value": {
                    "function": "getUnitFromId",
                    "string": {
                         "function": "getStringArrayElement",
                         "number": 1,
                         "string": {
                              "function": "getValueOfEntityVariable",
                              "variable": {
                                   "function": "getEntityVariable",
                                   "variable": {
                                        "text": "eventPackage",
                                        "dataType": "string",
                                        "entity": "kGLw70K50k",
                                        "key": "eventPackage"
                                   }
                              },
                              "entity": {
                                   "function": "thisEntity"
                              }
                         }
                    }
               },
               "comment": ""
          },
          {
               "type": "setEntityAttribute",
               "attribute": "health",
               "entity": {
                    "function": "thisEntity"
               },
               "value": {
                    "function": "calculate",
                    "items": [
                         {
                              "operator": "-"
                         },
                         {
                              "function": "getEntityAttribute",
                              "attribute": "health",
                              "entity": {
                                   "function": "thisEntity"
                              }
                         },
                         {
                              "function": "stringToNumber",
                              "value": {
                                   "function": "getStringArrayElement",
                                   "number": 2,
                                   "string": {
                                        "function": "getValueOfEntityVariable",
                                        "variable": {
                                             "function": "getEntityVariable",
                                             "variable": {
                                                  "text": "eventPackage",
                                                  "dataType": "string",
                                                  "entity": "kGLw70K50k",
                                                  "key": "eventPackage"
                                             }
                                        },
                                        "entity": {
                                             "function": "thisEntity"
                                        }
                                   }
                              }
                         }
                    ]
               }
          }
     ],
     "name": "event damage",
     "parent": null,
     "key": "D8IK5bGLg3",
     "order": 5
}```
4 Likes