Posted By: Anonymous
one action,many entities (diffrent effect on each) - 06/21/05 06:08
Just thought this bit of code might helpful to someone. It saved me a lot of time in my game from having to write 200 actions to make 200 juggling objects juggle at different sin and cos frequencies. Since my.skill1 through my.skill100 are local variables to an object, one can conform a skill to a global variable accordingly to allow that object to have the same action/function but still have it conform to either when it was created, where exactly it is, etc. This should significantly decrease the amount of everyone's favorite activity: c-script programming.
When juggling, if you didn't know, every ball is not thrown at the same time. So here is the function I used in the the ent_create to create more juggling balls without having multiple actions, but still having each ball moving in the pattern at the correct frequency:
function juggleobject()
{
my.skill1=2;fakecount+=1;my.skill60=fakecount;my.skill1=skilly;counter+=1;counter%=2;
if(counter==1){my.skill70=1;}else{my.skill70=-1;}
if(counter==0){my.skill80=0;}else{my.skill80=-180;}
my.material=sam;
while(1){
if(baco==0){my.material=sam;}if(baco==1){my.material=e1;}if(baco==2){my.material=e2;}
if(baco==3){my.material=e3;}if(baco==4){my.material=e4;}if(baco==5){my.material=e5;}
if(baco==6){my.material=e6;}
if(baco==7){if(my.skill60%6==0){my.material=e1;}if(my.skill60%6==1){my.material=e2;}
if(my.skill60%6==2){my.material=e3;}if(my.skill60%6==3){my.material=e4;}
if(my.skill60%6==4){my.material=e5;}if(my.skill60%6==5){my.material=e6;}}
if(frc((fakecount/4))==0){my.skill90=even;}else{my.skill90=my.skill80;}
vec_set(my.skill13,my.x);my.skill12=fsin(my.roll,-20);my.skill11=fcos(-my.roll,-20);my.skill10=0;
vec_add(my.skill13,my.skill10);
if(key_ctrl==on)
{effect(flame,8*time,my.skill13,nullvector);
effect(smoke,8*time,vector(my.skill13+fcos(total_ticks*10,10),my.skill14+fcos(total_ticks*10,10),my.skill15+20),nullvector);};
if(my.skill1==1){ent_morph(my,sphere_mdl);my.skill1=0;};
if(my.skill1==2){ent_morph(my,ball_mdl);my.skill1=0;};
if(my.skill1==3){ent_morph(my,box_mdl);my.skill1=0;};
if(my.skill1==4){ent_morph(my,club_mdl);my.skill1=0;};
if(my.skill1==5){ent_morph(my,ring_mdl);my.skill1=0;};
if(my.skill1==6){my.facing=on;ent_morph(my,cloud_pcx);my.skill1=0;};
if(frc(fakecount/2)!=0)
{ my.invisible=off;
my.x=-width*cos((total_ticks*8*rev)+(timing*(my.skill60-1)));
my.z=-height*cos((total_ticks*16*rev+(timing*(my.skill60-1)*2))-45);
if(skilly==4){my.roll=(-total_ticks*16*spin)+(timing*(my.skill60-1)*2)-90;};
}else{if(frc(fakecount/2)==0)
{
my.invisible=off;my.x=((width/2)*cos((timing*(my.skill60-1)+my.skill90)+(total_ticks*16*rev)))+(my.skill70*width);
my.z=-1*my.skill70*height*sin((timing*(my.skill60-1)+my.skill90)+(total_ticks*16*rev));if(skilly==4){my.roll=(-total_ticks*16*spin)+timing*(my.skill60-1)+90;}}
else{my.invisible=on;}}
if(count<my.skill60){fakecount-=1;counter+=1;ent_remove(my);break;}
wait(1);};
}
Ok, forget about everything here related to its material and path and all that excess stuff that's just for looks, the main thing I wanted to relate is that the global variable (fakecount in this case) is saved into a skill60 (this variable tells how many objects there are), that skill60 could be used to time its path (motion of object is at the bottom part of the function) perfectly according to how many objects are being juggled (fakecount). In other words, the global variable will change each objects skill to how many objects there are, so that skill can be used to time its movement correctly (if you're juggling 3 balls, there's gonna be about 1/2 as much time between each throw as if you were juggling 6 balls right?). So using these local variables, skills can be helpful in applying a formula to each object according to a global factor/variable. In this case its just the amount of balls already there (when it was created). Also in this case the global variable was increasing each time an object was created so I just placed that in the created-object's function. This might save you a lot of time if you're making hundreds of entities. I could use this for a whole lot of objects, but after juggling about 75, framerates get so low, you can't even tell the difference! I think 500 models is the default maximum. This can also apply to particles (my.skill_a through my.skill_z). You could also even have the skills be applied to a global FUNCTION. I'm just hoping to save you guys some time.....
"Those who are faithful with little, will be entrusted with much" -Albert Einstein quoting Jesus Christ
When juggling, if you didn't know, every ball is not thrown at the same time. So here is the function I used in the the ent_create to create more juggling balls without having multiple actions, but still having each ball moving in the pattern at the correct frequency:function juggleobject()
{
my.skill1=2;fakecount+=1;my.skill60=fakecount;my.skill1=skilly;counter+=1;counter%=2;
if(counter==1){my.skill70=1;}else{my.skill70=-1;}
if(counter==0){my.skill80=0;}else{my.skill80=-180;}
my.material=sam;
while(1){
if(baco==0){my.material=sam;}if(baco==1){my.material=e1;}if(baco==2){my.material=e2;}
if(baco==3){my.material=e3;}if(baco==4){my.material=e4;}if(baco==5){my.material=e5;}
if(baco==6){my.material=e6;}
if(baco==7){if(my.skill60%6==0){my.material=e1;}if(my.skill60%6==1){my.material=e2;}
if(my.skill60%6==2){my.material=e3;}if(my.skill60%6==3){my.material=e4;}
if(my.skill60%6==4){my.material=e5;}if(my.skill60%6==5){my.material=e6;}}
if(frc((fakecount/4))==0){my.skill90=even;}else{my.skill90=my.skill80;}
vec_set(my.skill13,my.x);my.skill12=fsin(my.roll,-20);my.skill11=fcos(-my.roll,-20);my.skill10=0;
vec_add(my.skill13,my.skill10);
if(key_ctrl==on)
{effect(flame,8*time,my.skill13,nullvector);
effect(smoke,8*time,vector(my.skill13+fcos(total_ticks*10,10),my.skill14+fcos(total_ticks*10,10),my.skill15+20),nullvector);};
if(my.skill1==1){ent_morph(my,sphere_mdl);my.skill1=0;};
if(my.skill1==2){ent_morph(my,ball_mdl);my.skill1=0;};
if(my.skill1==3){ent_morph(my,box_mdl);my.skill1=0;};
if(my.skill1==4){ent_morph(my,club_mdl);my.skill1=0;};
if(my.skill1==5){ent_morph(my,ring_mdl);my.skill1=0;};
if(my.skill1==6){my.facing=on;ent_morph(my,cloud_pcx);my.skill1=0;};
if(frc(fakecount/2)!=0)
{ my.invisible=off;
my.x=-width*cos((total_ticks*8*rev)+(timing*(my.skill60-1)));
my.z=-height*cos((total_ticks*16*rev+(timing*(my.skill60-1)*2))-45);
if(skilly==4){my.roll=(-total_ticks*16*spin)+(timing*(my.skill60-1)*2)-90;};
}else{if(frc(fakecount/2)==0)
{
my.invisible=off;my.x=((width/2)*cos((timing*(my.skill60-1)+my.skill90)+(total_ticks*16*rev)))+(my.skill70*width);
my.z=-1*my.skill70*height*sin((timing*(my.skill60-1)+my.skill90)+(total_ticks*16*rev));if(skilly==4){my.roll=(-total_ticks*16*spin)+timing*(my.skill60-1)+90;}}
else{my.invisible=on;}}
if(count<my.skill60){fakecount-=1;counter+=1;ent_remove(my);break;}
wait(1);};
}
Ok, forget about everything here related to its material and path and all that excess stuff that's just for looks, the main thing I wanted to relate is that the global variable (fakecount in this case) is saved into a skill60 (this variable tells how many objects there are), that skill60 could be used to time its path (motion of object is at the bottom part of the function) perfectly according to how many objects are being juggled (fakecount). In other words, the global variable will change each objects skill to how many objects there are, so that skill can be used to time its movement correctly (if you're juggling 3 balls, there's gonna be about 1/2 as much time between each throw as if you were juggling 6 balls right?). So using these local variables, skills can be helpful in applying a formula to each object according to a global factor/variable. In this case its just the amount of balls already there (when it was created). Also in this case the global variable was increasing each time an object was created so I just placed that in the created-object's function. This might save you a lot of time if you're making hundreds of entities. I could use this for a whole lot of objects, but after juggling about 75, framerates get so low, you can't even tell the difference! I think 500 models is the default maximum. This can also apply to particles (my.skill_a through my.skill_z). You could also even have the skills be applied to a global FUNCTION. I'm just hoping to save you guys some time.....
"Those who are faithful with little, will be entrusted with much" -Albert Einstein quoting Jesus Christ
