Quantcast

Jump to content

» «
Photo

[C#] Is is possible that swap spawned traffic vehicle to specific model ?

No replies to this topic
ES_SENCE
  • ES_SENCE

    Player Hater

  • Members
  • Joined: 4 weeks ago
  • South-Korea

#1

Posted 4 weeks ago Edited by ES_SENCE, 4 weeks ago.

What's up, guys.

 

I'm sorry that I mistyped the subject of this post.

 

I wanted to ask "Is is possible to swap spawned traffic vehicle to specific model ?".

 

I'm trying to select a random vehicle in traffic then change it to specific vehicle model I want.

 

I found a native function, called CREATE_MODEL_SWAP.

 

I thought this method could help me but I don't know how to use this one.

 

Is there anyone who has an example of this method ?

 

Anyway, here is my code:

...
namespace myCode
{
    public class myCode : Script
    {
        private Random dice = new Random();
        private List<string> targetVehs = new List<string> { "nero", "vigilante" };

        public myCode ()
        {
            this.Tick += onTick;
        }

        private void onTick (Object sender, EventArgs e)
        {
            string selected = targetVehs[dice.Next(0, targetVehs.Count)];
            Model selectedVeh = new Model(selected);
            selectedVeh.Request();

            while (!selectedVeh.IsLoaded) Wait(0);

            if (selectedVeh.IsLoaded)
            {
                Vehicle[] nearbyVehs = World.GetNearbyVehicles(Game.Player.Character, 200.0f);
                Vehicle sourceVeh = nearbyVehs[dice.Next(0, nearbyVehs.Length)];

                Blip b = addOn.AddBlip();
                Function.Call(Hash.SET_BLIP_SPRITE, b, 227);
                Function.Call(Hash.SET_BLIP_COLOUR, b, 0);
                Function.Call(Hash.SET_BLIP_SCALE, b, 0.7f);
                Function.Call(Hash.SET_BLIP_AS_SHORT_RANGE, b, true);

                Function.Call(Hash.CREATE_MODEL_SWAP, sourceVeh.Position.X, sourceVeh.Position.Y, sourceVeh.Position.Z, 10.0f, sourceVeh.Model, selectedVeh.Model, true);
            }
        }
    }
}

When I run the game, blip would be created for source vehicle which is nearby, but source vehicle won't be swapped to target vehicle.

 

If I should use another function, please let me know.

 

Thank you for reading.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users