Jump to content
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. The Criminal Enterprises
      2. Updates
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Red Dead Online

      1. Blood Money
      2. Frontier Pursuits
      3. Find Lobbies & Outlaws
      4. Help & Support
    3. Crews

    1. Grand Theft Auto Series

      1. Bugs*
      2. St. Andrews Cathedral
    2. GTA VI

    3. GTA V

      1. Guides & Strategies
      2. Help & Support
    4. GTA IV

      1. The Lost and Damned
      2. The Ballad of Gay Tony
      3. Guides & Strategies
      4. Help & Support
    5. GTA San Andreas

      1. Classic GTA SA
      2. Guides & Strategies
      3. Help & Support
    6. GTA Vice City

      1. Classic GTA VC
      2. Guides & Strategies
      3. Help & Support
    7. GTA III

      1. Classic GTA III
      2. Guides & Strategies
      3. Help & Support
    8. Portable Games

      1. GTA Chinatown Wars
      2. GTA Vice City Stories
      3. GTA Liberty City Stories
    9. Top-Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    1. Red Dead Redemption 2

      1. PC
      2. Help & Support
    2. Red Dead Redemption

    1. GTA Mods

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Red Dead Mods

      1. Documentation
    3. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    4. Featured Mods

      1. Design Your Own Mission
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Rockstar Games

    2. Rockstar Collectors

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Movies & TV
      5. Music
      6. Sports
      7. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. Announcements

    2. Support

    3. Suggestions

*DO NOT* SHARE MEDIA OR LINKS TO LEAKED COPYRIGHTED MATERIAL. Discussion is allowed.

Simulating TBOGT explosive shotgun in vanilla IV


TempleOfLight
 Share

Recommended Posts

Not more than two days ago, I stumbled upon Lorenzo3024's EFLC weapons pack for the IV base game, which I downloaded instantly, knowing it would breathe some new life back into a game we all already love. It absolutely did, and I've been having a whole lot of new fun shooting heads up with AA12s and P90s so far. There's still a problem making this pack less enjoyable by a good amount, though : The closest people have come so far to replicating the "explosive rounds" effect of the TBOGT AA12 via WeaponInfo editing was by making it shoot actual rockets, which somewhat gets the job done, but is totally ridiculous when it comes to damage and realism, obviously. Despite the initial bummer, I thought this was exactly one of the classic cases where scripting was the solution, and decided to try my hand at it with my extremely limited C# knowledge ;)

 

------------------------------

 

namespace ExplosiveShotgun
{
using System;
using System.Drawing;
using System.Windows.Forms;
using GTA;

public class Main : Script
{
public Main()
{
Tick += ShotgunCheck_Tick;
}
private void ShotgunCheck_Tick(object sender, EventArgs e)
{
if (Player.Character.Weapons.CurrentType == Weapon.Episodic_10)
{
Ped[] pedArray = World.GetPeds(Player.Character.Position, 50f);
foreach (Ped pede in pedArray)
{
if (pede.HasBeenDamagedBy(Player.Character.Weapons.CurrentType))
{
GTA.Native.Function.Call("ADD_EXPLOSION", pede.Position.X, pede.Position.Y, pede.Position.Z, 16, 1f, true, true, 0f);
GTA.Native.Function.Call("TRIGGER_PTFX", "exp_molotov", pede.Position.X, pede.Position.Y, pede.Position.Z, 0, 0, 0, 1.0f);
GTA.Native.Function.Call("CLEAR_CHAR_LAST_WEAPON_DAMAGE", pede);
}
}
}
}
}
}

 

-------------------------------

 

Wanna know something funny about it? Despite how incredibly clunky and clumsy this small code is looking, it actually does the job rather well. To me, there's still the HUGE downside of it not really relying on "bullets" per se and only triggering explosions on damaged peds, which is far from being good enough to be decent looking in-game :(

 

I came up with a way to make it somewhat actually detect bullet collision, which is normally not something possible due to the lack of appropriate native functions for that, from what I understood, but this is something I thought maybe some of you people would be interested in messing around with :

- Instead of detecting damaged peds, detecting if the player is aiming and using the isFiring bool to determine when script actions should be done

- If the conditions are fulfilled, get where the player is aiming (This is where I'm completely stuck, unfortunately. Is there any way to natively detect the position of the crosshair on-screen? If not, I'm assuming there are still ways this could be done, like getting screen center coordinates or using a combination of Player.Character.Heading and CurrentCamera.Position, but this is too far beyond my scripting knowledge)

- Create a small object at that position (think apple, knife, dart or something to that effect), make it invisible and apply forward force to it sufficient for it to travel in a straight line at bullet speed.

- Set it to trigger an explosion and delete itself upon colliding with anything else.

 

All in all, I know I'm oversimplying this and that this is probably much more complicated than I'm making it sound, but I know this is within the grasp of a lot of experienced coders out there, which is why I'm reaching out to the community. Needless to say, I'd appreciate it IMMENSELY if you guys tried to work something out with this and tried to get closer to the way this weapon behaves in TBOGT. Thanks in advance, and keep up the good work.

 

By the way, I wrote it to work with Lorenzo's weapon pack in mind. If you want to make that particular script work the unedited WeaponInfo.xml and explosionfx.dat files, just replace Weapon.Episodic_10 with the vanilla shotgun along with the ADD_EXPLOSION parameter (16 is not going to work with vanilla, but 7 does the job pretty well). Have fun with this.

Edited by TempleOfLight
Link to comment
Share on other sites

I've actually tried this exact same thing, but ran into some problems, quit developing it, and soon forgot about it. Now that you reminded me, I'll try and fix those problems ;)

  • Like 1
Link to comment
Share on other sites

the problem with detecting if ur shooting another ped is where ur aiming is not a single location but a bunch of locations on a straight line coming from the direction of the camera so to get where the player is aiming and check for potential targets requires u to loop like this (not perfect but just an example)...

 

also this may lag the game and u need to make more efficient... oh an another thought, this code does not keep checking if it finds a ped and misses their bone... so technically ud have to jump back into the loop looking for peds, obviously this would need to be rewritten but this is the idea and yeah u can just fire an invisible object by applying force to it and detecting it's collision, i made a rocket launcher doing this except i added like 50 more explosions >:D

const float WEAPON_RANGE = 50f;...Ped target = null;for (Vector3 position = Game.CurrentCamera.Position; position.DistanceTo(Game.CurrentCamera.Position) < WEAPON_RANGE; position += Game.CurrentCamera.Direction){    foreach (Ped ped in World.GetPeds(position, 1f))//1f might be too large radius, u probably need to check if ur aiming at a bone too so get bone positions when target is found    {        if (Game.Exists(ped) && ped.isAliveAndWell)        {            target = ped; break;        }    }    if (Game.Exists(target)) break;} if (!Game.Exists(target)) return; bool hit = false;foreach (Bone bone in (Bone[])Enum.GetValues(typeof(Bone))){    Vector3 bonePos = target.GetBonePosition(bone);    //i would check the position returned before proceeding, u may need to continue if it is a bone that does not exist, not all bones exist on peds in that enum    if (bonePos.DistanceTo(Game.CurrentCamera.Position + Game.CurrentCamera.Direction * Game.CurrentCamera.Position.DistanceTo(bonePos)) < 0.1f)//different bones may require larger or smaller for another layer of accuracy    {        hit = true;        break;    }}if (hit) target.AttachBlip();
Edited by byteMe420
Link to comment
Share on other sites

Ah, I see. This way of doing it is insanely complex, though, damnit, haha. I can almost feel my framerate being reduced by half just reading that code. Thanks for the tip, though, man. I'll be sure to save that piece of code for later use. Do you happen to have that rocket launcher script still sitting on your hard drive somewhere, by the way? I'd appreciate looking into the code you wrote. Firing invisible objects sounds much more like my style, if you ask me ;p

Link to comment
Share on other sites

Ah, I see. This way of doing it is insanely complex, though, damnit, haha. I can almost feel my framerate being reduced by half just reading that code. Thanks for the tip, though, man. I'll be sure to save that piece of code for later use. Do you happen to have that rocket launcher script still sitting on your hard drive somewhere, by the way? I'd appreciate looking into the code you wrote. Firing invisible objects sounds much more like my style, if you ask me ;p

the code basically travels in a straight line in the direction of the camera searching for peds each step of the way, when it finds a ped then it tries to determine which bone the camera is pointing at... it needs some editing but that is the idea

Big scripts reduce FPS? I didn't know that, or at least never experienced it.

doing loops in loops and a bunch of calcs can cause the game to lag depending what ur doing, actually the code i wrote shouldnt be noticeable each tick... u can loop all peds very quick if not checking too many things each one

Link to comment
Share on other sites

i know if we used World.GetAllPeds then The Game will extremely Lag. julio said that

I wouldn't say extremely. I've used that many times and it doesn't lag too bad.
Link to comment
Share on other sites

i know if we used World.GetAllPeds then The Game will extremely Lag. julio said that

Again what ? :DDD (died.)

 

Of course it would lag if in 1 m³(maths) is more that 3 peds(very high density).

Also I put wait(0); after each(Thanks byteme420). It helps from lag.

 

Best regards,

Paul.

Link to comment
Share on other sites

 

i know if we used World.GetAllPeds then The Game will extremely Lag. julio said that

Again what ? :DDD (died.)

 

Of course it would lag if in 1 m³(maths) is more that 3 peds(very high density).

Also I put wait(0); after each(Thanks byteme420). It helps from lag.

 

Best regards,

Paul.

 

u can loop all peds no problem every tick... zero lag... if ur just checking some property values and setting some properties it is fast

i know if we used World.GetAllPeds then The Game will extremely Lag. julio said that

julio is wrong or you did not understand what he said correctly

Edited by byteMe420
Link to comment
Share on other sites

Unless this function's implementation is horribly slow, but something would have to be real f*cked up in it then.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.