I'm using V-U Mod with Cider, and I'd like to know if there is a hook that's called before a player enters a vehicle...because I would like to first check if the person owns the vehicle and if it's unlocked/locked/etc...
EDIT: Problem solved...now I just need to know what the KeyPress codes are. is IN_GRENADE1 the G button by default?
EDIT2: I'd like to know if there is like a single function that can spawn a vehicle? I currently create an entity, then set the model, script, etc and then spawn it. But I can just press the vehicle in the vehicle tab which does it in one click, what is the function that spawns a vehicle?
A quick answer would be no, there is not one function to just spawn a vehicle.
Unless you make a function, like sandbox does:
[lua]
local function MakeVehicle( Player, Pos, Ang, Model, Class, VName, VTable )
if (!gamemode.Call( "PlayerSpawnVehicle", Player, Model, VName, VTable )) then return end
local Ent = ents.Create( Class )
if (!Ent) then return NULL end
Ent:SetModel( Model )
// Fill in the keyvalues if we have them
if ( VTable && VTable.KeyValues ) then
for k, v in pairs( VTable.KeyValues ) do
Ent:SetKeyValue( k, v )
end
end
Ent:SetAngles( Ang )
Ent:SetPos( Pos )
Ent:Spawn()
Ent:Activate()
Ent.VehicleName = VName
Ent.VehicleTable = VTable
// We need to override the class in the case of the Jeep, because it
// actually uses a different class than is reported by GetClass
Ent.ClassOverride = Class
gamemode.Call( "PlayerSpawnedVehicle", Player, Ent )
return Ent
end
duplicator.RegisterEntityClass( "prop_vehicle_jeep_old", MakeVehicle, "Pos", "Ang", "Model", "Class", "VehicleName", "VehicleTable" )
duplicator.RegisterEntityClass( "prop_vehicle_jeep", MakeVehicle, "Pos", "Ang", "Model", "Class", "VehicleName", "VehicleTable" )
duplicator.RegisterEntityClass( "prop_vehicle_airboat", MakeVehicle, "Pos", "Ang", "Model", "Class", "VehicleName", "VehicleTable" )
duplicator.RegisterEntityClass( "prop_vehicle_prisoner_pod", MakeVehicle, "Pos", "Ang", "Model", "Class", "VehicleName", "VehicleTable" )
/*---------------------------------------------------------
Name: CCSpawnVehicle
Desc: Player attempts to spawn vehicle
---------------------------------------------------------*/
function CCSpawnVehicle( Player, command, arguments )
if ( arguments[1] == nil ) then return end
local vname = arguments[1]
local VehicleList = list.Get( "Vehicles" )
local vehicle = VehicleList[ vname ]
// Not a valid vehicle to be spawning..
if ( !vehicle ) then return end
local tr = Player:GetEyeTraceNoCursor()
local Angles = Player:GetAngles()
Angles.pitch = 0
Angles.roll = 0
Angles.yaw = Angles.yaw + 180
local Ent = MakeVehicle( Player, tr.HitPos, Angles, vehicle.Model, vehicle.Class, vname, vehicle )
if ( !ValidEntity( Ent ) ) then return end
if ( vehicle.Members ) then
table.Merge( Ent, vehicle.Members )
duplicator.StoreEntityModifier( Ent, "VehicleMemDupe", vehicle.Members );
end
undo.Create( "Vehicle" )
undo.SetPlayer( Player )
undo.AddEntity( Ent )
undo.SetCustomUndoText( "Undone "..vehicle.Name )
undo.Finish( "Vehicle ("..tostring( vehicle.Name )..")" )
Player:AddCleanup( "vehicles", Ent )
end
concommand.Add( "gm_spawnvehicle", CCSpawnVehicle )
local function VehicleMemDupe( Player, Entity, Data )
table.Merge( Entity, Data );
end
duplicator.RegisterEntityModifier( "VehicleMemDupe", VehicleMemDupe )
[/lua]
[B]@Derek[/B] Thank you! Since sandbox is the parent game mode, I'm guessing I can just call this function? If so, how would I do that? GM:MakeVehicle()?
No because MakeVehicle is a local function. You can call CCSpawnVehicle (which I doubt will work for your purpose??) or recreate the MakeVehicle function (copy-paste yo)
Sorry, you need to Log In to post a reply to this thread.