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

    3. Suggestions

[C#] spawning a random weapon pickup and checking whether it's been picked up


xanman2331
 Share

Recommended Posts

I am making my first mod and I have only really started learning C# in the last few days, so I apologise if the problem is something very obvious. I just want to check whether the pickup has been collected and I don't understand what's wrong (nor can I find any other topic on these forums that helps me). The error I am getting says "Error CS1503 Argument 2: cannot convert from 'GTA.Pickup' to 'GTA.Native.InputArgument'". Thanks for your help and I can provide more code if needed.
Pickup randWeapon = World.CreatePickup(weapons[rnd.Next(0, weapons.Count)], player.Position + (player.ForwardVector * 5), player.Rotation, 0, 1);{    Function.Call(Hash.HAS_PICKUP_BEEN_COLLECTED, randWeapon);

 

Link to comment
Share on other sites

OfficerJohnson

I am making my first mod and I have only really started learning C# in the last few days, so I apologise if the problem is something very obvious. I just want to check whether the pickup has been collected and I don't understand what's wrong (nor can I find any other topic on these forums that helps me). The error I am getting says "Error CS1503 Argument 2: cannot convert from 'GTA.Pickup' to 'GTA.Native.InputArgument'". Thanks for your help and I can provide more code if needed.

 

 

 

Pickup randWeapon = World.CreatePickup(weapons[rnd.Next(0, weapons.Count)], player.Position + (player.ForwardVector * 5), player.Rotation, 0, 1);{    Function.Call(Hash.HAS_PICKUP_BEEN_COLLECTED, randWeapon);

Determine what HAS_PICKUP_BEEN_COLLECTED takes as an input argument. It's not accepting your Pickup object. Maybe it's an enum? If the function is supposed to take an object of type Pickup, review what is considered a pickup under SHV.NET.

Link to comment
Share on other sites

OfficerJohnson

Okay. So the Pickup class has enums defined for pickups. Your code seems fine. Perhaps World.CreatePickup is not taking your randomization of the weapon as a valid argument? Try adding a single pickup type as the first argument and see if it gives you the error still. You may have to use a loop or some other method (maybe switch statement) to do that part.

Link to comment
Share on other sites

 

I am making my first mod and I have only really started learning C# in the last few days, so I apologise if the problem is something very obvious. I just want to check whether the pickup has been collected and I don't understand what's wrong (nor can I find any other topic on these forums that helps me). The error I am getting says "Error CS1503 Argument 2: cannot convert from 'GTA.Pickup' to 'GTA.Native.InputArgument'". Thanks for your help and I can provide more code if needed.
Pickup randWeapon = World.CreatePickup(weapons[rnd.Next(0, weapons.Count)], player.Position + (player.ForwardVector * 5), player.Rotation, 0, 1);{    Function.Call(Hash.HAS_PICKUP_BEEN_COLLECTED, randWeapon);

 

 

Do you use ScriptHookVDotNet?

 

If so, it is not how pickup are created:

World.CreatePickup(PickupType type, Vector3 position, Vector3 rotation, Model model, int value)

The first parameter is the type of pickup the player will collect, it is an enum as OfficerJohnson said.

You also need to specify a valid Model or else your pickup will not be created.

 

Going back to your problem.

Oddly, Pickups don't react the same way as other entities like Peds, Props or Vehicles when you have to pass it to a native. I don't know why, I tried to pass randWeapon.Handle since natives works with handles but it didn't work.

Pickups also have the isCollected property but I had no success with it either...

 

The only working way I've found to detect if the pickup has been collected is to check ObjectExists():

// Creating PickuprandWeapon = World.CreatePickup(PickupType.WeaponMinigun, Game.Player.Character.GetOffsetInWorldCoords(new Vector3(0f, 2f, 0f)), new Model("w_mg_minigun"), -1);// Checking every Tick:if randWeapon != null)	if (!randWeapon.ObjectExists())		UI.Notify("~g~Pickup has been collected!");
Edited by Bob_74
Link to comment
Share on other sites

 

 

I am making my first mod and I have only really started learning C# in the last few days, so I apologise if the problem is something very obvious. I just want to check whether the pickup has been collected and I don't understand what's wrong (nor can I find any other topic on these forums that helps me). The error I am getting says "Error CS1503 Argument 2: cannot convert from 'GTA.Pickup' to 'GTA.Native.InputArgument'". Thanks for your help and I can provide more code if needed.
Pickup randWeapon = World.CreatePickup(weapons[rnd.Next(0, weapons.Count)], player.Position + (player.ForwardVector * 5), player.Rotation, 0, 1);{    Function.Call(Hash.HAS_PICKUP_BEEN_COLLECTED, randWeapon);

 

 

Do you use ScriptHookVDotNet?

 

If so, it is not how pickup are created:

World.CreatePickup(PickupType type, Vector3 position, Vector3 rotation, Model model, int value)

The first parameter is the type of pickup the player will collect, it is an enum as OfficerJohnson said.

You also need to specify a valid Model or else your pickup will not be created.

 

Going back to your problem.

Oddly, Pickups don't react the same way as other entities like Peds, Props or Vehicles when you have to pass it to a native. I don't know why, I tried to pass randWeapon.Handle since natives works with handles but it didn't work.

Pickups also have the isCollected property but I had no success with it either...

 

The only working way I've found to detect if the pickup has been collected is to check ObjectExists():

// Creating PickuprandWeapon = World.CreatePickup(PickupType.WeaponMinigun, Game.Player.Character.GetOffsetInWorldCoords(new Vector3(0f, 2f, 0f)), new Model("w_mg_minigun"), -1);// Checking every Tick:if randWeapon != null)	if (!randWeapon.ObjectExists())		UI.Notify("~g~Pickup has been collected!");

This fixed the problem thanks :)

Link to comment
Share on other sites

I have a couple of other questions: How would I go about writing the random weapon's name as a subtitle on screen? and (separate function) how do I set the coordinates I want something to spawn at?

 

I have been using Vector3 for spawn location but it says I have a problem with value tuples (Error CS8179 Predefined type 'System.ValueTuple`3' is not defined or imported, or is declared in multiple referenced assemblies), as well as converting (int, int, int) to Vector3 (Cannot implicitly convert type '(int, int, int)' to 'GTA.Math.Vector3')

Random rnd = new Random();            GTA.Math.Vector3 spawnLoc1 = (rnd.Next(-3500, 7200), rnd.Next(-3300, 4000), 0);

Again I can provide more code if you need

Link to comment
Share on other sites

OfficerJohnson

I have a couple of other questions: How would I go about writing the random weapon's name as a subtitle on screen? and (separate function) how do I set the coordinates I want something to spawn at?

 

I have been using Vector3 for spawn location but it says I have a problem with value tuples (Error CS8179 Predefined type 'System.ValueTuple`3' is not defined or imported, or is declared in multiple referenced assemblies), as well as converting (int, int, int) to Vector3 (Cannot implicitly convert type '(int, int, int)' to 'GTA.Math.Vector3')

 

Random rnd = new Random();            GTA.Math.Vector3 spawnLoc1 = (rnd.Next(-3500, 7200), rnd.Next(-3300, 4000), 0);
Again I can provide more code if you need

For the first part, IIRC, UI.ShowSubtitle(). You need that.

 

As for the second part, see if there is a function for converting Vector3toInt. Yeah. We can't be casting 3-point parameters to a single int. vector3 needs an x,y and z value.

Link to comment
Share on other sites

I have been using Vector3 for spawn location but it says I have a problem with value tuples (Error CS8179 Predefined type 'System.ValueTuple`3' is not defined or imported, or is declared in multiple referenced assemblies), as well as converting (int, int, int) to Vector3 (Cannot implicitly convert type '(int, int, int)' to 'GTA.Math.Vector3')

 

Random rnd = new Random();            GTA.Math.Vector3 spawnLoc1 = (rnd.Next(-3500, 7200), rnd.Next(-3300, 4000), 0);

Again I can provide more code if you need

Vector3 is defined by three float values.

You need to cast the float type on your int numbers:

GTA.Math.Vector3 spawnLoc1 = (float)(rnd.Next(-3500, 7200), (float)rnd.Next(-3300, 4000), 0f);

The float notation in C# is made using an f after the number (ie: 0.0f). Otherwise it is considered as a int or a double if the number has a decimal separator (ie: 0.0).

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