Quantcast

Jump to content

» «
Photo

[Q] Lowering Niko's Max Health?

24 replies to this topic
cp1dell
  • cp1dell

    Ghetto Star

  • Members
  • Joined: 04 Jul 2008

#1

Posted 09 May 2013 - 03:39 AM

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.

CODE
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:
CODE
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?

Nevitro
  • Nevitro

    Modder

  • Members
  • Joined: 31 Mar 2009

#2

Posted 09 May 2013 - 09:54 PM Edited by Nevitro, 09 May 2013 - 10:16 PM.

Code is wrong. Should be:
CODE

//---FIRST - INCLUDE
using 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.

cp1dell
  • cp1dell

    Ghetto Star

  • Members
  • Joined: 04 Jul 2008

#3

Posted 09 May 2013 - 10:03 PM Edited by cp1dell, 09 May 2013 - 10:13 PM.

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:
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.

Nevitro
  • Nevitro

    Modder

  • Members
  • Joined: 31 Mar 2009

#4

Posted 09 May 2013 - 10:18 PM Edited by Nevitro, 09 May 2013 - 10:39 PM.

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...

cp1dell
  • cp1dell

    Ghetto Star

  • Members
  • Joined: 04 Jul 2008

#5

Posted 09 May 2013 - 10:41 PM

EDIT: Alright.

Nevitro
  • Nevitro

    Modder

  • Members
  • Joined: 31 Mar 2009

#6

Posted 09 May 2013 - 11:03 PM Edited by Nevitro, 09 May 2013 - 11:11 PM.

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]:
CODE

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.

cp1dell
  • cp1dell

    Ghetto Star

  • Members
  • Joined: 04 Jul 2008

#7

Posted 09 May 2013 - 11:39 PM Edited by cp1dell, 10 May 2013 - 12:16 AM.

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.

CODE
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;
       }
   }
}
}

blowjobcumpussy
  • blowjobcumpussy

    Player Hater

  • BUSTED!
  • Joined: 10 May 2013

#8

Posted 10 May 2013 - 01:22 AM Edited by blowjobcumpussy, 10 May 2013 - 01:36 AM.

QUOTE (cp1dell @ Thursday, May 9 2013, 23:39)
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.

CODE
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

cp1dell
  • cp1dell

    Ghetto Star

  • Members
  • Joined: 04 Jul 2008

#9

Posted 10 May 2013 - 03:12 AM

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).

CODE
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;
          }
      }
  }
}

Nevitro
  • Nevitro

    Modder

  • Members
  • Joined: 31 Mar 2009

#10

Posted 10 May 2013 - 05:09 AM Edited by Nevitro, 10 May 2013 - 05:14 AM.

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

blowjobcumpussy
  • blowjobcumpussy

    Player Hater

  • BUSTED!
  • Joined: 10 May 2013

#11

Posted 10 May 2013 - 07:35 AM Edited by blowjobcumpussy, 10 May 2013 - 07:49 AM.

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?

Nevitro
  • Nevitro

    Modder

  • Members
  • Joined: 31 Mar 2009

#12

Posted 10 May 2013 - 08:54 AM

Okey, the results isnt soo big how i think, but still sometimes it will help:
With this code:
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

blowjobcumpussy
  • blowjobcumpussy

    Player Hater

  • BUSTED!
  • Joined: 10 May 2013

#13

Posted 11 May 2013 - 01:23 AM Edited by blowjobcumpussy, 11 May 2013 - 01:29 AM.

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...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

Nevitro
  • Nevitro

    Modder

  • Members
  • Joined: 31 Mar 2009

#14

Posted 11 May 2013 - 08:54 AM

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

cp1dell
  • cp1dell

    Ghetto Star

  • Members
  • Joined: 04 Jul 2008

#15

Posted 11 May 2013 - 01:23 PM

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.

CODE
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?

lolleroz
  • lolleroz

    Homeboy

  • Members
  • Joined: 29 Jul 2010
  • None

#16

Posted 11 May 2013 - 01:33 PM Edited by lolleroz, 11 May 2013 - 04:26 PM.

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.

cp1dell
  • cp1dell

    Ghetto Star

  • Members
  • Joined: 04 Jul 2008

#17

Posted 11 May 2013 - 01:53 PM

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.

CODE
# Modelname      Sex    Age    Sexiness   Bravery     Attack   Defend   Agility   MeleeMartialLevelPercent   1stLanguage  2ndLanguage  Tickboxes
player,   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

lolleroz
  • lolleroz

    Homeboy

  • Members
  • Joined: 29 Jul 2010
  • None

#18

Posted 11 May 2013 - 04:27 PM

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

Nevitro
  • Nevitro

    Modder

  • Members
  • Joined: 31 Mar 2009

#19

Posted 11 May 2013 - 04:42 PM

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...

lolleroz
  • lolleroz

    Homeboy

  • Members
  • Joined: 29 Jul 2010
  • None

#20

Posted 11 May 2013 - 05:00 PM

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

Nevitro
  • Nevitro

    Modder

  • Members
  • Joined: 31 Mar 2009

#21

Posted 11 May 2013 - 05:29 PM

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

?? smile.gif

cp1dell
  • cp1dell

    Ghetto Star

  • Members
  • Joined: 04 Jul 2008

#22

Posted 13 May 2013 - 12:39 AM Edited by cp1dell, 13 May 2013 - 01:59 AM.

QUOTE (lolleroz @ Saturday, May 11 2013, 16:27)
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.

Nevitro
  • Nevitro

    Modder

  • Members
  • Joined: 31 Mar 2009

#23

Posted 13 May 2013 - 11:59 AM

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"...

cp1dell
  • cp1dell

    Ghetto Star

  • Members
  • Joined: 04 Jul 2008

#24

Posted 13 May 2013 - 08:31 PM Edited by cp1dell, 16 May 2013 - 07:47 PM.

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.

CODE
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?

cp1dell
  • cp1dell

    Ghetto Star

  • Members
  • Joined: 04 Jul 2008

#25

Posted 01 August 2013 - 06:13 PM

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
CODE
Gta.Native.Function.Call("SET_CHAR_MAX_HEALTH"), Player, 25)

and
CODE
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.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users