Quantcast
Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. The Diamond Casino Heist
      2. Find Lobbies & Players
      3. Guides & Strategies
      4. Vehicles
      5. Content Creator
      6. Help & Support
    2. Red Dead Online

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

      1. Events
    1. Red Dead Redemption 2

      1. PC
      2. Gameplay
      3. Missions
      4. Help & Support
    2. Red Dead Redemption

    1. Grand Theft Auto Series

    2. GTA 6

    3. GTA V

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

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

    6. GTA Vice City Stories

    7. GTA Liberty City Stories

    8. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
    9. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
    10. GTA III

      1. Guides & Strategies
      2. Help & Support
    11. Top Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    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. DYOM
      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
    3. Gangs

    1. Announcements

    2. Support

    3. Suggestions

jaky2008

[C#] Adding marker to map not working.

Recommended Posts

jaky2008

BIG ASS EDIT (FOR ANY OTHER NOOBS)

Thank you to FowardElement for helping me get it working exactly how I wanted and bilago for helping me out too.
If anyone reads this with the same problem; all you need to do is add a reference to System.Drawing and also add using System.Drawing;
You also need GTA.Math;
Drawing the marker in game:
GTA.World.DrawMarker(MarkerType.UpsideDownCone, new Vector3(x, y, z), Vector3.Zero, Vector3.Zero, new Vector3(1f, 1f, 1f), Color.Yellow);
And this code for the blip:
GTA.Blip blip = GTA.World.CreateBlip(new Vector3(x, y, z);
blip.Sprite = BlipSprite.Rampage;
Replacing the values with your own.
Edited by jaky2008

Share this post


Link to post
Share on other sites
FowardElement

The DRAW_MARKER function needs to be placed in the OnTick.

  • Like 1

Share this post


Link to post
Share on other sites
jaky2008

The DRAW_MARKER function needs to be placed in the OnTick.

Thank you! I will try that now, I tried it earlier but it kept crashing. Doesn't ontick mean that it is constantly being drawn to the map each second? I changed the waypoint in the OnTick method first time around and it was constantly changing the waypoint to that no matter if you set a custom one because of the constant loop/update.

 

Here's hoping it will still work, because the code for pressing "L" and giving the weapon does nothing still.

 

 

EDIT: GTA V has stopped responding. Doesn't work :(

EDITx2: I replaced the texture args with "false" (excluding quotation marks) and the game doesn't crash, but there is still no map marker where it is supposed to be. The other problem however (giving player snowball) is fixed.

Edited by jaky2008

Share this post


Link to post
Share on other sites
FowardElement

Try GTA.WORLD.DrawMarker(MarkerType.UpsideDownCone, new Vector3(2070.15f, 3760.85f, 32.45f), GTA.MATH.Vector3.Zero, GTA.MATH.Vector3.Zero, new GTA.MATH.Vector3(1f, 1f, 1f), Color.Yellow);

 

Question....Are you wanting to create a Blip that shows on the map or a marker that shows in game?

Edited by FowardElement
  • Like 1

Share this post


Link to post
Share on other sites
jaky2008

Try GTA.WORLD.DrawMarker(MarkerType.UpsideDownCone, new Vector3(2070.15f, 3760.85f, 32.45f), GTA.MATH.Vector3.Zero, GTA.MATH.Vector3.Zero, new GTA.MATH.Vector3(1f, 1f, 1f), Color.Yellow);

"The type or namespace name 'WORLD' does not exist in the namespace 'GTA' (are you missing an assembly reference?)"
"The type or namespace name 'MATH' does not exist in the namespace 'GTA' (are you missing an assembly reference?)"
This looks an awful lot like XNA, with the Color.Yellow and Vector3's (also don't work.)
I swear it is something simple i'm not smart enough to understand.
To answer your question:
I'm wanting to make both; I wan't a blip to appear on the map which leads to an area and then a marker to stand in at the area which would have some behavior for doing so.
Edited by jaky2008

Share this post


Link to post
Share on other sites
FowardElement

Sorry about that. Im using my phone to try and help. "WORLD" should be "World". Also add "using GTA.Math;" and "using System.Drawing;"at the top.

Edited by FowardElement
  • Like 1

Share this post


Link to post
Share on other sites
jaky2008

Sorry about that. Im using my phone to try and help. "WORLD" should be "World". Also add "using GTA.Math;" and "using System.Drawing;"at the top.

 

Don't apologize, you're a great help.

Making good progress here, the non capitalized WORLD and MATH fixed those errors, the issue is that Color.Yellow still doesn't work, even with System.Drawing declared because System.Drawing doesn't exist.

Share this post


Link to post
Share on other sites
FowardElement

Only put the draw marker in the ontick.

 

For a blip:

GTA.Blip blip = GTA.World.CreateBlip(new Vector3(2070.15f, 3760.85f, 32.45f);

blip.Sprite = BlipSprite.Rampage;

Make sure you add the reference for System.Drawing in you Solution Explorer in VS.

  • Like 1

Share this post


Link to post
Share on other sites
jaky2008

Thank you so much everyone, I now have the blip showing in game, I added the System.Drawing reference and then changed the code around a little bit because the arguments were off, it is ordered like this:

 

GTA.World.DrawMarker(MarkerType.UpsideDownCone, new Vector3(2070.15f, 3760.85f, 32.45f), Vector3.Zero, Vector3.Zero, new Vector3(1f, 1f, 1f), Color.Yellow);

 

I will now try adding a blip! Thank you.

BLIP ADDED! Easy as that, big thanks to you, FowardElement for helping me out with this.

 

 

 

dtptt.jpg

 

Edited by jaky2008

Share this post


Link to post
Share on other sites
FowardElement

jaky2008 glad I could help.

  • Like 1

Share this post


Link to post
Share on other sites
jaky2008

I.. uh. Ok so I ask for a little more help, you don't have to help me, you've already done enough.

 

The blips being created in the OnTick method lags out the PC because it creates 1419 of them. So I created a method for them which is called LoadBlips();

Seen here:

 

void LoadBlips()
{
GTA.Blip ballasBlip1 = GTA.World.CreateBlip(new Vector3(130f, -1934f, 20f));
ballasBlip1.Sprite = BlipSprite.Drugs;
GTA.World.DrawMarker(MarkerType.HorizontalCircleSkinny, new Vector3(130f, -1934f, 20f), Vector3.Zero, Vector3.Zero, new Vector3(1f, 1f, 1f), Color.White);
}

 

Additionally I made a LoadPeds(); method here:

 

void LoadPeds()
{
Ped balla = World.CreatePed(PedHash.Ballasog, new Vector3(130.5f, -1934.2f, 20f));
}

 

So I added/ran these methods in the public TestScript() here:

 

public TestScript()
{
Tick += OnTick;
KeyDown += OnKeyDown;
LoadBlips();
LoadPeds();
}

When in game, LoadBlips(); only creates the map blip and does not create the map marker. And unfortunately, LoadPeds(); does nothing.

 

So so far I have two choices;

  1. Do it all in OnTick and have the game unplayable.
  2. Only create the blip.

 

Can I do anything else? Maybe put a limit on the blips spawned at once in OnTick?

Share this post


Link to post
Share on other sites
FowardElement

Im still on my phone, so sorry if any typos...try this.

 

using System;

using System.Drawing;

using System.Windows.Forms;

using GTA;

using GTA.Math;

using GTA.Native;

 

namespace TestScript

{

 

public class TestScript : Script

{

 

bool isRunning = false;

 

public TestScript()

{

Tick += OnTick;

KeyDown += OnKeyDown;

KeyUp += OnKeyUp;

}

 

private void OnKeyDown(object sender, KeyEventArgs e)

{

 

}

 

private void OnKeyUp(object sender, KeyEventArgs e)

{

if (e.KeyCode == Keys.NumPad1) // Change keys here.

{

isRunning = true;

LoadBlips();

LoadPeds();

}

 

if (e.KeyCode == Keys.NumPad3) // Change keys here.

{

isRunning = false;

}

}

 

private void OnTick(object sender, EventArgs e)

{

if (isRunning)

{

GTA.World.DrawMarker(MarkerType.HorizontalCircleSkinny, new Vector3(130f, -1934f, 20f), Vector3.Zero, Vector3.Zero, new Vector3(1f, 1f, 1f), Color.White);

}

}

 

private void LoadBlips()

{

GTA.Blip ballasBlip1 = GTA.World.CreateBlip(new Vector3(130f, -1934f, 20f));

ballasBlip1.Sprite = BlipSprite.Drugs;

 

}

 

void LoadPeds()

{

Ped balla = World.CreatePed(PedHash.Ballasog, new Vector3(130.5f, -1934.2f, 20f));

}

 

}

}

Share this post


Link to post
Share on other sites
jaky2008

It handles as expected, nothing originally.

 

 

2rdff6a.jpg

 

 

 

Then after keypress "L" it begins; balla is spawned and icon/blip are drawn.

 

 

 

azc2ns.jpg

 

And it stops after pressing "K", well only the blip disappears (as coded above)

 

 

 

atm6nm.jpg

 

 

 

Would it only be possible to continue this mod this way? requiring the player to press a key to begin as opposed to it starting automatically from being installed? Thanks again!

Edited by jaky2008

Share this post


Link to post
Share on other sites
FowardElement

So you are wanting the script to create the ped, the blip and draw the marker, when the game starts, without having to press any buttons?

  • Like 1

Share this post


Link to post
Share on other sites
jaky2008

Yes! So it is all automatic; all available from the start when they load their save game.

Share this post


Link to post
Share on other sites
FowardElement

This is the best I could do from my phone from memory.

 

using System;

using System.Drawing;

using System.Windows.Forms;

using GTA;

using GTA.Math;

using GTA.Native;

 

namespace TestScript

{

 

public class TestScript : Script

{

bool isRunning = true;

 

public TestScript()

{

Tick += OnTick;

KeyDown += OnKeyDown;

KeyUp += OnKeyUp;

 

LoadBlips();

 

}

 

private void OnKeyDown(object sender, KeyEventArgs e)

{

 

}

 

private void OnKeyUp(object sender, KeyEventArgs e)

{

if (e.KeyCode == Keys.NumPad1) // Change keys here.

{

 

}

 

if (e.KeyCode == Keys.NumPad3) // Change keys here.

{

 

}

}

 

private void OnTick(object sender, EventArgs e)

{

GTA.World.DrawMarker(MarkerType.HorizontalCircleSkinny, new Vector3(130f, -1934f, 20f), Vector3.Zero, Vector3.Zero, new Vector3(1f, 1f, 1f), Color.White);

 

if (isRunning)

{

if (Game.Player.Character.IsInRangeOf(new Vector3(130.5f, -1934.2f, 20f), 100f))

{

LoadPeds();

isRunning = false;

}

}

}

 

private void LoadBlips()

{

GTA.Blip ballasBlip1 = GTA.World.CreateBlip(new Vector3(130f, -1934f, 20f));

ballasBlip1.Sprite = BlipSprite.Drugs;

 

}

 

private void LoadPeds()

{

Ped balla = World.CreatePed(PedHash.Ballasog, new Vector3(130.5f, -1934.2f, 20f));

 

}

 

}

}

  • Like 1

Share this post


Link to post
Share on other sites
jaky2008

Thank you! This is perfect, its what I had in mind from the beginning I just wasn't smart enough to do it myself.

Earlier on I thought I could use a radius near the area to trigger and spawn the ped instead, because otherwise it crashes the game, I just didn't know how to do it.

 

I think I'm all good from here, sorry for taking up so much of your time, and thanks again.

Share this post


Link to post
Share on other sites
FowardElement

All good. Just keep in mind that all of that is very basic code that will get you started. Glad I could help.

Share this post


Link to post
Share on other sites
jaky2008

So I figured it out not long after posting this, sorry!

Edited by jaky2008

Share this post


Link to post
Share on other sites
bilago

 

 

So I figured it out not long after posting this, sorry!

 

 

 

Why shrink the text and cross it out making it unreadable? Just delete the post if you dont want people seeing it.

 

Also, just a suggestion to make your code better, I would make a Dictionary<Vector3, string> and store all your locations and ped models in that dictionary like this...:

 

private Dictionary<Vector3, string> Locations = new Dictionary<Vector3, string>();public YourEntryMethod(){    //this is your main entry method        Locations.Add(Location1, "Ped_ModelA");        Locations.Add(Location2, "Ped_ModelB");        Locations.Add(Location3, "Ped_ModelC");}private Ped CurrentlySpawnedPed;private bool isInRange = false;tick(){        foreach(var Entry in Locations)        {            isInRange = Game.Player.Character.IsInRangeOf(Entry.Key, 50f);            if(isInRange)            {                                if(CurrentlySpawnedPed != null) //if ped isn't null lets delete it                    CurrentlySpawnedPed.Delete();                CurrentlySpawnedPed = World.CreatePed(Entry.Value, Entry.Key); //Spawn new ped in this location                Function.Call(Hash.SET_PED_RANDOM_COMPONENT_VARIATION, CurrentlySpawnedPed, true);                break; //no need to keep looping if we are in this location already            }        }        if(!isInRange && CurrentlySpawnedPed != null) //only is false if you are not in any of the defined locations           CurrentlySpawnedPed.Delete();}

Doing it like this will let you add additional locations with virtually no code changes other than adding more dictionary items.

Edited by bilago
  • Like 1

Share this post


Link to post
Share on other sites
jaky2008

Thank you! I will implement it now, I have other issues with the code at the moment but I can at least tidy things up a bit in the meantime! I love how you guys actually help out, some people would sh*t on me for being a noob.

 

And yeah, i'll also edit the comments to make it not as big of an eyesore.

 

EDIT:

 

Here are the code segments in order, with some irrelevant information removed.
        private Dictionary<Vector3, string> Locations = new Dictionary<Vector3, string>();        private Ped CurrentlySpawnedPed;        private bool isInRange = false; public TestScript()        {            Tick += OnTick;            KeyUp += OnKeyUp;            Locations.Add(new Vector3(83.18f, -1972.86f, 20.92f), "PedHash.BallaEast01GMY");            Locations.Add(new Vector3(1023.01f, -1869.51f, 30.89f), "PedHash.Vagos01GFY");            Locations.Add(new Vector3(-215.39f, -1617.88f, 34.87f), "PedHash.Famdnf01GMY");            Locations.Add(new Vector3(795.68f, -122.42f, 75.83f), "PedHash.Lost01GMY");            Locations.Add(new Vector3(791.86f, -122.35f, 79.76f), "PedHash.Lost02GMY");            LoadBlips();        }private void OnTick(object sender, EventArgs e)        {            foreach (var Entry in Locations)            {                isInRange = Game.Player.Character.IsInRangeOf(Entry.Key, 100f);                if (isInRange)                {                    if (CurrentlySpawnedPed != null) //if ped isn't null lets delete it                        CurrentlySpawnedPed.Delete();                    CurrentlySpawnedPed = World.CreatePed(Entry.Value, Entry.Key); //Spawn new ped in this location                    Function.Call(Hash.SET_PED_RANDOM_COMPONENT_VARIATION, CurrentlySpawnedPed, true);                    LoadModels();                      break; //no need to keep looping if we are in this location already                }            }            if (!isInRange && CurrentlySpawnedPed != null) //only is false if you are not in any of the defined locations                CurrentlySpawnedPed.Delete();        }
It doesn't work, i get the feeling i'm still putting parts of the code into the wrong areas. All that works is that my markers are drawn and the blips are shown.
Also the props are loaded with LoadModels(); except the props spawn on itself many times and makes a tower in the sky, though the code seems to work, its just got nowhere to spawn the peds?
Edited by jaky2008

Share this post


Link to post
Share on other sites
bilago

Looking at the code I see where it would cause a problem, right now if the player is in range of an area its going to delete the currently spawned ped every tick and remake him... Code needs to be modified to something like this:

      private Dictionary<Vector3, string> Locations = new Dictionary<Vector3, string>();      private Ped CurrentlySpawnedPed;      private Vector3 CurrentlySpawnedLocation = Vector3.Zero;      private bool isInRange = false; public TestScript()        {            Tick += OnTick;            KeyUp += OnKeyUp;            Locations.Add(new Vector3(83.18f, -1972.86f, 20.92f), "PedHash.BallaEast01GMY");            Locations.Add(new Vector3(1023.01f, -1869.51f, 30.89f), "PedHash.Vagos01GFY");            Locations.Add(new Vector3(-215.39f, -1617.88f, 34.87f), "PedHash.Famdnf01GMY");            Locations.Add(new Vector3(795.68f, -122.42f, 75.83f), "PedHash.Lost01GMY");            Locations.Add(new Vector3(791.86f, -122.35f, 79.76f), "PedHash.Lost02GMY");            LoadBlips();        }private void OnTick(object sender, EventArgs e)        {            foreach (var Entry in Locations)            {                isInRange = Game.Player.Character.IsInRangeOf(Entry.Key, 100f);                if (isInRange)                {                    if (CurrentlySpawnedPed != null) //if ped isn't null lets delete it if its not in our target zone                    {                       if(CurrentlySpawnedLocation != Entry.Key) //ped is not in the right location                        CurrentlySpawnedPed.Delete(); //deleting                     else                        break; //Ped is already spawned from the right location so lets just continue on                    }                    CurrentlySpawnedPed = World.CreatePed(Entry.Value, Entry.Key); //Spawn new ped in this location                    Function.Call(Hash.SET_PED_RANDOM_COMPONENT_VARIATION, CurrentlySpawnedPed, true);LoadModels();                      break; //no need to keep looping if we are in this location already                }            }            if (!isInRange && CurrentlySpawnedPed != null) //only is false if you are not in any of the defined locations                CurrentlySpawnedPed.Delete();        }

Share this post


Link to post
Share on other sites
jaky2008

Thanks for helping again and sorting that out.

I've used the code exactly like that and still no peds are spawning in the area, I'm guessing that it has to do with Entry.Value and Entry.Key.

How would I assign each ped's information into that? I thought that is what the pedhash part of Locations.Add(new Vector3(83.18f, -1972.86f, 20.92f), "PedHash.BallaEast01GMY"); did for us?

 

So I changed

private Dictionary<Vector3, string> Locations = new Dictionary<Vector3, string>(); to private Dictionary<Vector3, Pedhash> Locations = new Dictionary<Vector3, Pedhash>();

Locations.Add(new Vector3(83.18f, -1972.86f, 20.92f), "PedHash.BallaEast01GMY"); to Locations.Add(new Vector3(83.18f, -1972.86f, 20.92f), PedHash.BallaEast01GMY); etc.

And this is result:

 

 

29on7g4.jpg

 

2prv0hd.jpg

 

 

 

The peds now spawn, in the air, and flicker between each component. I assume this is because of the Tick method constantly updating?

Edited by jaky2008

Share this post


Link to post
Share on other sites
bilago

change your ontick to this:

private void OnTick(object sender, EventArgs e)        {            foreach (var Entry in Locations)            {                isInRange = Game.Player.Character.IsInRangeOf(Entry.Key, 100f);                if (isInRange)                {                    if (CurrentlySpawnedPed != null) //if ped isn't null lets delete it if its not in our target zone                   {                      if(CurrentlySpawnedLocation != Entry.Key) //ped is not in the right location                        CurrentlySpawnedPed.Delete(); //deleting                    else                       break; //Ped is already spawned from the right location so lets just continue on                   }                    CurrentlySpawnedLocation = Entry.Key; //Updating the Stored spawned location                    CurrentlySpawnedPed = World.CreatePed(Entry.Value, CurrentlySpawnedLocation); //Spawn new ped in this location                                        Function.Call(Hash.SET_PED_RANDOM_COMPONENT_VARIATION, CurrentlySpawnedPed, true);LoadModels();                      break; //no need to keep looping if we are in this location already                }            }            if (!isInRange && CurrentlySpawnedPed != null) //only is false if you are not in any of the defined locations                CurrentlySpawnedPed.Delete();        }
Edited by bilago
  • Like 1

Share this post


Link to post
Share on other sites
jaky2008

Thank you so much bilago, I would've ended up reverting back to my old sloppy code if not for you.

Sorry for not replying sooner, I was playing Fallout 4 way too much like many others.

It works nicely, only thing is the models spawn 3 of the same model in each area stacked on top. I will figure that out myself, you've already done enough!

 

EDIT:

Figured it out, or something. It was spawning three instances of each object/model but for some reason it isn't now, either it glitched the first time or I changed something and can't remember, anyways; good work and thank you.

Edited by jaky2008

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


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