PDA

View Full Version : Fire direction/angles



guiismiti
22nd September 2014, 07:17
Hello,

Spent a few hours on this, no success, and haven't found anything in the forum.
I'm still adjusting an AC-130 script, and I need to fire 7 bullets in different angles:

774

Right now I'm not even making the bullet trace, only thing I'm doing is the damage on target origin:

This is called on each player for every bullet:


players[p] thread [[level.callbackPlayerDamage]](players[p], self, 200, 0, "MOD_RIFLE_BULLET", "gunship_25mm_mp", players[p].origin, (0,0,0), "none",0);


Any ideas?

IzNoGoD
22nd September 2014, 09:48
init()
{
level.effects = [];
level.effects["large_bark"]=loadfx("fx/impacts/large_woodhit.efx");
level.effects["large_brick"]=loadfx("fx/impacts/large_brick.efx");
level.effects["large_carpet"]=loadfx("fx/impacts/default_hit.efx");
level.effects["large_cloth"]=loadfx("fx/impacts/cloth_hit.efx");
level.effects["large_concrete"]=loadfx("fx/impacts/large_plaster.efx");
level.effects["large_dirt"]=loadfx("fx/impacts/large_dirt.efx");
level.effects["large_flesh"]=loadfx("fx/impacts/flesh_hit.efx");
level.effects["large_foliage"]=loadfx("fx/impacts/small_foliage.efx");
level.effects["large_glass"]=loadfx("fx/impacts/large_glass.efx");
level.effects["large_grass"]=loadfx("fx/impacts/small_grass.efx");
level.effects["large_gravel"]=loadfx("fx/impacts/large_gravel.efx");
level.effects["large_ice"]=loadfx("fx/impacts/small_snowhit.efx");
level.effects["large_metal"]=loadfx("fx/impacts/large_metalhit.efx");
level.effects["large_mud"]=loadfx("fx/impacts/large_mud.efx");
level.effects["large_paper"]=loadfx("fx/impacts/default_hit.efx");
level.effects["large_plaster"]=loadfx("fx/impacts/large_plaster.efx");
level.effects["large_rock"]=loadfx("fx/impacts/large_rock.efx");
level.effects["large_sand"]=loadfx("fx/impacts/large_dirt.efx");
level.effects["large_snow"]=loadfx("fx/impacts/small_snowhit.efx");
level.effects["large_water"]=loadfx("fx/impacts/large_waterhit.efx");
level.effects["large_wood"]=loadfx("fx/impacts/large_woodhit.efx");
level.effects["large_asphalt"]=loadfx("fx/impacts/large_rock.efx");
level.effects["large_default"]=loadfx("fx/impacts/default_hit.efx");
}

firebullets(bullets, spread, damage)
{
for(i = 0; i < bullets; i++)
{
spreadangles = spreadangles(spread, self getplayerangles);
smallforward = anglestoforward(spreadangles);
forward = maps\mp\_utility::vectorscale(smallforward, 10000);
point = self geteyepos();
trace = bullettrace(point, point + forward, true, self);
if(isdefined(trace["entity"]) && isplayer(trace["entity"]))
{
iDflags = 0;
sMeansofDeath = "MOD_RIFLE_BULLET"
vDir = vectornormalize(trace["position"] - self.origin);
if(distancesquared(trace["entity"] geteye() + (0, 0, 16), trace["position"]) < 64)
{
damage = int(damage * 2);
sHitloc = "head";
}
else
sHitloc = "none";
trace["entity"] maps\mp\gametypes\_callbacksetup::CodeCallback_Pla yerDamage(self, self, damage, iDFlags, sMeansOfDeath, weap, trace["position"], vDir, sHitLoc, 0);
}
else if(trace["fraction"] < 1 && isdefined(trace["surfacetype"]) && trace["surfacetype"] != "default")
placebullethole(trace, self.origin);
}
}

placebullethole(trace, startpoint)
{
fx="large_";
fx += trace["surfacetype"];
if(isdefined(level.effects[fx]))
effect = level.effects[fx];
else
effect = level.effects["large_default"];
normal = vectornormalize(startpoint - trace["position"]);
if(normal != (0,0,0))
{
normal2 = trace["normal"];
if(distance(normal, normal2)> 2 * sin(22.5))
normal = normal2;
playfx(effect, trace["position"], normal);
}
}


spreadangles(spread, oldangles)
{
minx = 1 - randomint(2) * 2;
miny = 1 - randominit(2) * 2;
spready = randomfloat(spread);
oldangles = (oldangles[0] + minx * randomfloat(spread), oldangles[1] + miny * spready, oldangles[2]);
if(oldangles[1] > 180)
oldangles = (oldangles[0], oldangles[1] - 360, oldangles[2]);
if(oldangles[1] < -180)
oldangles = (oldangles[0], oldangles[1] + 360, oldangles[2]);
if(oldangles[0] > 90 && oldangles[1] > 180)
oldangles = (oldangles[0] - spready * 2, oldangles[1] - 180, oldangles[2]);
else if(oldangles[0] > 90)
oldangles = (oldangles[0] - spready * 2, oldangles[1] + 180, oldangles[2]);
if(oldangles[0] < -90 && oldangles[1] > 180)
oldangles = (oldangles[0] + spready * 2, oldangles[1] - 180, oldangles[2]);
else if(oldangles[0] < -90)
oldangles = (oldangles[0] + spready * 2, oldangles[1] + 180, oldangles[2]);
return oldangles;
}

Just a little addition: if you want to fire 7 bullets each frame, this would result in 140 bullets per second or 8400 bullets per minute. Just for reference, the biggest flying gun does only 3900 rpm (source: http://en.wikipedia.org/wiki/Fairchild_Republic_A-10_Thunderbolt_II )

serthy
22nd September 2014, 16:03
I did my AC130 with 3 real weapons (modified rocket launcher, simply make them faster/ slower + no recoil etc) since u already use 3(?) custom weapon files for your killicon.
So you dont need to precache effects nor use bullettraces and a script at all on this.
You can even use the reticle and dont have to precache and use your huds etc. Just monitor the weapon the player currently has.

guiismiti
22nd September 2014, 16:52
@iznogod
It's only 1 shot for each one of the hud marks (there are seven, like in the image). The user can fire a set of 7 bullets every 0.875 seconds (0.125s delay between each bullet).
By the way, I got the code I'm editting from pastebin, and it was entitled "to IzNoGod" - do you remember who created it? I need to credit this person.

@serthy
The killicons for the ac130 (and also the airstrike) are working now.


This is a demo video I just made:
http://classic.xfire.com/video/62cd41/

As you can see, I'm firing 7 shots right at the center of my screen with 1 mouse click. What I want is - to fire 7 shots, but 1 shot in each of the hud marks (is this how the ac130 works? I'm gonna look for it now, actually....):
776

This is the code I'm using to fire the 25mm gun right now.


if(self attackbuttonpressed() && isalive(self) && self._ac_gun1_ammo>0)
{
self playsound("gunship_25mm_fire");
earthquake(0.3,0.5, self.origin, 80);
vec=anglestoforward(self getplayerangles());
trace=bullettrace(self geteye()+(0,0,18),self geteye()+(20000*vec[0],20000*vec[1],20000*vec[2]+18),true,self);

for(i = 1; i < 8; i++)
{
if(isDefined(self.acsound))
self.acsound delete();

self.acsound = spawn("script_origin",trace["position"]);

if(isDefined(trace["surfacetype"]) && trace["surfacetype"] == "water")
{
playfx(level._effect["water_small"],trace["position"]);
self.acsound playsound("bullet_small_water");
}
else
{
playfx(level._effect["ac25mm"],trace["position"]);
}
self._ac_gun1_ammo--;
players=getentarray("player","classname");

for(p=0;p<players.size;p++)
{
if(players[p].pers["team"]!=self.pers["team"] && isAlive(players[p]))
{
if(distance(trace["position"],players[p].origin)<80)
{
earthquake(0.5,1, trace["position"], 80);
players[p] thread [[level.callbackPlayerDamage]](players[p], self, 200, 0, "MOD_RIFLE_BULLET", "gunship_25mm_mp", players[p].origin, (0,0,0), "none",0);
}
}
}
if(isdefined(self.hud_currentammo))
self.hud_currentammo setValue(self._ac_gun1_ammo);

wait 0.125;
}
}



Editted:
I'm now guessing it's something to do with this


trace=bullettrace(self geteye()+(0,0,18),self geteye()+(20000*vec[0],20000*vec[1],20000*vec[2]+18),true,self);


But I've been trying to identify the player angles (by moving and printing it), and I don't know what to change there.

guiismiti
22nd September 2014, 21:21
oh I didn't actually read it all.
I'm gonna try to make some changes based on your code, thank you.

serthy
22nd September 2014, 22:29
What do you want? An AC130 like in the modern CoD titles?
They are done like I said, by using projectile weapons.
You can download the gamescripts from MW2, MW3 and BO1 to see how its done.
Otherwise you can just add a delay of 0.1 between your 7 bullettraces

guiismiti
24th September 2014, 16:54
Sorry it took so long for me to answer, but what I want is exactly what the code from iznogod is doing.
I set the weapon to 20 rounds/second. Seems to be working fine.
Although I'm trying to add the flash effect. It should start at the shooter's origin and end at the target - but it's starting in variable locations, which depend on the surface angle of the target.
I'm placing this
playfx(level._effect["ac25mm_tracer_flash"], trace["position"], normal);
after this
playfx(effect, trace["position"], normal);


and here, a few corrections and the base code should run:
1


spreadangles = spreadangles(spread, self getplayerangles);

should be


spreadangles = spreadangles(spread, self getplayerangles());


2


point = self geteyepos();

should be


point = self geteye();


3


sMeansofDeath = "MOD_RIFLE_BULLET"

should be


sMeansofDeath = "MOD_RIFLE_BULLET";


4


miny = 1 - randominit(2) * 2;

should be


miny = 1 - randomint(2) * 2;

IzNoGoD
24th September 2014, 18:35
For your tracer effect: I had an issue with the fx playing on the impact if the angle between the fx and the surface was too high: this would cause the bullethole to become invisible, thus i had to hack in the normal of the surface if the angle exceeded this value. You should always use the normal in placebullethole(), not normal2. Try to playfx() your fx before this check. (aka right before the normal2 = line, but inside that if)

guiismiti
24th September 2014, 19:26
worked perfectly.

Editted: is there an easy way to zoom the shooter's view? I know I could use the overlay from weapon_mp, but I'm not using it at the moment, and still, the player would need to aim to zoom it. Any way to automatically zoom it depending on the hud?

serthy
24th September 2014, 20:07
you could look in the extreme mod to see how they did their sniper zoom (by setting the client var cg_fov or something like that)

Ni3ls
25th September 2014, 08:13
Video? I want to see how it looks :)

guiismiti
25th September 2014, 18:02
http://classic.xfire.com/video/62cecc/

message me if you want the code, some things must also be set in the game type script, the gunship menu must be added so the players can call the function (or simply use F3 to start it), sounds and soundaliases, effects and maybe even more.

Editted: I know that the ammo for the 25mm is not discounting - it's temporary for the tests. I'll also change the ammo hud color when current ammo goes under 1/3 of the max ammo.

guiismiti
2nd December 2014, 19:05
I've been testing my mods now that I'm back, and I tested this gunship not as the user for the first time. I noticed the flashes go from the target to the shooter, and that looks really weird - the shots go from the ground to the pilot and beyond the ac130.

What is the syntax here? Maybe I can fix it.



trace = bullettrace(point, point + forward, true, self);

IzNoGoD
2nd December 2014, 19:56
nope, just rotate your normal 180 degrees using a vectorscale with -1 as scale on it (in playfx)

guiismiti
7th June 2015, 20:42
After loosing most of my work, I only corrected this now.

In addition to IzNo's correction, I had also to change the source of the shot, by changing this


playfx(level._effect["ac25mm_tracer_flash"], trace["position"], normal);

to this


playfx(level._effect["ac25mm_tracer_flash"], startpoint, normal);

guiismiti
10th June 2015, 19:57
Since xfire is going down, I'll just leave this here

https://www.youtube.com/watch?v=tzKUYd89_24


Any ideas on how to highlight other players for the gunship gunner only? I know that team icons show up for same team players only, but not sure if this is hardcoded or what...

serthy
10th June 2015, 20:25
Since xfire is going down, I'll just leave this here

https://www.youtube.com/watch?v=tzKUYd89_24


Any ideas on how to highlight other players for the gunship gunner only? I know that team icons show up for same team players only, but not sure if this is hardcoded or what...

I know of 2 ways:


Play an Fx (maybe a simple decal or light) on the players origin and do a hide() + showToPlayer() on the fx to the pilot only)
use Huds lik in the zombie-gametypes

Tally
10th June 2015, 22:27
Since xfire is going down, I'll just leave this here

https://www.youtube.com/watch?v=tzKUYd89_24


Any ideas on how to highlight other players for the gunship gunner only? I know that team icons show up for same team players only, but not sure if this is hardcoded or what...

Not sure if you can use setTargetEnt() in COD2 MP, but in COD4, we did it with a waypoint:


ac130_AddtargetWaypoints( team )
{
self.ac130_targetWaypoint = [];

for( i = 0; i < level.players.size; i++ )
{
player = level.players[i];

if( !isAlive( player ) )
continue;

if( level.teambased && player.pers["team"] != team )
continue;

waypoint = NewClientHudElem( self );
waypoint.x = 0;
waypoint.y = 0;
waypoint.z = 0;
waypoint.archived = true;
waypoint.alpha = 1.0;
waypoint setShader( level.playerTargetShader, 8, 8 );
waypoint setWayPoint( true, level.playerTargetShader );
waypoint setTargetEnt( player );

self.ac130_targetWaypoint[self.ac130_targetWaypoint.size] = waypoint;
}
}


The waypoint becomes "attached" to each player targeted, and follows them around.

serthy
10th June 2015, 22:52
Not sure if you can use setTargetEnt() in COD2 MP, but in COD4...
setEntTarget() is CoD4 only, you can use Tally's code, but you need to set the origin of the hud every frame to the players origin (this looks abit laggy though)

vanfreddy
11th June 2015, 00:04
hi, i do it this way

init()
{
precacheshader("finder_icon");
}

markfounded(target,size)
{
scale = int(size);
//self endon("disconnect");

target_mark = newClientHudElem(self);
target_mark.x = target[0];
target_mark.y = target[1];
target_mark.z = target[2] + 28;
target_mark.archived = true;
target_mark.alpha = 1;
target_mark.color = (1,0,0);
target_mark setShader("finder_icon", scale, scale);
target_mark setwaypoint(true);

wait .05;
target_mark destroy();

}


canseeinview()
{
self endon("disconnect");
max_viewangle = 15;
if(isdefined(self.isbot))
if(self.isbot) return;

for(;;)
{
while(self playerads() == 1)//aim only
{
if (self getcurrentweapon() != "enfield_mp")//your gun
break;

players = getentarray("player", "classname");
for(f = 0; f < players.size; f++)
{
//wait .05;
player = players[f];

if(player == self )
continue;

//if((isdefined(player.pers["team"]) && player.pers["team"] == "spectator"))
//continue;

if (!isalive(player) ||player.sessionstate != "playing")
continue;

dist2 = vectornormalize(player.origin - self.origin);

vfwd = anglestoforward(self getplayerangles());
dot = vectordot(vfwd, dist2);
if (dot > 1)
dot = 1;
else if (dot < -1)
dot = -1;

viewangle = acos(dot);
if (viewangle > max_viewangle)
continue;

test = bullettracepassed(self geteye(),player geteye(),false,self);
if(test)
self thread markfounded(player.origin,8);

}
wait .05;
}
wait .05;
}
}

here u can see it in action just use targetfinder gun or wait for ac
Server IP: 217.172.178.19:28979 (V1.2)

guiismiti
11th June 2015, 00:57
If I'm not asking too much, could you upload your finder icon shader please? I only have 1.3 installed, I'd like to see how it is. The code works well.


Editted amazing...

vanfreddy
11th June 2015, 01:19
http://217.172.178.19/Vanfreddy/findericon.rar

Tally
11th June 2015, 08:19
setEntTarget() is CoD4 only, you can use Tally's code, but you need to set the origin of the hud every frame to the players origin (this looks abit laggy though)

No, it's in COD2 for sure but it must be Single Player only.

Mitch
11th June 2015, 08:51
No, it's in COD2 for sure but it must be Single Player only.

Indeed, it is only available in SP. But it might be possible to port it to MP.
Edit: isn't in SP either. I posted the wrong function.. (for turret).

COD4


int __cdecl sub_808F8EA(int a1)
{
int *v1; // ebx@2
int result; // eax@3
char v3; // [sp+8h] [bp-10h]@0

if ( HIWORD(a1) == 1 )
{
v1 = &dword_8335620[43 * (unsigned __int16)a1];
}
else
{
sub_815F134("not a hud element");
v1 = 0;
}
result = sub_80C76EC(0);
v1[4] = *(_DWORD *)result;
if ( !(*(_BYTE *)(result + 246) & 0x10) )
result = sub_81228D4(
15,
"SetTargetEnt() called on a non-broadcasting entity, may not show in client snapshots.",
v3);
return result;
}


COD2 turrent setTargetEntity (not a hud function, oops).


int __cdecl GScr_SetTargetEntity(int a1)
{
char *v1; // ebx@2
int v2; // ebx@3
int result; // eax@3
char v4; // al@5
int v5; // eax@5
int v6; // ebx@5

if ( HIWORD(a1) )
{
Scr_ObjectError("not an entity");
v1 = 0;
if ( v10C )
goto LABEL_3;
}
else
{
v1 = (char *)&g_entities + 508 * (unsigned __int16)a1;
if ( *((_DWORD *)v1 + 67) )
{
LABEL_3:
v2 = *((_DWORD *)v1 + 67);
result = Scr_GetEntity(0);
*(_DWORD *)(v2 + 16) = result;
return result;
}
}
v4 = SL_ConvertToString(*((_WORD *)v1 + 140));
v5 = va("entity type '%s' is not a turret", v4);
Scr_Error(v5);
v6 = *((_DWORD *)v1 + 67);
result = Scr_GetEntity(0);
*(_DWORD *)(v6 + 16) = result;
return result;
}

serthy
11th June 2015, 08:53
Nice




v1 = (char *)&g_entities + 508 * (unsigned __int16)a1;
if ( *((_DWORD *)v1 + 67) )

How do you know such things? (magic numbers etc)

Mitch
11th June 2015, 09:11
Nice



How do you know such things? (magic numbers etc)

I searched it that function name in the Mac binary. It contains all the functions names and more.

Edit: you only need the code within else curly brackets.

filthy_freak_
11th June 2015, 10:54
I searched it that function name in the Mac binary. It contains all the functions names and more.

Rawr. If I had known this I could have probably saved 10+ hours going through code.

EDIT: Could you upload the mac binaries for those of us that have never touched a mac?

Mitch
11th June 2015, 15:12
https://.../libcod/binaries.7z (https:/.../libcod/binaries.7z)
Contains both 1.0 binary for MP and SP.

guiismiti
11th June 2015, 17:50
Changing topic again, but still with the AC-130, not sure if I can solve this one.

I simply like the fire sounds from COD4, but I can't find them.
I know I can find the regular weapon sounds in the mod tools, but not the AC-130.

I found this, in a sound aliases file (common.csv) from the mod tools:


#AC-130 Weapon Sounds,,,,,,,,,,,,,,,,,,,,,,,
ac130_gunready,,null.wav,1,1,na,,,750,12000,auto,, ,,0.9,ac130,,,,,,,,
ac130_25mm_fire,,ac130/ac130_25mm_fire_rev01sh2.wav,0.37,0.37,explosion,0 .7,0.7,11500,12000,weapon2d,,,,0.9,ac130,,,,,,ac13 0weapon,,0.3
#ac130_25mm_fire,,ac130/ac130_25mm_fire_rev01sh2.wav,0.18,0.18,explosion,1 .1,1.1,11500,12000,weapon2d,,,,0.9,ac130,,,,,,,,0. 1
ac130_40mm_fire,,ac130/ac130_40mm_fire_c2.wav,0.75,0.8,explosion,0.85,0.9 5,11500,12000,weapon2d,,,,0.9,ac130,,,ac130_40mm_r eload,,,ac130weapon,,0.5
#ac130_40mm_fire,,weapons/test/ac130_40mm_fire_d1.wav,1,1,explosion,0.85,0.95,115 00,12000,weapon2d,,,,0.9,ac130,,,ac130_40mm_reload ,,,,,0.2
#ac130_40mm_fire,,weapons/50cal/weap_50cal_temp_v2.wav,1,1,explosion,0.9,0.9,11500 ,12000,weapon2d,,,,0.9,ac130,,,ac130_40mm_reload,, ,,,0.2
#ac130_40mm_fire,,ac130/ac130_40mm_fire_rev01.wav,0.21,0.21,explosion,1.25 ,1.35,11500,12000,weapon2d,,,,0.9,ac130,,,ac130_40 mm_reload,,,,,0.2
ac130_105mm_fire,,ac130/ac130_105canon_fire.wav,0.45,0.45,explosion,0.7,0. 8,11500,12000,weapon2d,,,,0.9,ac130,,,ac130_105mm_ reload,,,ac130weapon,,0.65
#ac130_105mm_fire,,ac130/ac130_105canon_fire.wav,0.2,0.2,explosion,0.7,0.8, 11500,12000,weapon2d,,,,0.9,ac130,,,ac130_105mm_re load,,,,,0.4
ac130_40mm_reload,,ac130/ac130_40mm_reload.wav,0.3,0.3,explosion,0.95,1.05, 11500,12000,reload2d,,,,0.9,ac130,,,,,1000,ac130we apon,,
#ac130_40mm_reload,,ac130/ac130_40mm_reload.wav,0.12,0.12,explosion,0.95,1.0 5,11500,12000,reload2d,,,,0.9,ac130,,,,,1000,,,
ac130_105mm_reload,,ac130/ac130_105canon_reload.wav,0.7,0.7,explosion,0.9,0. 9,11500,12000,reload2d,,,,0.9,ac130,,,,,2000,ac130 weapon,,
#ac130_105mm_reload,,ac130/ac130_105canon_reload.wav,0.12,0.12,explosion,0.95 ,1.05,11500,12000,reload2d,,,,0.9,ac130,,,,,2000,, ,
ac130_weapon_switch,,user_interface/ui_text_beep1.wav,0.25,0.25,vehicle,1.5,1.6,500000 ,,local2,,,,0.9,ac130,,,,,,,,


Tried googling the wav file names, no success.

Anybody has any idea? It should be ripped somewhere.

IzNoGoD
11th June 2015, 18:56
wav files are compiled into the .ff and as far as i know there is no way to extract them again (unless you record them ingame ofcourse)
For stock sounds you could look in the raw/sound folder, but there is no ac130 folder in there

vanfreddy
11th June 2015, 19:15
http://wiki.modsrepository.com/index.php?title=Call_of_Duty_4:_Ripping_sounds
http://forum.drdteam.org/viewtopic.php?f=6&t=3735

filthy_freak_
12th June 2015, 04:25
http://tom-crowley.co.uk/downloads/

"Tom FastFile Extractor"

guiismiti
25th September 2015, 18:37
The only method that worked was the sounds ripping. The rest only worked for scripts.

Anyway, I'm uploading the sounds I got. Had to do some additional stuff, since cod wouldn't accept the sounds right after I saved them from Audacity, saying they were corrupted. Still had to convert them.
Also, couldn't get the 40mm fire sound (I'll try to make a mod for singleplayer, changing the ac130 ambient sound volume to zero, then record it).