Jump to content
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. Los Santos Drug Wars
      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

[Q] Lowering Niko's Max Health?


cp1dell
 Share

Recommended Posts

So I've been trying to increase the difficulty in GTA IV. Something on the scale of Red Dead Redemption or Max Payne 3 where on certain difficulties, the player can take as much damage as an NPC. With some help, I threw together a small script that should limit Niko's health to 100 - where from what I have seen in the GTA IV Control Center Trainer, the default is 400, 4x the amount that a ped has.

 

 

namespace HardHealth{  using System;  using GTA;  public class Main : Script  {      public Main()      {          GTA.Native.Function.Call("SET_CHAR_MAX_HEALTH", Player, 100);      }  }}

 

 

For some reason though, I always get this message from the ScriptHook:

 

2013-05-08 23:31:47 - Error during NetHook.Tick:                     System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.                        at Scripting.NativeContext2.Invoke(SByte* name, NativeContext2* cxt)                        at GTA.Native.Function.BaseCall(String Name, Parameter[] Arguments)                        at GTA.Native.Function.Call(String Name, Parameter[] Arguments)                        at GTA.Native.Template.Invoke()                        at GTA.ScriptDomain.RemoteEvent(RemoteEventArgs ev)                        at GTA.ScriptDomain.ProcessRemoteEvents()                        at GTA.ScriptDomain.Tick()                        at GTA.NetHook.Tick()2013-05-08 23:31:48 -  ...successfully started script 'HardHealth.Main'!

 

 

But Niko's health stays the same, 4x the amount of a ped's. I even tried changing it to 25. I still receive the same message, and the max health does not change at all.

 

Is there something really obvious I am doing wrong? Is there a better function to use than SET_CHAR_MAX_HEALTH?

Link to comment
Share on other sites

Code is wrong. Should be:

 

//---FIRST - INCLUDEusing System;using GTA;// MORE CODE HERE CAN BE... example : using System.IO;//--- Everythink will get name like "HardHealth.GTA.Native...". Why it is important? We want script only run when we want this, no when //--- somebody run another script and make us sciprt with other script... I know, this is not good for big scripts and debuggers, but for //--- begginers it is enought.namespace HardHealth{//--- public class - class published for everyone, can be changed [ask google for private and protected] public class XYZ: Script {     //-- public XYZ - make here something what You want...  for more info write in google "class Main() : script public Main c#" or check     //http://www.msdn.microsoft.com/en-us/library/aa288463%28v=vs.71%29.aspx     public XYZ()     {        // MORE CODE HERE CAN BE...         GTA.Native.Function.Call("SET_CHAR_MAX_HEALTH", Player.Character, 100);     } }}

 

 

Remeber these things:

First - include [using in c#] first.

Seoncd - in C# if You want make something with player write "Player.Character".

Third - use Microsoft Visual Studio 2010 for writing script after including solutions of GTA [search at the forum about scriphook, there should be instruction how instal it and use this].

 

I do not tested, soo write here if error will still print.

Edited by Nevitro
Link to comment
Share on other sites

Sweet, thanks. Let me test it out.

 

Do I have to use Microsoft Visual Studio? Most .cs files I've done for other games were perfectly fine using Notepad.

 

EDIT: Weird, it still doesn't work. No errors or anything, it's as if the SET_CHAR_MAX_HEALTH doesn't really do anything. I'm using the fixed code:

 

using System;using GTA;namespace HardHealth{ public class Main : Script {     public Main()     {         GTA.Native.Function.Call("SET_CHAR_MAX_HEALTH", Player.Character, 25);     } }}

 

 

The reason I changed it to 25 is because it had no effect at 100, so I thought lowering it to 25 would gain the result I was looking for. No such luck.

Edited by cp1dell
Link to comment
Share on other sites

I prefer use Visual because You will not make chaos in script, will underline unuset bools etc. and shows everyhink what You want for example: I write "Player" and menu shows ".Character". It make writing scripts faster, belive me.

 

It looks game check this every second and You shiult put this in thick thread or interval...

 

Wait. I found this Native call is broken. I found "Player.Maxhealth = 25". Trying to get how it is working. Wait...

Edited by Nevitro
Link to comment
Share on other sites

Okey i found problem. Game just make self limit for everythink all time... If You want only 25 HP You should add little tick with "if". There is code [not tested but should work]:

 

using System;using GTA;namespace Life{public class Main : Script{    public Main()    {        this.Interval = 1;        this.Tick += new EventHandler(this.TICK_DO_ALL_TIME);    }    private void TICK_DO_ALL_TIME(object sender, EventArgs e)    {        if (Player.Character.Health > 25)        {            Player.Character.Health = 25;        }    }}}

 

 

You want comments?

Edit: i tired. I go sleep. Tommorow i will help You more if You want. Goodnight.

Edited by Nevitro
Link to comment
Share on other sites

Sweet, works perfectly man! Thank you so much!

 

I really appreciate it. I also threw in some lines for armor too. So now Niko has the same amount of health and armor as the peds. Maybe someday someone will be looking for the same thing like I was, and they'll stumble across this.

 

 

using System;using GTA;namespace HardHealth{public class Main : Script{   public Main()   {       this.Interval = 1;       this.Tick += new EventHandler(this.TICK_DO_ALL_TIME);   }   private void TICK_DO_ALL_TIME(object sender, EventArgs e)   {       if (Player.Character.Health > 25)       {           Player.Character.Health = 25;       }       if (Player.Character.Armor > 25)       {           Player.Character.Armor = 25;       }   }}}

 

Edited by cp1dell
Link to comment
Share on other sites

blowjobcumpussy

 

Sweet, works perfectly man! Thank you so much!

 

I really appreciate it. I also threw in some lines for armor too. So now Niko has the same amount of health and armor as the peds. Maybe someday someone will be looking for the same thing like I was, and they'll stumble across this.

 

 

namespace HardHealth{   using System;   using GTA;   public class Main : Script   {       public Main()       {           this.Tick += this.TICK_DO_ALL_TIME;       }       private void TICK_DO_ALL_TIME(object sender, EventArgs e)       {           if (Player.Character.Health > 25)           {               Player.Character.Health = 25;           }           if (Player.Character.Armor > 25)           {               Player.Character.Armor = 25;           }       }   }}

 

interval default is 0 and an acceptable value for a tick that is used to keep things updated, why even wait a ms??

 

also hooking a NEW event handler isnt necessary, compiler will do it and it makes code cleaner

 

and putting using statements inside the namespace i think is a better style and more logical to see everything contained in a namespace, unless of course u want multiple namespaces on 1 file and u want them to use same libraries, but nobody does that unless u want to break your mouse wheel scrolling all day

 

@Nevitro well that explains why setting max does nothing as the game changes soon after

Edited by blowjobcumpussy
Link to comment
Share on other sites

Wow, thank you so much guys. Well here's the final script. I threw in a few extra lines that regenerates your health up to 25 (since the max health is 50).

 

 

namespace HardHealth{  using System;  using GTA;  public class HardHealth : Script  {      public HardHealth()      {          this.Tick += this.TICK_DO_ALL_TIME;      }      private void TICK_DO_ALL_TIME(object sender, EventArgs e)      {          if (Player.Character.Health > 50)          {              Player.Character.Health = 50;          }          if (Player.Character.Armor > 50)          {              Player.Character.Armor = 50;          }          if (Player.Character.Health < 25)          {              Interval = 10000;              Player.Character.Health = 25;          }      }  }}

 

Link to comment
Share on other sites

Oh, sorry about that. I just wrote my scripts and saw many scripts with my structure [using, namespace, etc...] and I do not have mind it is bad.

Thanks for sign me this.

 

But about interval - test it. It is make script do less times than 0 [interval 1 = 1000 or less, interval 0 = more than 1000]. Mayby this is small issue, but for 20 scripts in game, this make big difference for smothly FPS. I just do not have big server with 10 GPUs etc. I just like fast game with scripts wink.gif

 

About eventhandler - You mean compiler = change name file in some folder to dll before compile in Visual? I make scripts in .cs for OpenSource and i think - Your code works without compile?

Tested - works.

 

Please reply smile.gif

Edited by Nevitro
Link to comment
Share on other sites

blowjobcumpussy

yes starting in .net 2.0 i read, u do not need to explicitly state the type of eventhandler as the compiler will know at runtime what to use, so u can simply hook the event and compiler will create correct eventhandler

 

for people that like to explicitly tell the compiler what eventhandler to use just because they like to see it with their own eyes then sure go ahead. Refactor tools like resharper will recommend removing this "extra code" as it is not necessary.

 

If you are actually going to save the event to an object of type of event handler then u would want to explicitly state but that is another situation

 

also when u counted ticks at intervals 0 and 1, when u say 0 had more than a thousand and 1 had less than a thousand, what period of time did u do that for? how did u measure time?

Edited by blowjobcumpussy
Link to comment
Share on other sites

Okey, the results isnt soo big how i think, but still sometimes it will help:

With this code:

 

namespace Life{using System;using GTA;public class Main : Script{ int x=0; bool doit=false;    public Main()    {    GTA.Native.Function.Call("SETTIMERC", 0);    Game.Console.Print("RUN TIMER ON");    this.Interval = 1;    this.Tick += this.TICK_DO_ALL_TIME;    }    private void TICK_DO_ALL_TIME(object sender, EventArgs e)    {    if (GTA.Native.Function.Call<int>("TIMERC")<1000)    {    x=x+1;    }    if (GTA.Native.Function.Call<int>("TIMERC")>1000 && doit ==false)    {    Game.Console.Print("X do in : "+x+" times");    doit = true;    }    }}}

 

... I got for many processors around, nearly 28 X. With interval 0 - 32 X. If You will had nearly more than 60 X with high use of CPU, You should not see big difference [mayby 61 with interval 0]. What is conclusion? For slowly computer it make better ... My comp do this script 28, less 4 times... And watch - if 10 script run, my computer will lost big amount of CPU to do things what i can't see, because 1 milisecond more it isn't have big difference for not precission script. That is why, i prefer add interval - computer will don't must calculate thing what will not have effect in gameplay.

 

To sum up, interval is very friendly for slowly PC. Tested on my PC ;D

Link to comment
Share on other sites

blowjobcumpussy

yeah ok makes sense for low end pc's as calculations from the cpu would reduce more significantly than a faster cpu where u would get almost no benefit, but be aware as your test can be flawed...

 

http://stackoverflow.com/questions/1153112...in-net-accurate

 

the operating system and jit compiler might put your code on hold sometimes and this will cause counting ticks for a specific time to always come up with different numbers, this method of testing does not guarantee each test is same amount of time

Edited by blowjobcumpussy
Link to comment
Share on other sites

That is why i used Game Timer, not my timer. [native call]

Game timer is working with game, soo if game fps will be high, timer will works faster. And if game will got 15 fps, that timer in GTA also be 'slower'.

My script make X in 1 sec in game, not in script.

That is difference smile.gif

 

Mayby You got right, soo, today i will try write a script which will test script running for interval 1, interval 0 and interval 10. smile.gif

 

Link to comment
Share on other sites

Alright, now I'm done adding changes to the script. Niko has the same amount of health as peds (like in Hardcore Red Dead Redemption) and the same regeneration rate in RDR.

 

 

namespace HardHealth{  using System;  using GTA;  public class HardHealth : Script  {      public HardHealth()      {          this.Interval = 33;          this.Tick += this.HealthCheck;      }      private void HealthCheck(object sender, EventArgs e)      {          if (Player.Character.Health > 25)          {              Player.Character.Health = 25;          }          if (Player.Character.Armor > 25)          {              Player.Character.Armor = 25;          }          if (Player.Character.Health < 25)          {              Interval = 5000;              Player.Character.Health += 4;          }      }  }}

 

 

One question, is there any way to edit the amount of health the healthbar displays as "full?" Since this caps the player's health at 25, it's always a little flashing red bar that only takes up a quarter of the radar. Is there any way to edit a default file, or functions that would make it take up the whole radar instead?

Link to comment
Share on other sites

I haven't tested it so I'm not entirely sure, but I think you can just change the ped stats data to increase Niko's damage weakness (so he'd get 2x or 4x damage) that way, you'd have exact same result as changing his HP to lower.

Edited by lolleroz
Link to comment
Share on other sites

That would be a better solution, that way Niko could still take the amount of fall damage he's supposed to, and doesn't burn too quick from moltovs, and other stuff. I tried editing his Defense in pedpersonality.dat, but it didn't have any effect.

 

 

# Modelname      Sex    Age    Sexiness   Bravery     Attack   Defend   Agility   MeleeMartialLevelPercent   1stLanguage  2ndLanguage  Tickboxesplayer,   M,   30,   3,   5,   1,   0.4,   5,   50,   E,   E,   core_moves,   hits_pool,   unarmed_player,   counters_player,   firearm_core,   ground_player,   -,   move_melee,   +cancarryweapons

 

Link to comment
Share on other sites

Could you try changing the value to something like -50.0 just for the test?

Link to comment
Share on other sites

The best result should be editing weaponinfo...

 

But if You want in code...

 

You can just make secondary bar for Your mod... including falling, "isonfire" etc.

Or just make white circle, set center point, rotate this and change size when player got small health or more...

 

Many things can do, but what is the best ?

I think to find in files what weapon do damage for player, and change dmg for him...

Link to comment
Share on other sites

That's a really poor solution since first of all it makes the car damage unbalanced (a Huntley blowing up after single pistol magazine etc) and makes peds even more easy to kill

Link to comment
Share on other sites

Heh, or mayby just "Getallpeds" and for every 1 sec give them 800 HP? biggrin.gif [player wll have 1/4 ;D ]

 

?? smile.gif

Link to comment
Share on other sites

 

Could you try changing the value to something like -50.0 just for the test?

My internet has been f*cking me around for the past few days, sorry I haven't been able to get back to you. Sure, I'll try that right now. Hopefully afterwards I can update you on the results.

 

EDIT: No effect.

Edited by cp1dell
Link to comment
Share on other sites

So, the best way to make health up for everyone around... but if player unarmed - for peds around 5 meters... with som,e gun - 200... Get all peds or get peds in area, and after that make "foreach"...

Link to comment
Share on other sites

Giving peds more health instead of taking away Niko's health would be a good alternative. It would be like playing online where everyone has lots of health.

 

There's also the fact that Darko takes twelve shots in the execution and is still breathing, so I don't see the problem in giving peds as much health as Niko. I'll see what I can put together.

 

EDIT: Alright, I got a script working. I don't know how HippieCommunist does it with his zombies, but the peds with my script regenerate their health every tick instead of it being set once.

 

 

namespace ToughPeds{  using System;  using GTA;  public class ToughPeds : Script  {      public ToughPeds()      {          this.Interval = 1000;          this.Tick += this.ToughenPed;      }      private void ToughenPed(object sender, EventArgs e)      {          GTA.Ped[] pedArray = GTA.World.GetPeds(Player.Character.Position.Around(9.0f), 455.9F, 40);          foreach (Ped npc in pedArray)          {              if (npc.Exists() && npc != null)              {                 npc.Health = 400;              }           }      }  }}

 

 

EDIT: Is there a way to have a tick going, but the function to apply only once to each ped?

Edited by cp1dell
Link to comment
Share on other sites

  • 2 months later...

Okay, so I'm still trying to lower Niko's health. I've been using a script that just takes away -75 if it's over 25HP - but it makes the HUD look weird (just a constant small red, flashing bar) and can mess with other scripts. It would be much more efficient if I could change the max health from 100 (or whatever the hell it is) to 25 (the same amount as a ped).

 

I've been using

 

Gta.Native.Function.Call("SET_CHAR_MAX_HEALTH"), Player, 25)

 

and

 

Gta.Native.Function.Call("SET_CHAR_MAX_HEALTH"), Player.Character, 25)

 

 

But neither work. I'm starting to think that this is a broken function or something. Somehow HippieCommunist was able to raise pedestrian's max health for his zombie script, but I haven't figured out how to do so for the player.

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.