Quantcast
Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!   (84,864 visits to this link)

    2. News

    1. GTA Online

      1. Find Lobbies & Players
      2. Guides & Strategies
      3. Vehicles
      4. Content Creator
      5. Help & Support
    2. Crews

      1. Events
      2. Recruitment
    1. Grand Theft Auto Series

    2. GTA Next

    3. GTA V

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

      1. Episodes from Liberty City
      2. Multiplayer
      3. Guides & Strategies
      4. Help & Support
      5. GTA Mods
    5. GTA Chinatown Wars

    6. GTA Vice City Stories

    7. GTA Liberty City Stories

    8. GTA San Andreas

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

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

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

      1. GTA Advance
      2. GTA 2
      3. GTA
    12. Wiki

      1. Merchandising
    1. GTA Modding

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    3. Featured Mods

      1. DYOM
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Red Dead Redemption 2

    2. Red Dead Redemption

    3. Rockstar Games

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Programming
      5. Movies & TV
      6. Music
      7. Sports
      8. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. Forum Support

    2. Site Suggestions

xanman2331

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

Recommended Posts

xanman2331
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);

 

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
Bob_74

 

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

Share this post


Link to post
Share on other sites
xanman2331

 

 

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

Share this post


Link to post
Share on other sites
xanman2331

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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
Bob_74
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

Share this post


Link to post
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

×

Important Information

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