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

need C# help please


ShadowCoderKing
 Share

Recommended Posts

ShadowCoderKing

im making a script that places objects and peds and cars at coords but nothing shows up at all what did i do wrong ?

using GTA;using System;using System.Collections.Generic;using System.Threading.Tasks;using GTA.Native;using System.Windows.Forms;using GTA.Math;public class Armybase : Script{    public Armybase()    {        Tick += OnTick;        KeyDown += OnKeyDown;        KeyUp += OnKeyUp;        Interval = 10;    }    void OnTick(object sender, EventArgs e)    {            }    void OnKeyDown(object sender, KeyEventArgs e)    {        }    void OnKeyUp(object sender, KeyEventArgs e)    {        if(e.KeyCode == Keys.F11)        {                        GTA.World.CreateProp(new Model(276224379), new GTA.Math.Vector3(2033.644f, 2830.369f, 49.30626f), new GTA.Math.Vector3(0f, 0f, -16.99992f), false, false);            GTA.World.CreateProp(new Model(2122387284), new GTA.Math.Vector3(1988.923f, 2852.714f, 49.27079f), new GTA.Math.Vector3(0f, 0f, 25f), false, false);            GTA.World.CreateProp(new Model(2122387284), new GTA.Math.Vector3(2000.575f, 2858.135f, 49.28042f), new GTA.Math.Vector3(0f, 0f, 8.000007f), false, false);            GTA.World.CreateProp(new Model(2122387284), new GTA.Math.Vector3(2013.178f, 2859.965f, 49.23547f), new GTA.Math.Vector3(0f, 0f, 7.999998f), false, false);            GTA.World.CreateVehicle(new Model(-82626025) new GTA.Math.Vector3(2058.021f, 2765.874f, 50.80261f), -59.5616f);            GTA.World.CreatePed(new Model(307287994), new GTA.Math.Vector3(2031.123f, 2859.301f, 49.64544f), 55.04015f);        }    }}
Edited by SpiderMight
Link to comment
Share on other sites

ShadowCoderKing

nothing is showing up in game that i try to spawn in the script

Edited by SpiderMight
Link to comment
Share on other sites

Well, do you get any errors?

if not try spawning the props using a button

i.e:

using GTA;using System;using System.Collections.Generic;using System.Threading.Tasks;using GTA.Native;using System.Windows.Forms;public class Armybase : Script{    public Armybase()    {        Tick += OnTick;        KeyDown += OnKeyDown;        KeyUp += OnKeyUp;        Interval = 10;    }    void OnTick(object sender, EventArgs e)    {    }    void OnKeyDown(object sender, KeyEventArgs e)    {    }    void OnKeyUp(object sender, KeyEventArgs e)    {        if (e.Keycode == Keys.F12)        {                     GTA.World.CreateProp(new Model(276224379), new GTA.Math.Vector3(2033.644f, 2830.369f, 49.30626f), new GTA.Math.Vector3(0f, 0f, -16.99992f), false, false);         GTA.World.CreateProp(new Model(2122387284), new GTA.Math.Vector3(1988.923f, 2852.714f, 49.27079f), new GTA.Math.Vector3(0f, 0f, 25f), false, false);         GTA.World.CreateProp(new Model(2122387284), new GTA.Math.Vector3(2000.575f, 2858.135f, 49.28042f), new GTA.Math.Vector3(0f, 0f, 8.000007f), false, false);         GTA.World.CreateProp(new Model(2122387284), new GTA.Math.Vector3(2013.178f, 2859.965f, 49.23547f), new GTA.Math.Vector3(0f, 0f, 7.999998f), false, false);         GTA.World.CreateVehicle(new Model(-82626025) new GTA.Math.Vector3(2058.021f, 2765.874f, 50.80261f), -59.5616f);         GTA.World.CreatePed(new Model(307287994), new GTA.Math.Vector3(2031.123f, 2859.301f, 49.64544f), 55.04015f);        }    }}

If F12 is pressed it will spawn your objects at the position you set.

Tell me what happens when you do this. It should work.

Link to comment
Share on other sites

ShadowCoderKing

i tryied it using a button but nothing shows up and no errors just nothing witch is strange it should work :(

Link to comment
Share on other sites

ShadowCoderKing

is anyone able to help please i dont understand why no props or peds are spawning

Edited by SpiderMight
Link to comment
Share on other sites

 

im making a script that places objects and peds and cars at coords but nothing shows up at all what did i do wrong ?

using GTA;using System;using System.Collections.Generic;using System.Threading.Tasks;using GTA.Native;using System.Windows.Forms;using GTA.Math;public class Armybase : Script{    public Armybase()    {        Tick += OnTick;        KeyDown += OnKeyDown;        KeyUp += OnKeyUp;        Interval = 10;    }    void OnTick(object sender, EventArgs e)    {            }    void OnKeyDown(object sender, KeyEventArgs e)    {        }    void OnKeyUp(object sender, KeyEventArgs e)    {        if(e.KeyCode == Keys.F11)        {                        GTA.World.CreateProp(new Model(276224379), new GTA.Math.Vector3(2033.644f, 2830.369f, 49.30626f), new GTA.Math.Vector3(0f, 0f, -16.99992f), false, false);            GTA.World.CreateProp(new Model(2122387284), new GTA.Math.Vector3(1988.923f, 2852.714f, 49.27079f), new GTA.Math.Vector3(0f, 0f, 25f), false, false);            GTA.World.CreateProp(new Model(2122387284), new GTA.Math.Vector3(2000.575f, 2858.135f, 49.28042f), new GTA.Math.Vector3(0f, 0f, 8.000007f), false, false);            GTA.World.CreateProp(new Model(2122387284), new GTA.Math.Vector3(2013.178f, 2859.965f, 49.23547f), new GTA.Math.Vector3(0f, 0f, 7.999998f), false, false);            GTA.World.CreateVehicle(new Model(-82626025) new GTA.Math.Vector3(2058.021f, 2765.874f, 50.80261f), -59.5616f);            GTA.World.CreatePed(new Model(307287994), new GTA.Math.Vector3(2031.123f, 2859.301f, 49.64544f), 55.04015f);        }    }}

 

You need patience, but regardless.

 

I see one problem. your interval is set to 10ms. So that may not detect that you are pressing F11. (set that to 1;)

 

To help others in future, you may want to split your code up so it is more readable (this may help you in future when you have long code too)

 if (e.Keycode == Keys.F12)        {                     GTA.World.CreateProp(new Model(276224379), new GTA.Math.Vector3(2033.644f, 2830.369f, 49.30626f), new GTA.Math.Vector3(0f, 0f, -16.99992f), false, false);         GTA.World.CreateProp(new Model(2122387284), new GTA.Math.Vector3(1988.923f, 2852.714f, 49.27079f), new GTA.Math.Vector3(0f, 0f, 25f), false, false);         GTA.World.CreateProp(new Model(2122387284), new GTA.Math.Vector3(2000.575f, 2858.135f, 49.28042f), new GTA.Math.Vector3(0f, 0f, 8.000007f), false, false);         GTA.World.CreateProp(new Model(2122387284), new GTA.Math.Vector3(2013.178f, 2859.965f, 49.23547f), new GTA.Math.Vector3(0f, 0f, 7.999998f), false, false);         GTA.World.CreateVehicle(new Model(-82626025) new GTA.Math.Vector3(2058.021f, 2765.874f, 50.80261f), -59.5616f);         GTA.World.CreatePed(new Model(307287994), new GTA.Math.Vector3(2031.123f, 2859.301f, 49.64544f), 55.04015f);        }

Can be written as

        if(e.KeyCode == Keys.F11)        {            //Cars            //Props            //Peds            //C++ Function     //Spawn Ped          //Ped Type     //Ped Model                          //X,Y,Z                                //Heading Dir           //Handles            Function.Call     (Hash.CREATE_PED,      1,            new Model(PedHash.Pilot01SMM),       2031.123f, 2859.301f, 49.64544f,       0,                      true, true);        }

I've only done one Ped example, but the Vehicles and Props follow the same pattern.

 

If problems persist with spawning props, you may need to load the prop model before spawning it.

 

 

EDIT, you might also want to remove void OnKeyDown()

 

you're probably not going to use it, but of course keep your void OnTick() for tick events

Edited by Colata
Link to comment
Share on other sites

qiangqiang101
GTA.World.CreateProp(new Model(276224379), new GTA.Math.Vector3(2033.644f, 2830.369f, 49.30626f), new GTA.Math.Vector3(0f, 0f, -16.99992f), false, false);

you cannot spawn model with hash, you need to spawn with model name

Link to comment
Share on other sites

ShadowCoderKing

thanks for your help, where in the scipt do i load the models ?

	    // Creates the model            var model = new Model("prop_fnclink_09e");            model.Request(250);            // Check the model is valid            if (model.IsInCdImage && model.IsValid)            {            // Ensure the model is loaded before we try to create it in the world            while (!model.IsLoaded) Script.Wait(50);                             }            // Mark the model as no longer needed to remove it from memory.            //model.MarkAsNoLongerNeeded();

qiangqiang101

does that mean i dont need all this code to load it ?



Edited  by SpiderMight

Link to comment
Share on other sites

 

thanks for your help, where in the scipt do i load the models ?

	    // Creates the model            var model = new Model("prop_fnclink_09e");            model.Request(250);            // Check the model is valid            if (model.IsInCdImage && model.IsValid)            {            // Ensure the model is loaded before we try to create it in the world            while (!model.IsLoaded) Script.Wait(50);                             }            // Mark the model as no longer needed to remove it from memory.            //model.MarkAsNoLongerNeeded();

qiangqiang101

does that mean i dont need all this code to load it ?


 

Yes, to spawn a prop you need to use all of that (which simply loads the model and spawns it) because models are more complex than cars and peds, i presume.

 

you can use a foreach (models in list)

        var model = new Model("prop_fnclink_09e");            model.Request(250);            // Check the model is valid            if (model.IsInCdImage && model.IsValid)            {            // Ensure the model is loaded before we try to create it in the world            while (!model.IsLoaded) Script.Wait(50);                             }

except of course you wouldn't make individual variables (var) you would make a list seperated from this and spawn each variable in that list, rather than in the foreach loop.

  • Like 1
Link to comment
Share on other sites

  • 4 weeks later...

You need patience, but regardless.

 

 

 

 

I see one problem. your interval is set to 10ms. So that may not detect that you are pressing F11. (set that to 1;)

 

To help others in future, you may want to split your code up so it is more readable (this may help you in future when you have long code too)

I think that interval only effects the Tick event, not the keyDown handler

Edited by AHK1221
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.