Quantcast

Jump to content

» «
Photo

Car spawning and despawning question

3 replies to this topic
icecube3456
  • icecube3456

    Player Hater

  • Members
  • Joined: 10 May 2013

#1

Posted 10 May 2013 - 01:40 AM

I'm using C# with scripthook .net, is there a way to remove cars if too many are spawned?

blowjobcumpussy
  • blowjobcumpussy

    Player Hater

  • BUSTED!
  • Joined: 10 May 2013

#2

Posted 10 May 2013 - 01:52 AM Edited by blowjobcumpussy, 10 May 2013 - 02:15 AM.

CODE
using System;
using System.Windows.Forms;
using GTA;

public class CarDensity : Script
{
   //edit numbers to right of equal sign only
   const Keys DELETE_CARS_MANUALLY_KEY = Keys.Delete;
   const float DELETE_RANGE = 25f;
   const float CAR_DENSITY = 0.75f;//1.0 is default
   //do not edit below unless u know what ur doing

   public CarDensity()
   {
       BindKey(DELETE_CARS_MANUALLY_KEY, DeleteAroundPlayer);
       World.CarDensity = CAR_DENSITY;
   }
   private void DeleteAroundPlayer()
   {
       foreach (Vehicle veh in World.GetVehicles(Game.LocalPlayer.Character.Position, DELETE_RANGE))
           if (Game.Exists(veh) && veh != Game.LocalPlayer.Character.CurrentVehicle)
               veh.Delete();
   }
}


Requires:
-scripthookdotnet 1.7.1.7 beta by hazardx
-scripthook c++ 0.4.0 (gta 1.0.4) or 0.5.1 (gta 1.0.7 or eflc) by aru
-one of the asi loaders (listener, alexander blade, etc)

Intsall:
-copy to notepad, save as ILoveBlowJobs.cs and put in scripts folder u made when u installed scripthookdotnet

Editing Values:
-to change values, tab out of game, open script in notepad, change values at top of script only, save and then go back to game and do the reloadscripts command in console

Extra Function:
-added command to manually delete cars in an area around player, u can change delete range at top of script, use delete key or edit key at top of script, google "system.windows.forms.keys enumeration" to see a list of valid Keys values

motorsport71
  • motorsport71

    newbie modder

  • Members
  • Joined: 20 Oct 2009

#3

Posted 11 May 2013 - 05:27 AM

@icecube3456 When you say "is there a way to remove cars if too many are spawned?", do you mean vehicles that you've spawned yourself and/or other scripts that won't go away even if you drive off and come back? If so they may be considered "mission vehicles" which won't despawn on their own. Off the top of my head try something like this:
CODE
Imports System
Imports System.Collections
Imports System.Windows.Forms
Imports GTA
Public Class ControlTraffic
   Inherits Script
   Private Scripton As Boolean = False
   Public Sub New()
       Me.interval = 1000
   End Sub
   Private Sub Traffic_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Tick
       If Scripton = True Then
           If (isKeyPressed(Settings.GetValueKey("Key", Keys.F9))) Then
               Native.Function.Call("PRINT_STRING_WITH_LITERAL_STRING_NOW", "STRING", "Vehicle Controls Deactivated", 5000, 1)
               world.cardensity = 1.0
               Scripton = False
           Else
               Dim vehicles As vehicle() = world.getallvehicles()
               For Each vehicle As Vehicle In vehicles
                   If Not exists(vehicle) OrElse vehicle Is Nothing Then
                       Continue For
                   End If
                   If exists(vehicle) AndAlso vehicle IsNot Nothing AndAlso vehicle.isrequiredformission = True AndAlso player.character.Position.DistanceTo(vehicle.Position) >= 30.0F Then
                       vehicle.nolongerneeded()
                   End If
               Next
           End If
       Else
           If (isKeyPressed(Settings.GetValueKey("Key", Keys.F9))) Then
               Scripton = True
               Native.Function.Call("PRINT_STRING_WITH_LITERAL_STRING_NOW", "STRING", "Vehicle Controls Activated", 5000, 1)
               world.cardensity = 1.0  'change this value to increace/decrease overall traffic. 1.0 is default, 0.5 is half, 2.0 is double, etc.
           End If
       End If
   End Sub
End Class


This should activate with F9, cycle through every second, and keep a constant default ingame value of 1.0 vehicle density. It will also allow the game to remove any spawned vehicles left lying around that are 30 meters or greater away from you. If you want to change the vehicles density change the second "world.cardensity = " whatever value you like, i marked it with a side annotation. When you turn off the script, it will automatically reset it to default vehicle density of 1.0. Copy the code to notepad and name "Traffic.vb" All necessary .net scripthook requirements that "blowjobcumpussy" are the same. Also, feel free to place it in a .cs converter and modify yourself. ps, i tested the script and it functions.

icecube3456
  • icecube3456

    Player Hater

  • Members
  • Joined: 10 May 2013

#4

Posted 11 May 2013 - 05:57 AM

Thanks for the help. I just made the script spawn the player in a vehicle and if you spawn another vehicle it deletes the current one and spawns you in another.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users