General > Developers Corner
Vehicle restricting
ahref:
Im fed up with people coming on my server to drive around in a car ITS FLAT GRASS. so i want to restrict vehicles to only the prisoner pod so that none of the others can be spawned unless the player is an admin of course.
heres my current code and its not working:
--- Code: ---function GAMEMODE:PlayerSpawnVehicle( ply, prop )
return spawned_vehicle( ply, prop )
end
function spawned_vehicle( ply, prop )
if ( SinglePlayer() ) then return true end
if ply:IsAdmin() or ply:IsSuperAdmin() then
return true
end
if ( prop != "prop_vehicle_prisoner_pod" ) then
ply:PrintMessage( HUD_PRINTTALK, "This is Garrys Mod BUILD A VEHICLE(seats and pods are still allowed)" )
return false
else
return true
end
end
--- End code ---
what am i dont wrong?
JamminR:
What isn't working? Non admins still allowed to spawn vehicles?
ahref:
yes
JamminR:
Few quick theories; test at your own pace. :P
I poked around in Garry's code by looking in gmod/gamemodes/sandbox .. player.lua and command.lua. (He REALLY needs to update code.garrysmod.com - it's quite out of date.
First;
Isn't prop_blah_blah an entity class, not a model? The references in his code all seem like it would be a model.
(Still seems that should return false though)
Second;
It's been my experience in Lua to place function BEFORE the call to the function. You currently have it backwards.
No idea if that's required for it to work, but it's definitely good practice.
Third;
Tried making functions local? See UNoLimited as an example. (I'm not 100% sure why Megiddo made them local, but I saw that it was, kept it that way, and it worked)
Also, part of this theory...anytime you attempt to spawn a prop, Gmod tries to check to see if the sbox_ limits are set for it... it's possible that function is getting called before yours is.
Fourth...
You're forcing this to run on the server and not the client, right?
Someone else could help here I'm sure.
I'm gonna go play some Fallout 3 now. Had no idea a "choose your own adventure" book (in theory) had been turned into a game.
ahref:
yes i read unolimited to see how it worked. It also had an init function with nothing in it:
--- Code: ---local function init()
and later on
hook.Add( "Initialize", "LimitInitilize", init )
--- End code ---
@first - i can try models :D
@second - oo thats my fault i had a standard hook in there before.
@third - will try
@fourth - its in my server autorun :D
Navigation
[0] Message Index
[#] Next page
Go to full version