UGX-Mods

Call of Duty 5: World at War => Help Desk => Scripting => Topic started by: fanmagic on August 05, 2016, 10:07:54 am

Title: Weapon impact
Post by: fanmagic on August 05, 2016, 10:07:54 am
How can i get the impact point of a weapon?
Title: Re: Weapon impact
Post by: Soy-Yo on August 05, 2016, 10:29:50 am
Wait until the player shots and use this:
Code Snippet
Plaintext
trace = bulletTrace( <start>, <end>, <hit characters>, <ignore entity> );
impact_point = trace[ "position" ];
Use for <start> the eye of the player (player getEye()), and for <end> a far point in front of the player.

At least this is what I did.

If you want the entity hit use:
Code Snippet
Plaintext
entity = trace[ "entity" ];
Title: Re: Weapon impact
Post by: alaurenc9 on August 05, 2016, 10:57:02 am
Wait until the player shots and use this:
Code Snippet
Plaintext
trace = bulletTrace( <start>, <end>, <hit characters>, <ignore entity> );
impact_point = trace[ "position" ];
Use for <start> the eye of the player (player getEye()), and for <end> a far point in front of the player.

At least this is what I did.

If you want the entity hit use:
Code Snippet
Plaintext
entity = trace[ "entity" ];
Well this isn't necessarily true because there is bullet spread, which you can manually script to perfect accuracy, but bullet spread is random meaning the actual weapon can hit in one point within the spread while your script could end up hitting another.
Title: Re: Weapon impact
Post by: Soy-Yo on August 05, 2016, 11:16:10 am
Well this isn't necessarily true because there is bullet spread, which you can manually script to perfect accuracy, but bullet spread is random meaning the actual weapon can hit in one point within the spread while your script could end up hitting another.
Yeah, that's right. Didn't think in that. But that's the most accurate way I know... :(
Title: Re: Weapon impact
Post by: fanmagic on August 05, 2016, 01:05:40 pm
most weapons you want the impact of are "projectile" weapons. you can use waittill("projectile_impact", weapon, impact). Cant remember if it is exactly that, but cant check at work
I try to modify your wonderweapon script only to see if its work for me. But it doesnt.

Code Snippet
Plaintext
start()
{
    flag_wait("all_players_connected");
players = GetPlayers();
array_thread(players, ::weapon_fired);
}

weapon_fired()
{
self endon( "disconnect" );
self waittill( "spawned_player" );
for( ;; )
{
self waittill( "projectile_impact", weapon, impact );
if (weapon == "zombie_colt")
{
self thread impact_fx( impact );
}

}
}

impact_fx( impact )
{
bullet = spawn("script_model", impact);
bullet SetModel("tag_origin");
playfxontag( level._effect["ww"], bullet.origin );
bullet delete();
}
Title: Re: Weapon impact
Post by: BluntStuffy on August 05, 2016, 01:09:12 pm
did you make the colt into a projectile weapon? otherwise it will never work..
If you did, try without the waittill "spawned_player", depending on where you call it they might have allready spawned?
Title: Re: Weapon impact
Post by: fanmagic on August 05, 2016, 01:10:59 pm
did you make the colt into a projectile weapon? otherwise it will never work..
If you did, try without the waittill "spawned_player", depending on where you call it they might have allready spawned?
How can i do that?
Title: Re: Weapon impact
Post by: BluntStuffy on August 05, 2016, 01:19:18 pm
Drag weaponfile into UGX weapons editor and change type on first page to "projectile"

^
but, a projectile weapon makes crawlers, has splash damage and doesn't have bullet-penetration ( so just like the normal ray-gun ) so it might not Always suit your needs..
Title: Re: Weapon impact
Post by: fanmagic on August 05, 2016, 01:21:05 pm
Drag weaponfile into UGX weapons editor and change type on first page to "projectile"

Edit: I also recommend you use playfx( fx, origin) instead of spawning the ent and playingfxontag. No need to make an ent for that.
To further explain:
Playfxontag has the advantage of being played on an entity while it is defined. Delete the model and the fx will stop. Best for looping fx.
Playfx has the advantage of not needing an entity and is best with "one shot" fx. For anything static playfx is usually best
Thanks for the explanation. But now i get this error.
(https://picload.org/image/rrlowrpr/fhvhdh.jpg)
Title: Re: Weapon impact
Post by: fanmagic on August 05, 2016, 01:25:27 pm
Ahh forgot there is a bit of modifications needed for a projectile weapon in the settings. Open up the IWD for my Afterlife and look at my weaponfile. I can imagine you are trying to make a custom WW? Could also look at my Atomic Levitator weaponfile in my weapons. Typically I copy and paste the zombie_colt_upgraded and change the things I want to get the settings right
Yes. That's what i would like to make. Testing it now...


Double Post Merge: August 05, 2016, 01:42:52 pm
Works perfect now. Thanks. But how can i move the fx a little bit higher?
(https://picload.org/image/rrlowado/fhvhdh.jpg)
Title: Re: Weapon impact
Post by: Soy-Yo on August 05, 2016, 01:46:59 pm
Yes. That's what i would like to make. Testing it now...


Double Post Merge: August 05, 2016, 01:42:52 pm
Works perfect now. Thanks. But how can i move the fx a little bit higher?
(https://picload.org/image/rrlowado/fhvhdh.jpg)
Sum something to the impact_point:
Code Snippet
Plaintext
impact_point += ( 0, 0, z );
Title: Re: Weapon impact
Post by: alaurenc9 on August 05, 2016, 01:55:25 pm
Well if you make the colt a projectile weapon, it no longer does bullet damage. And you must set a speed for the bullet to reach it's target.... in other words it won't be instantaneous like a real life bullet. And you can't do penetration damage, where it goes through zombies.... you can only do impact damage to the first zombie and a radius damage after that. And the impact damage is just one set of damage, unlike bullets where you can set min/max damage and then distances, and it only gives you +50, so there is no headshot points or even a specified hit location to script it to give you headshot points, otherwise it would give you headshot points already. So what I'm saying is, don't try this.
Title: Re: Weapon impact
Post by: fanmagic on August 05, 2016, 02:10:10 pm
Everything works good now. Thanks to all :)

(https://picload.org/image/rrlowcld/fhvhdh.jpg)
Title: Re: Weapon impact
Post by: fanmagic on August 05, 2016, 02:16:30 pm
Predicting from what your fx looks like:
In order to move a zombie, you need to spawn and link a tag_origin to the zom. Move the link. Zombies cant be moved themselves
Ok. Can i use the move-part of your WW for my weapon?
Title: Re: Weapon impact
Post by: fanmagic on August 05, 2016, 02:27:51 pm
Any script of mine ever you have permission to use exactly, or in pieces. ESPECIALLY if you are trying to learn :)
Spoiler: click to open...
even if I felt otherwise I couldnt actually tell you that you cant because all my releases are public. Just remember to credit ;)

I also have code to do what you need that was meant for an upgrade to the atomic levitator. I can send that when I get home. It will be good to learn off of
Ok, sure. Thank you very much, Nate. :)
Title: Re: Weapon impact
Post by: StupidEdits on August 05, 2016, 03:16:07 pm
Off topic, but that fx looks familiar  ::)
Title: Re: Weapon impact
Post by: fanmagic on August 05, 2016, 03:26:38 pm
Off topic, but that fx looks familiar  ::)
Pretty cool fx ;)  :D
Title: Re: Weapon impact
Post by: fanmagic on August 07, 2016, 04:49:52 pm
Everything works fine, but when i restart the map the fx is'nt playing on the impact point and my script to kill the zombies doesnt work anymore. It's only working correct when i start the map again with 'map' or 'devmap'. Is it possible to fix this isue?

Spoiler: click to open...
Code Snippet
Plaintext
#include common_scripts\utility; 
#include maps\_utility;
#include maps\_zombiemode_utility;

main()
{
    flag_wait("all_players_connected");
level.max_frozen = 24;
    level.max_freeze_distance = 300;
players = GetPlayers();
array_thread(players, ::weapon_fired);
}

weapon_fired()
{
self endon( "disconnect" );
self waittill( "spawned_player" );
for( ;; )
{
self waittill( "projectile_impact", weapon, impact );
if (weapon == "zombie_colt")
{
self thread impact_fx( impact );
}

}
}

impact_fx( impact )
{
level.bullet = spawn("script_model", impact);
level.bullet SetModel("tag_origin");
playfx( level._effect["ww"], level.bullet.origin  + ( 0, 0, 40 ));
iprintlnbold("Play fx on tag");

zombs = GetAISpeciesArray( "axis", "all" );
    get_AI = zombs;
close_zoms = get_array_of_closest( impact, get_AI, undefined, level.max_frozen, level.max_freeze_distance );

move_them = [];
for( i = 0; i < close_zoms.size; i++ )
{
        if(IsDefined(close_zoms[i].in_the_ground) && close_zoms[i].in_the_ground == true)
{
            close_zoms[i] super_kill();
            continue;
        }
move_them[i] = spawn("script_model", close_zoms[i].origin);
move_them[i] SetModel("tag_origin");
close_zoms[i] LinkTo( move_them[i] );
move_them[i] thread zombie_wobble();
close_zoms[i] thread kill_zoms();
}

wait (6);
for( i = 0; i < close_zoms.size; i++ )
{
close_zoms[i] unLink( move_them[i] );
move_them[i] delete();
}

level.bullet delete();
}

zombie_wobble()
{
while (isdefined(self))
{
self moveTo(level.bullet.origin, .5, .05, .05);
waittime = randomfloatrange(2.5, 5);
yaw = RandomInt( 360 );
if( yaw > 300 )
{
yaw = 300;
}
else if( yaw < 60 )
{
yaw = 60;
}
yaw = self.angles[1] + yaw;
self rotateto ((-60 + randomint(120), yaw, -45 + randomint(90)), waittime, waittime * 0.5, waittime * 0.5);
wait randomfloat (waittime - 0.1);
self thread kill_zoms();
}
}

kill_zoms()
{
wait(1.5);
self DoDamage( self.maxhealth+666, self.origin );
iprintlnbold("7 is Love. 7 is Life.");
    self thread NotifyPlayersOnSpatter();
self hide();
thread GivePlayersScore(60);
wait(1.5); 
}

super_kill()
{
self DoDamage( self.maxhealth+666, self.origin );
    if(IsDefined(self.animname) && self.animname != "zombie_dog" || self.animname != "quad_zombie") {
        self thread NotifyPlayersOnSpatter();
    }
self hide();
    thread GivePlayersScore(60);
}

blur_vision()
{
self SetBlur(10.3, 1);
wait(1);
self SetBlur(0, 1);
}

wait_for_bloodspatter() {
    for(;;) {
       // self iprintlnbold("Waiting for spatter notify");
       self waittill("spatter", zomb);
       if(DistanceSquared(zomb.origin, self.origin) <= 120000) {
           self.spatter = 1;
           // self iprintlnbold("Should splatter");
           wait(1);
           // self iprintlnbold("Splatter should be done");
           self.splatter = 0;
       }
       else {
           continue;
       }
    }
}

NotifyPlayersOnSpatter() {
    players = GetPlayers();
    for(i=0;i<players.size;i++) {
        players[i] notify("spatter", self);
    }
}

GivePlayersScore(score) {
    players = GetPlayers();
    for(i=0;i<players.size;i++) {
        players[i] maps\_zombiemode_score::add_to_player_score(score*level.zombie_vars["zombie_point_scalar"]);
    }
}
Title: Re: Weapon impact
Post by: fanmagic on August 07, 2016, 05:01:51 pm
Delete your mod in appdata. Sometimes appdata doesnt get updated properly
Tried out 3 times. Doesn't work.
Title: Re: Weapon impact
Post by: Scobalula on August 07, 2016, 05:29:04 pm
Everything works fine, but when i restart the map the fx is'nt playing on the impact point and my script to kill the zombies doesnt work anymore. It's only working correct when i start the map again with 'map' or 'devmap'. Is it possible to fix this isue?

Spoiler: click to open...
Code Snippet
Plaintext
#include common_scripts\utility; 
#include maps\_utility;
#include maps\_zombiemode_utility;

main()
{
    flag_wait("all_players_connected");
level.max_frozen = 24;
    level.max_freeze_distance = 300;
players = GetPlayers();
array_thread(players, ::weapon_fired);
}

weapon_fired()
{
self endon( "disconnect" );
self waittill( "spawned_player" );
for( ;; )
{
self waittill( "projectile_impact", weapon, impact );
if (weapon == "zombie_colt")
{
self thread impact_fx( impact );
}

}
}

impact_fx( impact )
{
level.bullet = spawn("script_model", impact);
level.bullet SetModel("tag_origin");
playfx( level._effect["ww"], level.bullet.origin  + ( 0, 0, 40 ));
iprintlnbold("Play fx on tag");

zombs = GetAISpeciesArray( "axis", "all" );
    get_AI = zombs;
close_zoms = get_array_of_closest( impact, get_AI, undefined, level.max_frozen, level.max_freeze_distance );

move_them = [];
for( i = 0; i < close_zoms.size; i++ )
{
        if(IsDefined(close_zoms[i].in_the_ground) && close_zoms[i].in_the_ground == true)
{
            close_zoms[i] super_kill();
            continue;
        }
move_them[i] = spawn("script_model", close_zoms[i].origin);
move_them[i] SetModel("tag_origin");
close_zoms[i] LinkTo( move_them[i] );
move_them[i] thread zombie_wobble();
close_zoms[i] thread kill_zoms();
}

wait (6);
for( i = 0; i < close_zoms.size; i++ )
{
close_zoms[i] unLink( move_them[i] );
move_them[i] delete();
}

level.bullet delete();
}

zombie_wobble()
{
while (isdefined(self))
{
self moveTo(level.bullet.origin, .5, .05, .05);
waittime = randomfloatrange(2.5, 5);
yaw = RandomInt( 360 );
if( yaw > 300 )
{
yaw = 300;
}
else if( yaw < 60 )
{
yaw = 60;
}
yaw = self.angles[1] + yaw;
self rotateto ((-60 + randomint(120), yaw, -45 + randomint(90)), waittime, waittime * 0.5, waittime * 0.5);
wait randomfloat (waittime - 0.1);
self thread kill_zoms();
}
}

kill_zoms()
{
wait(1.5);
self DoDamage( self.maxhealth+666, self.origin );
iprintlnbold("7 is Love. 7 is Life.");
    self thread NotifyPlayersOnSpatter();
self hide();
thread GivePlayersScore(60);
wait(1.5); 
}

super_kill()
{
self DoDamage( self.maxhealth+666, self.origin );
    if(IsDefined(self.animname) && self.animname != "zombie_dog" || self.animname != "quad_zombie") {
        self thread NotifyPlayersOnSpatter();
    }
self hide();
    thread GivePlayersScore(60);
}

blur_vision()
{
self SetBlur(10.3, 1);
wait(1);
self SetBlur(0, 1);
}

wait_for_bloodspatter() {
    for(;;) {
       // self iprintlnbold("Waiting for spatter notify");
       self waittill("spatter", zomb);
       if(DistanceSquared(zomb.origin, self.origin) <= 120000) {
           self.spatter = 1;
           // self iprintlnbold("Should splatter");
           wait(1);
           // self iprintlnbold("Splatter should be done");
           self.splatter = 0;
       }
       else {
           continue;
       }
    }
}

NotifyPlayersOnSpatter() {
    players = GetPlayers();
    for(i=0;i<players.size;i++) {
        players[i] notify("spatter", self);
    }
}

GivePlayersScore(score) {
    players = GetPlayers();
    for(i=0;i<players.size;i++) {
        players[i] maps\_zombiemode_score::add_to_player_score(score*level.zombie_vars["zombie_point_scalar"]);
    }
}

Ideally instead of doing array thread you should set up 3 functions to wait for the player to connect and another to wait for the player to spawn, and one to wait for the player to fire, you should take a look at the Tesla script to see how it's done there.
Title: Re: Weapon impact
Post by: BluntStuffy on August 07, 2016, 05:31:57 pm
try removing the:

Code Snippet
Plaintext
	self waittill( "spawned_player" );

it's not really serving any purpose where it's placed anyway..

EDIT:

Ideally instead of doing array thread you should set up 3 functions to wait for the player to connect and another to wait for the player to spawn, and one to wait for the player to fire, you should take a look at the Tesla script to see how it's done there.

he's having the flag_wait in front, so all players should be connected so it shouldn't matter in this case..

It might also have to do with if you thread the script from mapname.gsc or _zombiemode.gsc btw, but first just try removing the wait like i mentioned above