Page 1 of 1
How do i give - " Reinforced glass" more or less Health using the SetHealth() method
Posted: Sun Feb 12, 2017 7:07 am
by jamisco
Just so you know, soughta new to C-sharp
so far i go this but it does work...
abstract void SetHealth(float hp) {
glass.SetHealth(1000f); \\ glass is the object id for the "reinforced glass" object
}
I keep getting this error when i try to compile ----- virtual or abstract methods cannot be private .... but its not freaking PRIVATE... if i made it public abstract void .... it wont work cuz abstract classes cant have bodies ..... some one help a brother out.... I'm begging you
Re: How do i give - " Reinforced glass" more or less Health using the SetHealth() method
Posted: Sun Feb 12, 2017 4:54 pm
by JakSparro98
jamisco wrote:Just so you know, soughta new to C-sharp
so far i go this but it does work...
abstract void SetHealth(float hp) {
glass.SetHealth(1000f); \\ glass is the object id for the "reinforced glass" object
}
I keep getting this error when i try to compile ----- virtual or abstract methods cannot be private .... but its not freaking PRIVATE... if i made it public abstract void .... it wont work cuz abstract classes cant have bodies ..... some one help a brother out.... I'm begging you
An abstract class cannot be directly used, it needs to be inherited.
Anyway you don't need to use abstract classes for this:
Download map example
You Just need to adjust the first variable as you like.
Please note that some weapon can still break the glass with a single shot, this due to the small hardcoded health of 50, this script replace the damage and will break the glass when his health container is empty but cannot prevent the object destruction when is already initialized.
Re: How do i give - " Reinforced glass" more or less Health using the SetHealth() method
Posted: Sun Feb 12, 2017 5:37 pm
by jamisco
I see, thx..... btw i was able to change that 50 health to 1000 in game file ....

not sure gurt will approve of such practices
Added in 33 minutes 47 seconds:
Hey Mr JakSparr, do you mind posting the script here, for some reason i cant open the map in map editor-- it doesn't appear in the list
Re: How do i give - " Reinforced glass" more or less Health using the SetHealth() method
Posted: Sun Feb 12, 2017 5:40 pm
by JakSparro98
jamisco wrote:I see, thx..... btw i was able to change that 50 health to 1000 in game file ....

not sure gurt will approve of such practices
Added in 33 minutes 47 seconds:
Hey Mr JakSparr, do you mind posting the script here, for some reason i cant open the map in map editor-- it doesn't appear in the list
No problem mate:
Code: Select all
float MaxHealth=800f;
Events.UpdateCallback m_updateEvent = null;
public void OnStartup() {
m_updateEvent = Events.UpdateCallback.Start(Glass, 0);
}
Dictionary<int, float> GList = new Dictionary<int, float>();
public void Glass(float elapsed){
foreach (IObject temp in Game.GetObjectsByName("ReinforcedGlass00A"))
{
if(!GList.ContainsKey(temp.UniqueID))
{
GList.Add(temp.UniqueID,MaxHealth);
}
else
{
if(GList[temp.UniqueID]>0)
{
GList[temp.UniqueID]-=(50f-temp.GetHealth());
temp.SetHealth(50);
//Game.ShowPopupMessage("ridotto");
}
else
{
GList.Remove(temp.UniqueID);
temp.Destroy();
}
}
}
}
We should point this problem out, Gurt might find a solution, avoiding to change game files.
I've also wrote a possible script addition in the planned script API features.
Re: How do i give - " Reinforced glass" more or less Health using the SetHealth() method
Posted: Sun Feb 12, 2017 5:50 pm
by jamisco
Thx for the script m8 really appreciate it
For the File changing problem
Well he tried his best, it made it so you cant edit the file, only the system... but an easy workaround was that you could change who edits the file... properties - security --- change permission.... then give yourself permission to change the file.... so I'm guessing if Gurt can make it in a way that doesn't allow people to change permission on the file, problem solved.... or he could make the files completely server side. That's how most games do it.
Re: How do i give - " Reinforced glass" more or less Health using the SetHealth() method
Posted: Sun Feb 12, 2017 6:54 pm
by Gurt
You can not increase the maximum health of an object. In the next version you will be able to read the maximum health of an object but you still can't increase the maximum health.
Re: How do i give - " Reinforced glass" more or less Health using the SetHealth() method
Posted: Sun Feb 12, 2017 7:04 pm
by JakSparro98
Gurt wrote:You can not increase the maximum health of an object. In the next version you will be able to read the maximum health of an object but you still can't increase the maximum health.
Then there might be another solution I posted
here.
Re: How do i give - " Reinforced glass" more or less Health using the SetHealth() method
Posted: Sun Feb 12, 2017 7:28 pm
by jamisco
Gurt wrote:You can not increase the maximum health of an object. In the next version you will be able to read the maximum health of an object but you still can't increase the maximum health.
I do not understand, how come the above script works, the glass was able to take more hits from the same gun while using the script than it was when not using it
Re: How do i give - " Reinforced glass" more or less Health using the SetHealth() method
Posted: Sat Feb 18, 2017 5:48 pm
by ShutDownMan
jamisco wrote:Gurt wrote:You can not increase the maximum health of an object. In the next version you will be able to read the maximum health of an object but you still can't increase the maximum health.
I do not understand, how come the above script works, the glass was able to take more hits from the same gun while using the script than it was when not using it
This is what the code does, it's a workaround, you store the objects health in the code and subtracts from it when it takes damage, when it's life gets to <= 0, it's destroyed...
Here's a commented version of the code:
Code: Select all
// Initializes glass health and sets it to 800f (change as you want)
float MaxHealth=800f;
// Initializes var that will hold the health "tick" event
Events.UpdateCallback m_updateEvent = null;
// On startup
public void OnStartup() {
// Starts up an Update Event that calls "Glass" method
m_updateEvent = Events.UpdateCallback.Start(Glass, 0);
}
// Initializes new <key = int, value = float> dictionary for all reinforced glass in the map
Dictionary<int, float> GList = new Dictionary<int, float>();
// Method "Glass", will be called each update cycle
public void Glass(float elapsed){
// foreach IObject with name of ReinforcedGlass00A in game
foreach (IObject temp in Game.GetObjectsByName("ReinforcedGlass00A"))
{
// If dictionary doesn't have the current object
if(!GList.ContainsKey(temp.UniqueID))
{
// Add it to list (key = object unique ID, value = MaxHealth)
GList.Add(temp.UniqueID,MaxHealth);
}
else // If it has the current object
{
// If it's value (health) is > 0
if(GList[temp.UniqueID]>0)
{
// Objects health -= 50f-(current IObject's health)
GList[temp.UniqueID]-=(50f-temp.GetHealth());
// Set IObject's health to 50f
temp.SetHealth(50);
}
else // If it's value (health) is <= 0
{
// Remove object from dictionary
GList.Remove(temp.UniqueID);
// Destroy IObject
temp.Destroy();
}
}
}
}
Also, may I ask for all you SFD coders to comment more your code, it's beneficial for everyone...
Re: How do i give - " Reinforced glass" more or less Health using the SetHealth() method
Posted: Sat Feb 18, 2017 6:32 pm
by JakSparro98
ShutDownMan wrote:jamisco wrote:Gurt wrote:You can not increase the maximum health of an object. In the next version you will be able to read the maximum health of an object but you still can't increase the maximum health.
I do not understand, how come the above script works, the glass was able to take more hits from the same gun while using the script than it was when not using it
This is what the code does, it's a workaround, you store the objects health in the code and subtracts from it when it takes damage, when it's life gets to <= 0, it's destroyed...
Also, may I ask for all you SFD coders to comment more your code, it's beneficial for everyone...
I've already replied in a PM he sent me and explained it, furthermore I didn't thought this code may cause problems in the reading, I comment long and complex code when I expect someone will read it to improve it.
Re: How do i give - " Reinforced glass" more or less Health using the SetHealth() method
Posted: Sat Feb 18, 2017 9:42 pm
by ShutDownMan
JakSparro98 wrote:
I've already replied in a PM he sent me and explained it, furthermore I didn't thought this code may cause problems in the reading, I comment long and complex code when I expect someone will read it to improve it.
Oh no, your code was completely clean, the only thing is that newbies (me some time ago) sometimes don't understand some things in the language (e.g. Dictionaries)