Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
Health pickup (medkit) script

dekon_17
Registered User
Quote
2021-11-07 09:47:51

As a dude who (tries) to make an FPS game with CopperCube, I needed a health kits. So, I made a script for this! Also, feel free to use this script if you want or need it.

First of all, the script itself:
/*
<action jsname = "action_FirstAid" description = "Act as a first aid kit, I guess">
<property name = "HealthVar" type = "string"/>
<property name = "MaxHealth" type = "float" default = "100"/>
<property name = "HealthAmount" type = "float" default = "20"/>
<property name = "DoOnPickup" type = "action"/>
<property name = "DeleteOnPickup" type = "bool" default = "true"/>
<property name = "ObjectToDelete" type = "scenenode"/>
</action>
*/

action_FirstAid = function()
{
};

action_FirstAid.prototype.execute = function()
{
var bob = ccbGetCopperCubeVariable(this.HealthVar);
if ((bob + this.HealthAmount) <= this.MaxHealth && bob != this.MaxHealth)
{
ccbSetCopperCubeVariable(this.HealthVar, bob + this.HealthAmount);
ccbInvokeAction(this.DoOnPickup);

if (this.DeleteOnPickup == true)
{
ccbRemoveSceneNode(this.ObjectToDelete);
};
}
else if ((bob + this.HealthAmount) >> this.MaxHealth && bob != this.MaxHealth)
{
ccbSetCopperCubeVariable(this.HealthVar, this.MaxHealth);
ccbInvokeAction(this.DoOnPickup);

if (this.DeleteOnPickup == true)
{
ccbRemoveSceneNode(this.ObjectToDelete);
};
};
};


Now, about all the properties:
HealthVar - variable for health, which will be changed by script.
MaxHealth - maximal health amount that variable can have. If health is equal to it's maximum, then script wouldn't be executed.
HealthAmount - amount of health given by script.
DoOnPickup - action (-s) which will be executed if script is being executed.
DeleteOnPickup - if true, then it will delete the object selected in next property.
ObjectToDelete - an object that will be deleted if script is being executed.

If you will use this script, it's better to have it as an action for a "On proximity do something" behavior. Still, you can use this with any other behavior.
🔎︎



hadoken
Guest
Quote
2021-11-08 10:53:32

Haven't tested yet but this could surely come in handy.
Thanks for sharing!


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Int?rnational" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact