What's new

Discussion [Release] Updated projectile shooting :D

Lost4468

Contributor
Messages
2,202
Reaction score
1,760
Hey, the other code is pretty bad and this one allows you to easily add new functions. Put "self thread shootprojectiles();" before the part which looks like "for( ; ; )" by the "onplayerspawned()" part. To add a new projectile do this. Use up and down on the dpad to cycle through each one.

Code:
new_projectile(name,radius,maxdam,mindam,sound,model,fx)
For example

Code:
new_projectile("Care package Green",0,0,0,undefined,"com_plasticcase_friendly");
new_projectile("Explosion",200,1000,900,"exp_suitcase_bomb_main",undefined,"explosions/aerial_explosion_large");
^^these are included in the code below, add your own and post them here :smile:. Refer to the code below to see where to add them in the function.

Code:
NITRAM - new_projectile("Nuke",999999999,2000,900,"nuke_explosion",undefined,"explosions/emp_flash_mp");
And here is the rest of the code.

Code:
shootprojectiles()
{
level.projectiles = [];
new_projectile("Care package Red",0,0,0,undefined,"com_plasticcase_enemy");
new_projectile("Care package Green",0,0,0,undefined,"com_plasticcase_friendly");
new_projectile("Explosion",200,1000,900,"exp_suitcase_bomb_main",undefined,"explosions/aerial_explosion_large");
self notifyonplayercommand("Up", "+actionslot 1");
self notifyonplayercommand("Down", "+actionslot 2");
level.shot**** = [];level.obj=0;
self.pickedproj=0;
for(;;)
{
result = self waittill_any_return( "Up", "Down", "weapon_fired" );
switch(result)
{
case "Up":
if(self.pickedproj-1!=-1)
self.pickedproj--;
self iprintln(level.projectiles[self.pickedproj].name);
break;
case "Down":
if(self.pickedproj+1!=level.projectiles.size)
self.pickedproj++;
self iprintln(level.projectiles[self.pickedproj].name);
break;
case "weapon_fired":
trace=bullettrace(self gettagorigin("j_head"),self gettagorigin("j_head")+anglestoforward(self getplayerangles())*100000,1,self)["position"];
if(isdefined(level.projectiles[self.pickedproj].fx))
playfx(level.projectiles[self.pickedproj].fx,trace);
if(isdefined(level.projectiles[self.pickedproj].sound))
self playsound(level.projectiles[self.pickedproj].sound);
if(isdefined(level.projectiles[self.pickedproj].model))
{
level.shot****[level.shot****.size]=spawn("script_model",self gettagorigin("j_head"));
level.shot****[level.shot****.size-1] setmodel(level.projectiles[self.pickedproj].model);
level.shot****[level.shot****.size-1].angles = self.angles;
level.shot****[level.shot****.size-1] moveto(trace,distance(self.origin,trace)/5000);level.obj++;
if(level.obj == 350)
{
level.obj=0;
foreach(poop in level.shot****)
poop delete();
}
}
radiusdamage(trace,level.projectiles[self.pickedproj].radius,level.projectiles[self.pickedproj].maxdam,level.projectiles[self.pickedproj].mindam,self);
break;
}
}
}

new_projectile(name,radius,maxdam,mindam,sound,model,fx)
{
proj=spawnstruct();
proj.name = name;
proj.radius = radius;
proj.maxdam = maxdam;
proj.mindam = mindam;
if(isdefined(sound))
proj.sound = sound;
if(isdefined(fx))
proj.fx = loadfx(fx);
if(isdefined(model))
proj.model = model;
level.projectiles[level.projectiles.size] = proj;
}
 

NITRAM

Enthusiast
Messages
999
Reaction score
415
Wouldnt you have to undefined the fx

Code:
new_projectile("Care package Red",0,0,0,undefined,"com_plasticcase_enemy");
new_projectile("Care package Green",0,0,0,undefined,"com_plasticcase_friendly");
like so

Code:
new_projectile("Care package Red",0,0,0,undefined,"com_plasticcase_enemy",undefined);
new_projectile("Care package Green",0,0,0,undefined,"com_plasticcase_friendly",undefined);
I could be wrong but iam sure that you can't leave an argument in a function undefined

EDIT: I was wrong you only have to defined an argument in a function if you what to defined something in the next argument and so on

also here have a nuke to shoot

Code:
new_projectile("Nuke",999999999,2000,900,"nuke_explosion",undefined,"explosions/emp_flash_mp");
 

zy0n

Enthusiast
Messages
901
Reaction score
449
uhm... why dont you change it from this
Code:
new_projectile(name,radius,maxdam,mindam,sound,model,fx)
to this:
Code:
new_projectile(name,model,sound,fx,radius,maxdam,mindam)
So you only have to add the 'radius, maxdam, mindam' on projectiles that need it.

Code:
new_projectile(name,model,sound,fx,radius,maxdam,mindam)
{
proj=spawnstruct();
proj.name = name;
if(isDefined(radius)) proj.radius = radius;
else proj.radius = 0;
if(isDefined(maxdam)) proj.maxdam = maxdam;
else proj.maxdam = 0;
if(isDefined(mindam)) proj.mindam = mindam;
else proj.mindam = 0;

if(isdefined(sound))
proj.sound = sound;
if(isdefined(fx))
proj.fx = loadfx(fx);
if(isdefined(model))
proj.model = model;
level.projectiles[level.projectiles.size] = proj;
return;
}
also... you don't need the return proj; it just needs to return not with a value.
 

Lost4468

Contributor
Messages
2,202
Reaction score
1,760
uhm... why dont you change it from this
Code:
new_projectile(name,radius,maxdam,mindam,sound,model,fx)
to this:
Code:
new_projectile(name,model,sound,fx,radius,maxdam,mindam)
So you only have to add the 'radius, maxdam, mindam' on projectiles that need it.

Code:
new_projectile(name,model,sound,fx,radius,maxdam,mindam)
{
proj=spawnstruct();
proj.name = name;
if(isDefined(radius)) proj.radius = radius;
else proj.radius = 0;
if(isDefined(maxdam)) proj.maxdam = maxdam;
else proj.maxdam = 0;
if(isDefined(mindam)) proj.mindam = mindam;
else proj.mindam = 0;

if(isdefined(sound))
proj.sound = sound;
if(isdefined(fx))
proj.fx = loadfx(fx);
if(isdefined(model))
proj.model = model;
level.projectiles[level.projectiles.size] = proj;
return;
}
also... you don't need the return proj; it just needs to return not with a value.
It doesn't really matter which way you do it, your still going to have to use undefined on some places, and it doesn't really matter if you set them to 0. Also the return is because I was going to do it differently :tongue:.
 

zy0n

Enthusiast
Messages
901
Reaction score
449
It doesn't really matter which way you do it, your still going to have to use undefined on some places, and it doesn't really matter if you set them to 0. Also the return is because I was going to do it differently :tongue:.
I know lol, when I create a function I try to think of how it's going to be used most, and what order the arguments are used. wasnt saying anythings wrong with the code I was just reorganizing it to how I would do it

and you need the 'return' in there otherwise it would go to that script, and halt.
if you did self thread, then it would work without the return.
 

dconnor

Enthusiast
Messages
755
Reaction score
187
@lost: zy0n is correct. If you simply don't define following inputs, the compiler will assume they are undefined.
 

Lost4468

Contributor
Messages
2,202
Reaction score
1,760
I know lol, when I create a function I try to think of how it's going to be used most, and what order the arguments are used. wasnt saying anythings wrong with the code I was just reorganizing it to how I would do it

and you need the 'return' in there otherwise it would go to that script, and halt.
if you did self thread, then it would work without the return.
You don't need return, if it reaches the end of the function then it returns.

@lost: zy0n is correct. If you simply don't define following inputs, the compiler will assume they are undefined.
I know but if there are arguments after something then you need to put undefined.
 

BigWalrus

Enthusiast
Messages
2,007
Reaction score
880
I know but if there are arguments after something then you need to put undefined.
exactly.
for example if this is the function:
Code:
Do****( this, that, there )
{
}
and you do not want to define that then you must do:
Code:
Do****( "poop", undefined, "toilet" );
if you do not use undefined and just dont do it it would look like this:
Code:
Do****( "poop", "toilet" );
which would make that be defined as "toilet" when it should be there that is defined as "toilet".
 

dconnor

Enthusiast
Messages
755
Reaction score
187
zy0n is reordering the parameters:
Code:
Do****( this, there, that ){}
Code:
Do****( "poop", "toilet" );
Which is equivalent functionality as:
Code:
Do****( this, that, there ){}
Code:
Do****( "poop", undefined, "toilet" );
In zy0ns example that is assumed to be undefined @ compile. Which is a small but arguably better design.
 

zy0n

Enthusiast
Messages
901
Reaction score
449
zy0n is reordering the parameters:
Code:
Do****( this, there, that ){}
Code:
Do****( "poop", "toilet" );
Which is equivalent functionality as:
Code:
Do****( this, that, there ){}
Code:
Do****( "poop", undefined, "toilet" );
In zy0ns example that is assumed to be undefined @ compile. Which is a small but arguably better design.
:biggrin:
 
Top Bottom