Jump to content

[C#] Adding a script to random ped


Recommended Posts

Hello,

 

I'm trying to invoke native scripts from my script.
Here I want to add "pb_homeless" script to TracyDisanto model.

 

However, it doesn't do anything.

I wrote code to play anims and scenarios and it works fine, but I can't figure out how to add brain (script) to peds.

 

Natives I'm using:
void REQUEST_SCRIPT(char *scriptName)

For a dull list of scripts, see here: pastebin.com/yLNWicUi

void ADD_SCRIPT_TO_RANDOM_PED(char *name, Hash model, float p2, float p3)

ex.: BRAIN::ADD_SCRIPT_TO_RANDOM_PED("pb_prostitute", ${s_f_y_hooker_01}, 100, 0);

if (e.Control && e.Shift && e.KeyCode == Keys.D){    Ped player = Game.Player.Character;    GTA.Native.Function.Call(GTA.Native.Hash.REQUEST_SCRIPT, "pb_homeless");    while(!GTA.Native.Function.Call<bool>(GTA.Native.Hash.HAS_SCRIPT_LOADED, "pb_homeless")) {        Wait(20);    }    UI.Notify("HAS_SCRIPT_LOADED: " + GTA.Native.Function.Call<bool>(GTA.Native.Hash.HAS_SCRIPT_LOADED, "pb_homeless")); // true    UI.Notify("DOES_SCRIPT_EXIST: " + GTA.Native.Function.Call<bool>(GTA.Native.Hash.DOES_SCRIPT_EXIST, "pb_homeless")); // true    Model model = new Model(PedHash.TracyDisanto);    GTA.Math.Vector3 spawnPos = player.Position + (player.ForwardVector * 5);    Ped hooker = GTA.World.CreatePed(model, spawnPos);    GTA.Native.Function.Call(GTA.Native.Hash.ADD_SCRIPT_TO_RANDOM_PED, "pb_homeless", model, 100, 0);    GTA.Native.Function.Call(GTA.Native.Hash.REGISTER_OBJECT_SCRIPT_BRAIN, "pb_homeless", model, 100, 4.0, -1, 9);    GTA.Native.Function.Call(GTA.Native.Hash.START_NEW_SCRIPT, "pb_homeless", 5000);            }

Can you help me to understand invoking native scripts?

Can you point out code problems?

Can you give some links on this? I didn't found much, though I looked a lot.

 

Any response welcome! Thanks in advance :)

Edited by eseas
Link to comment
https://gtaforums.com/topic/880398-c-adding-a-script-to-random-ped/
Share on other sites

Hello,

 

I'm trying to invoke native scripts from my script.

Here I want to add "pb_homeless" script to TracyDisanto model.

 

However, it doesn't do anything.

I wrote code to play anims and scenarios and it works fine, but I can't figure out how to add brain (script) to peds.

 

Natives I'm using:

void REQUEST_SCRIPT(char *scriptName)

For a dull list of scripts, see here: pastebin.com/yLNWicUi

void ADD_SCRIPT_TO_RANDOM_PED(char *name, Hash model, float p2, float p3)

ex.: BRAIN::ADD_SCRIPT_TO_RANDOM_PED("pb_prostitute", ${s_f_y_hooker_01}, 100, 0);

if (e.Control && e.Shift && e.KeyCode == Keys.D){    Ped player = Game.Player.Character;    GTA.Native.Function.Call(GTA.Native.Hash.REQUEST_SCRIPT, "pb_homeless");    while(!GTA.Native.Function.Call<bool>(GTA.Native.Hash.HAS_SCRIPT_LOADED, "pb_homeless")) {        Wait(20);    }    UI.Notify("HAS_SCRIPT_LOADED: " + GTA.Native.Function.Call<bool>(GTA.Native.Hash.HAS_SCRIPT_LOADED, "pb_homeless")); // true    UI.Notify("DOES_SCRIPT_EXIST: " + GTA.Native.Function.Call<bool>(GTA.Native.Hash.DOES_SCRIPT_EXIST, "pb_homeless")); // true    Model model = new Model(PedHash.TracyDisanto);    GTA.Math.Vector3 spawnPos = player.Position + (player.ForwardVector * 5);    Ped hooker = GTA.World.CreatePed(model, spawnPos);    GTA.Native.Function.Call(GTA.Native.Hash.ADD_SCRIPT_TO_RANDOM_PED, "pb_homeless", model, 100, 0);    GTA.Native.Function.Call(GTA.Native.Hash.REGISTER_OBJECT_SCRIPT_BRAIN, "pb_homeless", model, 100, 4.0, -1, 9);    GTA.Native.Function.Call(GTA.Native.Hash.START_NEW_SCRIPT, "pb_homeless", 5000);            }

Can you help me to understand invoking native scripts?

Can you point out code problems?

Can you give some links on this? I didn't found much, though I looked a lot.

 

Any response welcome! Thanks in advance :)

 

I can't help because i've never actually tried to do this. But have you gone through the decompiled scripts to see exactly how rockstar is doing it?

Function.Call(Hash.ADD_SCRIPT_TO_RANDOM_PED, "pb_prostitute", Function.Call<int>(Hash.GET_HASH_KEY, "s_f_y_hooker_01"), 100, 0);

Function.Call(Hash.ADD_SCRIPT_TO_RANDOM_PED, "pb_prostitute", Function.Call<int>(Hash.GET_HASH_KEY, "s_f_y_hooker_02"), 100, 0);

Function.Call(Hash.ADD_SCRIPT_TO_RANDOM_PED, "pb_prostitute", Function.Call<int>(Hash.GET_HASH_KEY, "s_f_y_hooker_03"), 100, 0);

 

These are times the functions are used in the "standard_global_init" script. I suggest using "GET_HASH_KEY". I added that script to "ig_lamar" and it seemed to work.

Function.Call(Hash.ADD_SCRIPT_TO_RANDOM_PED, "pb_prostitute", Function.Call<int>(Hash.GET_HASH_KEY, "s_f_y_hooker_01"), 100, 0);

Function.Call(Hash.ADD_SCRIPT_TO_RANDOM_PED, "pb_prostitute", Function.Call<int>(Hash.GET_HASH_KEY, "s_f_y_hooker_02"), 100, 0);

Function.Call(Hash.ADD_SCRIPT_TO_RANDOM_PED, "pb_prostitute", Function.Call<int>(Hash.GET_HASH_KEY, "s_f_y_hooker_03"), 100, 0);

 

These are times the functions are used in the "standard_global_init" script. I suggest using "GET_HASH_KEY". I added that script to "ig_lamar" and it seemed to work.

Thanks for reply. It seems like it should works as simple as that.

I've looked at it in standard_global_init and it looks like it should work but it doesn't.

 

Could you give a little more code where you added script to ig_lamar?

Do you spawn ig_lamar in regular way or after ADD_SCRIPT_TO_RANDOM_PED? Or in some different way?

Right now my script: (doesn't work)

if (e.Control && e.Shift && e.KeyCode == Keys.E){    UI.Notify("GTA Forums help applied");    Ped player = Game.Player.Character;    GTA.Native.Function.Call(GTA.Native.Hash.REQUEST_SCRIPT, "pb_prostitute");    while (!GTA.Native.Function.Call<bool>(GTA.Native.Hash.HAS_SCRIPT_LOADED, "pb_prostitute"))    {        Wait(20);    }    GTA.Math.Vector3 spawnPos = player.Position + (player.ForwardVector * 5);    Ped hooker = GTA.World.CreatePed(new Model(PedHash.Hooker01SFY), spawnPos);    Function.Call(Hash.ADD_SCRIPT_TO_RANDOM_PED, "pb_prostitute", Function.Call<int>(Hash.GET_HASH_KEY, "s_f_y_hooker_01"), 100, 0);    Function.Call(Hash.ADD_SCRIPT_TO_RANDOM_PED, "pb_prostitute", Function.Call<int>(Hash.GET_HASH_KEY, "s_f_y_hooker_02"), 100, 0);    Function.Call(Hash.ADD_SCRIPT_TO_RANDOM_PED, "pb_prostitute", Function.Call<int>(Hash.GET_HASH_KEY, "s_f_y_hooker_03"), 100, 0);        Ped hooker1 = GTA.World.CreatePed(new Model(PedHash.Hooker01SFY), spawnPos);    Ped hooker2 = GTA.World.CreatePed(new Model(PedHash.Hooker02SFY), spawnPos);    Ped hooker3 = GTA.World.CreatePed(new Model(PedHash.Hooker03SFY), spawnPos);}

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
  • 0 User Currently Viewing
    0 members, 0 Anonymous, 0 Guests

×
×
  • Create New...

Important Information

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