Dear forum users! In compliance with the new European GDPR regulations, we'd just like to inform you that if you have an account, your email address is stored in our database. We do not share your information with third parties, and your email address and password are encrypted for security reasons.

New to the forum? Say hello in this topic! Also make sure to read the rules.

How do i give - " Reinforced glass" more or less Health using the SetHealth() method

Here you can find answered ScriptAPI topics.
Forum rules
By using the forum you agree to the following rules.
Post Reply
jamisco
Superfighter
Superfighter
Posts: 67
Joined: Sun Nov 06, 2016 11:34 pm
Title: Da God
SFD Account: Jamisco
SFD Alias: Jamisco
Started SFD: either late 2015 or early 2016
Location: Somewhere in the east of the United states
Gender:
Age: 103

How do i give - " Reinforced glass" more or less Health using the SetHealth() method

Post by jamisco » Sun Feb 12, 2017 7:07 am

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
0 x
Is it better to be feared or respected... please, is it too much to ask for both?

User avatar
JakSparro98
Superfighter
Superfighter
Posts: 530
Joined: Fri Jul 15, 2016 7:56 pm
Started SFD: PreAlpha 1.0.5
Location: Rome, Italy
Gender:
Age: 25

Post by JakSparro98 » Sun Feb 12, 2017 4:54 pm

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.
Last edited by JakSparro98 on Sun Feb 12, 2017 5:41 pm, edited 1 time in total.
1 x

jamisco
Superfighter
Superfighter
Posts: 67
Joined: Sun Nov 06, 2016 11:34 pm
Title: Da God
SFD Account: Jamisco
SFD Alias: Jamisco
Started SFD: either late 2015 or early 2016
Location: Somewhere in the east of the United states
Gender:
Age: 103

Post by jamisco » Sun Feb 12, 2017 5:37 pm

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
0 x
Is it better to be feared or respected... please, is it too much to ask for both?

User avatar
JakSparro98
Superfighter
Superfighter
Posts: 530
Joined: Fri Jul 15, 2016 7:56 pm
Started SFD: PreAlpha 1.0.5
Location: Rome, Italy
Gender:
Age: 25

Post by JakSparro98 » Sun Feb 12, 2017 5:40 pm

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

jamisco
Superfighter
Superfighter
Posts: 67
Joined: Sun Nov 06, 2016 11:34 pm
Title: Da God
SFD Account: Jamisco
SFD Alias: Jamisco
Started SFD: either late 2015 or early 2016
Location: Somewhere in the east of the United states
Gender:
Age: 103

Post by jamisco » Sun Feb 12, 2017 5:50 pm

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.
0 x
Is it better to be feared or respected... please, is it too much to ask for both?

User avatar
Gurt
Lead Programmer
Lead Programmer
Posts: 1884
Joined: Sun Feb 28, 2016 3:22 pm
Title: Lead programmer
Started SFD: Made it!
Location: Sweden
Gender:
Age: 34

Post by Gurt » Sun Feb 12, 2017 6:54 pm

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.
0 x
Gurt

User avatar
JakSparro98
Superfighter
Superfighter
Posts: 530
Joined: Fri Jul 15, 2016 7:56 pm
Started SFD: PreAlpha 1.0.5
Location: Rome, Italy
Gender:
Age: 25

Post by JakSparro98 » Sun Feb 12, 2017 7:04 pm

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.
Last edited by JakSparro98 on Mon Nov 27, 2017 4:13 pm, edited 1 time in total.
0 x

jamisco
Superfighter
Superfighter
Posts: 67
Joined: Sun Nov 06, 2016 11:34 pm
Title: Da God
SFD Account: Jamisco
SFD Alias: Jamisco
Started SFD: either late 2015 or early 2016
Location: Somewhere in the east of the United states
Gender:
Age: 103

Post by jamisco » Sun Feb 12, 2017 7:28 pm

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
0 x
Is it better to be feared or respected... please, is it too much to ask for both?

User avatar
ShutDownMan
Fighter
Fighter
Posts: 32
Joined: Sat Mar 19, 2016 7:17 pm
Title: Yeah, science!
SFD Alias: ShutDownMan, Devil Shut
Started SFD: 1.2.something
Location: Hu3, Brazil
Gender:
Age: 24
Contact:

Post by ShutDownMan » Sat Feb 18, 2017 5:48 pm

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...
0 x
~ShutDownMan

User avatar
JakSparro98
Superfighter
Superfighter
Posts: 530
Joined: Fri Jul 15, 2016 7:56 pm
Started SFD: PreAlpha 1.0.5
Location: Rome, Italy
Gender:
Age: 25

Post by JakSparro98 » Sat Feb 18, 2017 6:32 pm

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

User avatar
ShutDownMan
Fighter
Fighter
Posts: 32
Joined: Sat Mar 19, 2016 7:17 pm
Title: Yeah, science!
SFD Alias: ShutDownMan, Devil Shut
Started SFD: 1.2.something
Location: Hu3, Brazil
Gender:
Age: 24
Contact:

Post by ShutDownMan » Sat Feb 18, 2017 9:42 pm

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)
2 x
~ShutDownMan

Post Reply