Playmaker Forum
PlayMaker Help & Tips => PlayMaker Help => Topic started by: shadowof047 on April 25, 2016, 03:18:08 AM
-
Hello .
At first i wanna say that i searched the forum for this and found some other topics such as this :
http://hutonggames.com/playmakerforum/index.php?topic=4898.0 (ftp://hutonggames.com/playmakerforum/index.php?topic=4898.0)
but i couldnt find my answer there . so here is my question :
I have this script :
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using Invector;
public class MeleeWeapon : MeleeItem
{
#region variables
[Header("Weapon Settings")]
public int ATK_ID;
public int MoveSet_ID;
public Damage damage;
public DamagePercentage damagePercentage;
[Tooltip("How much stamina the attack will consume")]
public float staminaCost = 30f;
[Tooltip("Time for the stamina to recover")]
public float staminaRecoveryDelay = 1f;
[Header("Hitbox Settings")]
[Range(0.1f, 2.9f)]
public float centerSize = 1f;
[Range(-1.4f, 1.4f)]
public float centerPos = 0f;
public BoxCollider top, bottom, center;
public bool showHitboxes;
public HitProperties hitProperties { get; set; }
protected float curCenterSize;
[HideInInspector]
public HitBox hitTop, hitBotton, hitCenter;
public bool lockHitBox = true;
#endregion
[System.Serializable]
public class DamagePercentage
{
public float Top = 30f;
public float Center = 70f;
}
public void Init()
{
hitTop = top.GetComponent<HitBox>();
hitBotton = bottom.GetComponent<HitBox>();
hitCenter = center.GetComponent<HitBox>();
hitTop.hitBarPoint = HitBarPoints.Top;
hitCenter.hitBarPoint = HitBarPoints.Center;
hitBotton.hitBarPoint = HitBarPoints.Bottom;
hitTop.hitControl = this;
hitBotton.hitControl = this;
hitCenter.hitControl = this;
}
public bool isActive { get { return active; } }
public struct DamageType
{
public Collider hitCollider;
public HitBarPoints hitBarPoints;
}
}
I want to access the float "Top " and float "Center" in the Class "DamagePercentage" , but they are nowhere to be found .
Also when i add this script some other variables shows up in the inspector such as float "Value" or bool "Ignore Defense " which are not even in the script ( and i'm too noob to know where it is reading them from )
It maybe worth mentioning that it is "Melee Weapon" Script from " Melee Combat Template " asset by Invector .
Can someone help me on this ?
-
After doing some more search i found this topic on the forum which had a similar problem like me :
http://hutonggames.com/playmakerforum/index.php?topic=10222.0 (ftp://hutonggames.com/playmakerforum/index.php?topic=10222.0)
After reading through it , i found that the variables i'm trying to access is from Damage class . but i cant quite find a way to solve my problem , here is the line which declares a damage class in first script :
public Damage damage;
and here is the actual damage class in second script :
public class Damage
{
[Tooltip("Apply damage to the Character Health")]
public int value;
[Tooltip("Apply damage even if the Character is blocking")]
public bool ignoreDefense;
[Tooltip("Activated Ragdoll when hit the Character")]
public bool activeRagdoll;
[HideInInspector] public Transform sender;
[HideInInspector] public Recoil_ID recoil_id;
public Damage (int value, bool ignoreDefense, bool activeRagdoll, Transform sender, Recoil_ID recoil_ID)
{
this.value = value;
this.ignoreDefense = ignoreDefense;
this.activeRagdoll = activeRagdoll;
this.sender = sender;
this.recoil_id = recoil_ID;
}
public enum Recoil_ID
{
low,
medium,
hard
}
public Damage(Damage damage)
{
this.value = damage.value;
this.ignoreDefense = damage.ignoreDefense;
this.activeRagdoll = damage.activeRagdoll;
this.sender = damage.sender;
this.recoil_id = damage.recoil_id;
}
}
So how should i modify the first script to access "Value" variable in Damage class ? thanks.
-
If you can't access what you want in a script via get/set property or the method actions included with PM in the ScriptControl section you'll need a custom action-
I'm just an amateur coder but if you post the scripts I can have a go at making an action for it when I get the chance-
-
If you can't access what you want in a script via get/set property or the method actions included with PM in the ScriptControl section you'll need a custom action-
I'm just an amateur coder but if you post the scripts I can have a go at making an action for it when I get the chance-
That would be greatly appreciated because i'm really stuck :-[
Here is the complete first script which is called "MeleeWeapon.cs" :
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using Invector;
public class MeleeWeapon : MeleeItem
{
#region variables
[Header("Weapon Settings")]
public int ATK_ID;
public int MoveSet_ID;
public Damage damage;
public DamagePercentage damagePercentage;
[Tooltip("How much stamina the attack will consume")]
public float staminaCost = 30f;
[Tooltip("Time for the stamina to recover")]
public float staminaRecoveryDelay = 1f;
[Header("Hitbox Settings")]
[Range(0.1f, 2.9f)]
public float centerSize = 1f;
[Range(-1.4f, 1.4f)]
public float centerPos = 0f;
public BoxCollider top, bottom, center;
public bool showHitboxes;
public HitProperties hitProperties { get; set; }
protected float curCenterSize;
[HideInInspector]
public HitBox hitTop, hitBotton, hitCenter;
public bool lockHitBox = true;
#endregion
[System.Serializable]
public class DamagePercentage
{
public float Top = 30f;
public float Center = 70f;
}
//public override Type GetSubType()
//{
// return GetType();
//}
public void Init()
{
hitTop = top.GetComponent<HitBox>();
hitBotton = bottom.GetComponent<HitBox>();
hitCenter = center.GetComponent<HitBox>();
hitTop.hitBarPoint = HitBarPoints.Top;
hitCenter.hitBarPoint = HitBarPoints.Center;
hitBotton.hitBarPoint = HitBarPoints.Bottom;
hitTop.hitControl = this;
hitBotton.hitControl = this;
hitCenter.hitControl = this;
#region Set ignore collision for all hitBox
//if (transform.GetComponentInParent<MeleeEquipmentManager>() != null)
//{
// Physics.IgnoreCollision(top, bottom);
// Physics.IgnoreCollision(bottom, center);
// Physics.IgnoreCollision(center, top);
// var meleeManager = transform.GetComponentInParent<MeleeEquipmentManager>();
// if(meleeManager==null)
// {
// Debug.LogWarning("The " + gameObject.name + " don't have a MeleeEquipmentManager");
// }
// var col = meleeManager.GetComponent<Collider>();
// if (col != null && col.enabled)
// {
// Physics.IgnoreCollision(col, bottom);
// Physics.IgnoreCollision(col, center);
// Physics.IgnoreCollision(col, top);
// var colChild = meleeManager.GetComponentsInChildren<Collider>();
// foreach (Collider _col in colChild)
// {
// if (!_col.Equals(bottom) &&
// !_col.Equals(center) &&
// !_col.Equals(top) && _col.enabled)
// {
// Physics.IgnoreCollision(_col, bottom);
// Physics.IgnoreCollision(_col, center);
// Physics.IgnoreCollision(_col, top);
// }
// }
// }
//}
#endregion
}
public bool isActive { get { return active; } }
public struct DamageType
{
public Collider hitCollider;
public HitBarPoints hitBarPoints;
}
}
and here is the second script which is called "vObjectDamage" :
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class vObjectDamage : MonoBehaviour
{
public Damage damage;
[Tooltip("List of tags that can be hit")]
public List<string> tags;
public bool useTrigger, useCollision;
void OnCollisionEnter(Collision hit)
{
if (!useCollision)
return;
if(tags.Contains(hit.transform.tag))
{
damage.sender = transform;
// apply damage to Character
hit.transform.SendMessage ("TakeDamage", damage, SendMessageOptions.DontRequireReceiver);
}
}
void OnTriggerEnter(Collider hit)
{
if (!useTrigger)
return;
if (tags.Contains(hit.transform.tag))
{
damage.sender = transform;
// apply damage to Character
hit.transform.SendMessage("TakeDamage", damage, SendMessageOptions.DontRequireReceiver);
}
}
}
[System.Serializable]
public class Damage
{
[Tooltip("Apply damage to the Character Health")]
public int value;
[Tooltip("Apply damage even if the Character is blocking")]
public bool ignoreDefense;
[Tooltip("Activated Ragdoll when hit the Character")]
public bool activeRagdoll;
[HideInInspector] public Transform sender;
[HideInInspector] public Recoil_ID recoil_id;
public Damage (int value, bool ignoreDefense, bool activeRagdoll, Transform sender, Recoil_ID recoil_ID)
{
this.value = value;
this.ignoreDefense = ignoreDefense;
this.activeRagdoll = activeRagdoll;
this.sender = sender;
this.recoil_id = recoil_ID;
}
public enum Recoil_ID
{
low,
medium,
hard
}
public Damage(Damage damage)
{
this.value = damage.value;
this.ignoreDefense = damage.ignoreDefense;
this.activeRagdoll = damage.activeRagdoll;
this.sender = damage.sender;
this.recoil_id = damage.recoil_id;
}
}
-
Ok what variables do you want to access?
Do you want to set them from a Playmaker action or get them?
-
Ok what variables do you want to access?
Do you want to set them from a Playmaker action or get them?
i want to Set the "value" and "ignoreDefense" variables with playmaker action .
Thank you very much
-
Where is that vObjectDamage script used? Is it attached to the Playable character or NPC? I attached an action- I don't have the asset so I can't test it- but if the script is on the object with this FSM it will set it-
-
I went ahead and made an action that sets all the vars on the vObjectDamage script- it is attached-
-
Where is that vObjectDamage script used? Is it attached to the Playable character or NPC? I attached an action- I don't have the asset so I can't test it- but if the script is on the object with this FSM it will set it-
"vObjectDamage" script is not even in the scene , there is a line in "MeleeWeapon" script :
public Damage damage;
this Damage class is declared in "vObjectDamage" , but only "MeleeWeapon" script exists in the scene .
I just tested the actions that you kindly wrote , it isays "Gameobject requires a vObjectDamage Component" , but that script is not attached to my game object ( in this case , the player)
-
I see- since I don't have the asset I can't test/debug it properly- sorry about that- If I have the time I will go back and see if I can fix it
-
it is very kind of you to even try , and i appreciate it .
Since it a paid asset , i'm not sure what the rules are about putting it's script here :'(
-
In order for the action to work you need to set variables on a script that is not on a gameobject or in the scene- I've never done that before as I always use GetComponent and grab the script-
I'll give it another try this week as I'd like to learn how to do it-
If anyone reading can drop me a hint that would be great :)
-
Hi,
the best way for this would be to create a custom action really.
Have you contacted the author and mention you'd make good use of some PlayMaker support for that asset?
Bye,
Jean
-
Hi .
Thanks " mdotstrange " for all the support you have given .
Thats a good idea Jean , i'm gonna try it since it is the best 3rd controller there is ( in my idea ) and many would benefit from the integration of playmaker in it, including the developer .