A few bits of code

Posted By: James_Burke

A few bits of code - 09/10/05 14:44

Hi,
Here are a few bits of code I have lying around. Some people might find useful. They're pretty simple, but some people might have some use for them.
Flickering Light
Exploding Barrel

and here's a health and armor code (ready for A5 templates, change to _health__003 and _armor__003 for template 6).

Code:

//=============================
//Health And Armor Pack Code
//---------------
//Created By: James A. Burke
//email: contact@jabigp.com
//=============================
//-----------------------------
//Defines
//-----------------------------
DEFINE _health_val, skill1; //Medical pack value
DEFINE _armor_val, skill1; //Armor pack value

//-----------------------------
//Prototype Functions
//-----------------------------
function healthPackEvent(); //Event called when player collides with a health pack entity
function armorPackEvent(); //Event called when player collides with an armor pack entity

//-----------------------------
//Functions
//-----------------------------
//---------------
//Desc: Gives the player health
//---------------
function healthPackEvent()
{
if(player._health + my._health_val > 100)
{
player._health = 100; //Don't give the player over 100 health
}
if(player._health + my._health_val <= 100)
{
player._health += my._health_val;
}
my.enable_impact = off;
my.event = null;
my.invisible = on;
my.passable = on;
wait(1);
ent_remove(my); //Remove the model
}

//---------------
//Desc: Gives the player armor
//---------------
function armorPackEvent()
{
if(player._armor + my._armor_val > 100)
{
player._armor = 100; //Don't give the player over 100 armor
}
if(player._armor + my._armor_val <= 100)
{
player._armor += my._armor_val;
}
my.enable_impact = off; //Inactive now
my.event = null;
my.invisible = on;
my.passable = on;
wait(1);
ent_remove(my); //Remove the model
}

//-----------------------------
//Actions
//-----------------------------
//---------------
//Desc: Standard health pack
//---------------
//uses: _health_val
action health_pack
{
while(player == null)
{
wait(1); //Prevent empty pointer errors
}
if(my._health_val <= 0)
{
my._health_val = 25; //Give it a default value
}
while(1)
{
if(player != null)
{
if(vec_dist(my.x, player.x) < 100)
{
player._health = 100;
ent_remove(my);
return;
}
}
my.pan += 2 * time; //Rotate the entity
wait(1);
}
}

//---------------
//Desc: Standard armor pack
//---------------
//uses: _armor_val
action armor_pack
{
if(my._armor_val <= 0)
{
my._armor_val = 25; //Give it a default value
}
my.enable_impact = on;
my.event = armorPackEvent;
}



I would also be happy to hear any suggestions for other codes
Hope this helps,
James
Posted By: James_Burke

Re: A few bits of code - 09/11/05 09:09

Here's another thing I found, a very simple action to add to anything you want physics to. When shot, the physics will be applied and it will go flying off. Note that you will need the Commercial or Professional edition as it uses Conitec's physics engine.
Code:

//=============================
//Shootable Physics Objects
//---------------
//Created By: James A. Burke
//Copyright (c) 2004 - 2005 James A. Burke
//=============================
//-----------------------------
//Variable Defines
//-----------------------------
//-----------------------------
//Prototype Functions
//-----------------------------
function moniter_event(); //Changes the moniter model and physics

//-----------------------------
//Functions
//-----------------------------
//---------------
//Desc; Adds force to the moniter9
//---------------
function moniter_event()
{
my.lightrange = 0;
my.lightred = 0;
my.lightblue = 0;
my.lightgreen = 0;
phent_enable(my, 1);
if(event_type == event_shoot)
{
phent_addforcelocal(my, vector(6000, 0, 0), target);
}
if(event_type == event_impact)
{
phent_addforcelocal(my, vector(6000, 0, 0), target);
}
}


//-----------------------------
//Actions
//-----------------------------
//---------------
//Desc: Makes the shell fall to the ground
//---------------
action moniter
{
my.shadow = on;
my._id = _spark;
phent_settype(my, PH_RIGID, PH_BOX);
phent_setmass(my, 10, PH_BOX);
phent_setfriction(my, 20);
phent_setelasticity(my, 50, 100);
phent_setdamping(my, 50, 75);
ph_setgravity(vector(0,0,-386));
my.enable_shoot = on;
my.enable_impact = on;
my.event = moniter_event;
my.lightrange = 60;
my.lightred = 20;
my.lightgreen = 128;
my.lightblue = 140;
}


Posted By: AndrewSwallow

Re: A few bits of code - 09/11/05 18:38

any screens of anything?

im quite interested in the barrel and the light

im too busy with other stuff, to test them right now

thanks
andrewds
Posted By: Inestical

Re: A few bits of code - 09/12/05 07:17

nice code, but simple.. hmm I can modify 'em for my use ( *whistles* And I'm not abusing 'em now *whistles again* )
Posted By: James_Burke

Re: A few bits of code - 09/12/05 08:57

Quote:

any screens of anything?

im quite interested in the barrel and the light




Sure, here's a few screens:
Barrel



Light



Physics (not much to show really)

Posted By: James_Burke

Re: A few bits of code - 09/12/05 08:59

Quote:

nice code, but simple.. hmm I can modify 'em for my use ( *whistles* And I'm not abusing 'em now *whistles again* )




Hope they are of some use to you Unfortunetly the better more advanced codes aren't free If you (or anyone) does want some specific code (for cheap) you can contact us (www.jabigp.com)
© 2024 lite-C Forums