Seems like something is conflicting with your code, it should work just fine. Maybe you can share the code and we could take a look; if not, there isn't much help we can do :l
[QUOTE=Drakehawke;36121808]You can't until the first player has joined, if a player joins and then leaves you can still run queries with no players, but you can't run any queries between the server starting up and the first player joining.[/QUOTE]
[lua]hook.Add("InitPostEntity", "Enable Queries", function()
game.ConsoleCommand("bot\n");
timer.Simple(0, game.ConsoleCommand, "kick bot01\n");
end);[/lua]
[QUOTE=Lexic;36123239][lua]hook.Add("InitPostEntity", "Enable Queries", function()
game.ConsoleCommand("bot\n");
timer.Simple(0, game.ConsoleCommand, "kick bot01\n");
end);[/lua][/QUOTE]
You shouldn't really even need to do that, any queries you try and run should be ran properly when the first player does join.
[QUOTE=Drakehawke;36123206]Team shouldn't be nil, that would mean the thing you're calling it on isn't a player, which would be LocalPlayer(). You'll have to post more code if you want any more help.[/QUOTE]
There isn't much to post.
[lua]if LocalPlayer():Team() == 0 then
for Icon, Entity in pairs (RegularBuyList) do
Icon = vgui.Create( "Spawnicon" )
Icon:SetModel( ModelList[Entity] )
Icon:SetToolTip (Entity)
Icon.OnMousePressed = function()
RunConsoleCommand ("RP_Buy", Entity)
LocalPlayer():EmitSound( "ambient/levels/canals/drip1.wav", 150, 50 );
end
Icon.OnCursorEntered = function()
Hover[Icon] = true
end
Icon.OnCursorExited = function()
Hover[Icon] = false
end
Icon.Paint = function()
if Hover[Icon] == true then
draw.RoundedBox( 8, 0, 0, 64, 64, Color( 100, 0, 0, 200 ) )
else
draw.RoundedBox( 8, 0, 0, 64, 64, Color( 0, 0, 0, 200 ) )
end
end
DermaList:AddItem( Icon )
end
end[/lua]
It's basically right there. All I can think of is that it's allways Nil because this is called before the players team is set, but if that's the case should i just set it to if LocalPlayer():Team() == nil || LocalPlayer():Team() == 0 ?
[QUOTE=Drakehawke;36123274]You shouldn't really even need to do that, any queries you try and run should be ran properly when the first player does join.[/QUOTE]
It might not be strictly speaking necessary, but it's still an option he might want to take.
[QUOTE=kp3;36122998]I'm having issues with getting the players current team in a clientside script.
I'm using LocalPlayer():Team() for a derma panel in cl_init.
I get this:
[code][gamemodes\kush\gamemode\cl_init.lua:78] attempt to call method 'Team' (a nil value)[/code]
Is there another way I should be doing this?
I'm basically doing "if LocalPlayer():Team() == 1 then".
I saw it being used here: [url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index4cc3.html?title=Fretta_Derma_Panel[/url][/QUOTE]
The only thing I can think if is that your code is running before the InitPostEntity hook has been called.
[QUOTE=ralle105;36123477]The only thing I can think if is that your code is running before the InitPostEntity hook has been called.[/QUOTE]
It's in cl_init for my gamemode. LocalPlayer():Health() works fine so shouldn't this?
[QUOTE=kp3;36123521]It's in cl_init for my gamemode. LocalPlayer():Health() works fine so shouldn't this?[/QUOTE]
cl_init would be ran before the player exists I think, and before the team is even set, making checking the team completely redundant. If this is for a menu you probably want to be doing this in the function that opens the menu, rather than in the file itself.
I have this ATM Cracker I'm working on that I based off the keypad cracker.
It's supposed to have a 3 minute delay between each crack it just says "You must wait 3 minutes inbetween cracking ATM's!" x3 and it starts to crack without showing the progress bar.
It still says how much you stole and gives you the money.
And after you crack it spams "You must wait 3 minutes inbetween cracking ATM's" x4 and it stops you from cracking.
Code: [url]http://pastebin.com/kMqsNBBC[/url]
[QUOTE=Drakehawke;36123600]cl_init would be ran before the player exists I think, and before the team is even set, making checking the team completely redundant. If this is for a menu you probably want to be doing this in the function that opens the menu, rather than in the file itself.[/QUOTE]
Made it update the icons every time you open it instead, Which makes more sense because I'll be having different teams that can buy different things. Thanks.
I was wondering if anyone would be able to tell/help me make it so that in DarkRP only a certain ulx group (VIP and above) will be able to have certain weapons/entities.
For example i only want VIPs to have access to fists, on all jobs. Is there an easy way to do this?
Also i want so only VIPs can have/use the tazer when cop/swat... etc.
Reply back on here or message me on steam if needed :)
Thanks
Toby
Steam [url]http://steamcommunity.com/profiles/76561198005643722/[/url]
So some crazy math shit I need help with. No idea where to start, if anyone has done anything like this please let me know.
I'm recreating the Aerial Faith Plate for GMod. I have the base of it working and now I have a Stool that I'm going to use to set the landing location and the jump height.
Location will be set by right click on the STool and the height with a CPanel Slider.
The things we know:
-Where the landing pad position is
-Angle between the pad and the landing position
-The jump height
-Launching objects mass
-Gravity (sv_gravity)
Things we dont know:
-Required force to push to correct location
-Required angle to push at
I haven't taken enough physics to know where to really start with this.
I know we're going to need some kind of trajectory nonsense but again, no idea where to start.
Thoughts?
As far as I know, the trajectory path is a parabel. [img]http://www.knifethrowing.info/images/Physik_trajectory_of_the_throwing_knife.gif[/img]
You have to know how Source engine handles applying gravity to an object to correctly calculate the path. The required force you need is, again, as far as I know, calculated with the potential energy and kinetic energy formulas.
Goes like this: in a gravitational field, the potential energy an object has at a certain height, is calculated with the formula E = [I]mgh[/I], and the kinetic energy of an object is calculated with the formula E = (1/2)*mv^2. ( m = mass, g = gravitational pull( 9,81m/s^2 on Earth ), h = height )
---> mgh = (1/2)*mv^2 <=> gh = (1/2)*v^2 <=> v = sqrt( 2gh )
So the velocity you need to apply for the object to reach the highest point of the parabel( from that moment it will just fall to the desired position by itself ), is calculated with v = sqrt( 2gh ).
I think the tangent of the parabel at the launching point has something to do with this too, but can't think of anything right now. I haven't even tested this, but I think this would be a good start for you.
If anything in this is wrong please do correct me.
I am wondering if anyone can fix this code so that it only opens up one reason box when you right click. At the moment when you right click whilst looking at a player it opens 3 or 4 reason boxes when im looking for it to just open one. Here is the code.
[lua]
function SWEP:SecondaryAttack()
local trace = self.Owner:GetEyeTrace()
if trace.Entity:IsPlayer() then
Derma_StringRequest("wanted reason", "Enter the reason to arrest this player", "", function(Reason)
LocalPlayer():ConCommand("say /wanted ".. trace.Entity:UserID().." ".. Reason)
end)
end
end
[/lua]
Post a reply here or add me on steam if you need more information. Steam = [url]http://steamcommunity.com/profiles/76561198005643722/[/url]
Thanks Toby
[QUOTE=TobyB;36145834]I am wondering if anyone can fix this code so that it only opens up one reason box when you right click. At the moment when you right click whilst looking at a player it opens 3 or 4 reason boxes when im looking for it to just open one. Here is the code.
[lua]
function SWEP:SecondaryAttack()
local trace = self.Owner:GetEyeTrace()
if trace.Entity:IsPlayer() then
Derma_StringRequest("wanted reason", "Enter the reason to arrest this player", "", function(Reason)
LocalPlayer():ConCommand("say /wanted ".. trace.Entity:UserID().." ".. Reason)
end)
end
end
[/lua]
Post a reply here or add me on steam if you need more information. Steam = [url]http://steamcommunity.com/profiles/76561198005643722/[/url]
Thanks Toby[/QUOTE]
Because it's calling SecondaryFire more than once.
Your best bet is to make the secondary fire not automatic.
Either change or put in the line that says
SWEP.Secondary.Automatic = true
In your SWEP to
SWEP.Secondary.Automatic = false
That way it will only call once when you click
[editline]31st May 2012[/editline]
[QUOTE=whitespace;36142232]As far as I know, the trajectory path is a parabel. [img]http://www.knifethrowing.info/images/Physik_trajectory_of_the_throwing_knife.gif[/img]
You have to know how Source engine handles applying gravity to an object to correctly calculate the path. The required force you need is, again, as far as I know, calculated with the potential energy and kinetic energy formulas.
Goes like this: in a gravitational field, the potential energy an object has at a certain height, is calculated with the formula E = [I]mgh[/I], and the kinetic energy of an object is calculated with the formula E = (1/2)*mv^2. ( m = mass, g = gravitational pull( 9,81m/s^2 on Earth ), h = height )
---> mgh = (1/2)*mv^2 <=> gh = (1/2)*v^2 <=> v = sqrt( 2gh )
So the velocity you need to apply for the object to reach the highest point of the parabel( from that moment it will just fall to the desired position by itself ), is calculated with v = sqrt( 2gh ).
I think the tangent of the parabel at the launching point has something to do with this too, but can't think of anything right now. I haven't even tested this, but I think this would be a good start for you.
If anything in this is wrong please do correct me.[/QUOTE]
Thanks! I think that will help in a way with finding the force required, but need to find the appropriate angle as well. The yaw will be easy, its just finding the pitch that will be a bitch.
I'm creating some train sort of system however I have the spawning and all working but I cannot figure out the collision of the trains here is a screenshot:
[url]http://cloud.steampowered.com/ugc/578957683410101663/E2F1E8AF10FA7D404D533887178D66B2DD7F77CE/[/url]
Ignore the bad positioning of the train but basically even when pulled out of the ground it just floats in the air here is the code:
[lua]
function starttrain()
SpawnTrain( Vector(683.428162, -2151.920166, 91.897896), 0 )
end
concommand.Add( "trololol", starttrain )
function SpawnTrain( Pos, Direction )
local train = ents.Create( "prop_physics" )
train:SetModel("models/props_trainstation/train001.mdl")
train:SetAngles(Angle(0,0,0))
train:SetPos( Pos )
train:Spawn()
train:SetMoveType( MOVETYPE_FLY )
//train:Activate()
train:EmitSound( "ambient/alarms/train_horn2.wav", 100, 100 )
train:GetPhysicsObject():SetVelocity( Vector(0,3000,0) )
//constraint.NoCollide(train,GetWorldEntity(),0,0)
timer.Create( "TrainRemove_"..CurTime(), 5, 1, function( train ) train:Remove() end, train )
end
[/lua]
Now I know train:SetMoveType( MOVETYPE_FLY ) is causing that however I cant seem to find one that basically freezes the train however it can move when Velocity is added to it (It also collides with the player but won't be stopped by them either).
I'm also probably not doing this the best way either.
[lua]table.SortByMember(wr, "time", function(a, b) return a < b end)[/lua]
After populating my table "wr" (I am positive it is populated, check image at bottom) and trying to sort the members by their time, it does not affect the table at all in my for loops.
[lua]for _,v in ipairs(wr) do
if v["name"] and v["time"] and v["steamid"] then
records:AddLine(v["name"], string.ToMinutesSeconds(v["time"]))
end
end[/lua]
Anyone got any theories?
[img]http://i.imgur.com/2IBcy.png[/img]
Try table.sort.
[lua]table.sort(wr, function(a, b) return a.time < b.time end)[/lua]
[QUOTE=Feihc;36146277]Because it's calling SecondaryFire more than once.
Your best bet is to make the secondary fire not automatic.
Either change or put in the line that says
SWEP.Secondary.Automatic = true
In your SWEP to
SWEP.Secondary.Automatic = false
That way it will only call once when you click
[/QUOTE]
This doesn't work. Still calls it 3/4 times even with it set to false
[QUOTE=thejjokerr;36154880]Does anyone know if there's a proper way to set the GWEN skin already? And how do I change the colour of text in a textentry? I've tried modifying the the GWEN skin image and using SetTextColor on the textentry panel neither worked.[/QUOTE]
Garry's adding that in Update 20.
Toby, add this:
[lua]
self:SetNextPrimaryFire(CurTime() + 1);
[/lua]
Hello, I'm a bit new to lua, but thought I'd take a crack at the using sound.Add(table) function to script sounds for the Gmod 13 Beta, is there any way to fix this:
[CODE]function sound.Add(soundtest)
local soundtest = {};
channel = CHAN_RELOAD;
level = SNDLVL_NORM;
sound = "uzi/clin.wav"
name = "Weapon_imuzi.Clipin"
end[/CODE]
giving an "attempt to index global 'sound' (a string value)" error?
I put it in an autorun file and it does nothing (no lua errors, no scripted sound playing), so I ran it through LuaPad (In-game lua editor/script runner) and got the above error.
[QUOTE=Alex_grist;36153758]Try table.sort.
[lua]table.sort(wr, function(a, b) return a.time < b.time end)[/lua][/QUOTE]
Worked flawlessly, thank you.
[QUOTE=Chessnut;36155642]
Toby, add this:
[lua]
self:SetNextPrimaryFire(CurTime() + 1);
[/lua][/QUOTE]
Where about do i add this?
Sorry if this is the wrong place to ask but, does anyone happen to have a link to a mirror of the wiki?
[QUOTE=I Fail At Lua;36160907]Sorry if this is the wrong place to ask but, does anyone happen to have a link to a mirror of the wiki?[/QUOTE]
[url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index4875.html?title=Main_Page[/url] (seems to be down for some reason)
[url]http://bananatree.im/wiki/wiki.garrysmod.com/index4875.html?title=Main_Page[/url]
[QUOTE=pennerlord;36160967][url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index4875.html?title=Main_Page[/url] (seems to be down for some reason)
[url]http://bananatree.im/wiki/wiki.garrysmod.com/index4875.html?title=Main_Page[/url][/QUOTE]
Ah thanks for the help man.
my copy (bananatree.im) will search my wiki now instead of maur's (thanks for pointing that out Capsadmin/Drake), but you can only search from the main page - I'm not updating a couple thousand files, sorry.
I have a table made up in this format:
[lua]mytable = {
["map_one"] = {},
["map_two"] = {},
["map_three"] = {},
}[/lua]
And I am trying to get 5 random keys from the table (The actual table has more than 5 keys) so I can start a map vote. How would I go by grabbing 5 random keys from that type of table?
edit:
Ended up being lazy:
[lua]local maps = maplocs
function StartVote()
local tovote = {}
local mapscopy = {}
for k,v in pairs(maps) do
table.insert(mapscopy, k)
end
while table.Count(tovote) < 4 do
local newentry = table.Random(mapscopy)
if !table.HasValue(tovote, newentry) then
table.insert(tovote, newentry)
end
end
PrintTable(tovote)
end[/lua]
[lua]
local temp_maplist = {}
local temp_map
local pickingmaps = 5
for i = 1, 5 do
if temp_maplist then
if mytable then
for i = 1, 5 do
temp_map = table.Random( mytable )
if not table.HasValue( temp_maplist, temp_map ) then
table.insert( temp_maplist, temp_map )
break
end
end
else
print('No Maplist')
end
end
end
[/lua]
Maybe like this?
[QUOTE=rebel1324;36162869][lua]
lotsa cod
[/lua]
Maybe like this?[/QUOTE]
You should be using a while loop. If your table happens to get duplicates, it won't be added to the table. And the method I posted in my edit worked fine.
Sorry, you need to Log In to post a reply to this thread.