• Help making a vehicle nocollide with players only when it is occupied by a player?
    8 replies, posted
Right now I have vehicles set to be nocollided with players universally. This is causing a few issues where people are crouching inside vehicles to avoid getting shot. What I want to do now is set the collision group to not collide with players only when the vehicle is occupied. Thus meaning that when there is no one inside the vehicle, it collides with players. When there IS someone inside the vehicle, it doesn't. How would I do this?
IsValid(Vehicle:GetDriver())
Mind sharing the script for that?
okay, IsValid(Vehicle:GetDriver()) doesnt seem to be helping. I have tried: [lua] hook.Add("PlayerSpawnedVehicle", "NoCollideVehicle", function(ply, vehicle) if ply:IsValid(Vehicle:GetDriver()) then vehicle:SetCollisionGroup(COLLISION_GROUP_WEAPON) end end) [/lua] and [lua] hook.Add("PlayerSpawnedVehicle", "NoCollideVehicle", function(ply, vehicle) ply:IsValid(Vehicle:GetDriver()) vehicle:SetCollisionGroup(COLLISION_GROUP_WEAPON) end) [/lua] Both actually fully enable the collisions for the cars instead of just when there isn't an occupant. Any other ideas?
You'll need to run it in a think hook or in player enter & exit vehicle hooks.
[lua]ply:IsValid(Vehicle:GetDriver())[/lua] I am fairly sure that the [b][url=http://gmodwiki.net/Lua/Classes/Entity/IsValid]Lua/Classes/Entity/IsValid[img]http://gmodwiki.net/favicon.ico[/img][/url][/b] method doesn't accept an argument. You probably want the global function [b][url=http://gmodwiki.net/Lua/Global/IsValid]Lua/Global/IsValid[img]http://gmodwiki.net/favicon.ico[/img][/url][/b].
[QUOTE=Robotboy655;41917647]You'll need to run it in a think hook or in player enter & exit vehicle hooks.[/QUOTE] I don't know how to do that. Care to share? My lua experience is extremely basic.
[QUOTE=Cjmax;41917831]I don't know how to do that. Care to share? My lua experience is extremely basic.[/QUOTE] Here's an example of doing it in a think hook. [lua]--shit happens here hook.Add("Think", "NoCollideVehicleCheck", function() for k,v in ipairs(ents.GetAll()) do --loop all entities if IsValid(v) and v:IsVehicle() then --is it a vehicle? --Check collision group and driver status if v:GetCollisionGroup()~=COLLISION_GROUP_WEAPON and IsValid(v:GetDriver()) then --we HAVE a driver and we AREN'T no collided, change to nocollide v:SetCollisionGroup(COLLISION_GROUP_WEAPON) elseif (not IsValid(v:GetDriver()) and v:GetCollisionGroup()==COLLISION_GROUP_WEAPON then --we DONT have a driver and we ARE no collided, stop no colliding v:SetCollisionGroup(COLLISION_GROUP_VEHICLE) --restore whatever the normal collision group is end end end end)[/lua] I can imagine some in game problems with this though, like people driving their nocollided car INTO another player then exitting the car, trapping that person.
Thanks a lot for the help man. I thought about that trapping issue, but I don't think it will be that big of an issue. I'm making cars permanent but pricey, so that narrows down the people who will be capable of trapping others to the more dedicated players. Even then, cars have names on them so reporting it would be really easy especially when there's an admin on almost all the time. But really that's a big help, I just got off work so I'm going to try it when I get home.
Sorry, you need to Log In to post a reply to this thread.