A possible alternate approach, and another episode of "I'll never use this outside of school",
[img]http://puu.sh/naT6V/f11a06b25f.png[/img]
The angle you likely want is theta, the angle between the hypotenuse and the opposite. Since we know two points, we know the third must be a right angle as noted.
We know the direction the player is looking ( the opposite side of the triangle ), and the angle between the player and the other entity, which is the hypotenuse.
We know the desired angle is equal to the dot product between these two normalized vectors, and that the dot product is equal to the cosine of that angle, so we just need to invert it.
[code]a = Player:GetPos( )
b = Target:GetPos( )
a.z = 0
b.z = 0
c = Player:GetAimVector( )
d = ( a - b ):GetNormalized( )
theta = math.deg( math.arccos( c:Dot( d ) )
[/code]
You may need to reverse b and a when getting it normalized, and you will be limited from 0 to 180 degrees since it has a domain of 0 to pi.
Disclaimer: I should be in bed 20 minutes ago, so I am possibly wrong/insane.
[QUOTE=Kogitsune;49757238]A possible alternate approach, and another episode of "I'll never use this outside of school",
[img]http://puu.sh/naT6V/f11a06b25f.png[/img]
The angle you likely want is theta, the angle between the hypotenuse and the opposite. Since we know two points, we know the third must be a right angle as noted.
We know the direction the player is looking ( the opposite side of the triangle ), and the angle between the player and the other entity, which is the hypotenuse.
We know the desired angle is equal to the dot product between these two normalized vectors, and that the dot product is equal to the cosine of that angle, so we just need to invert it.
[code]a = Player:GetPos( )
b = Target:GetPos( )
a.z = 0
b.z = 0
c = Player:GetAimVector( )
d = ( a - b ):GetNormalized( )
theta = math.deg( math.arccos( c:Dot( d ) )
[/code]
You may need to reverse b and a when getting it normalized, and you will be limited from 0 to 180 degrees since it has a domain of 0 to pi.
Disclaimer: I should be in bed 20 minutes ago, so I am possibly wrong/insane.[/QUOTE]
While that is still helpful, that's not quite what I mean.
Perhaps compass isn't the right word.
This is the result I'm trying to achieve.
[t]https://puu.sh/naLAz.jpg[/t]
That was made using ToScreen and only using the X value, but the white markers represent an npc. The reason ToScreen isn't optimal is because if I look up or down too far, the markers freak out
[QUOTE=Splerge;49755112]this is called clientside? It has to check each players model, read the post[/QUOTE]
Sorry, i though you were running the thing serverside and i also didnt see the :GetModel thing.
I was very sleepy.
Sorry.
I'm still learning and can't seem to get my head round the concept of using the 'or' operator correctly.
What I'm trying to do here is:
User inputs something,
If the user input [B]is not[/B] "james" or "admin" then print something and ask for the input again,
If the input [B]is[/B] "james" or "admin" then print something and move on.
[Lua]
print ('Enter your username:')
username = io.read()
while username ~= "james" or username ~= "admin" do
print ("Sorry, don't recognise that name.")
username = io.read()
if username == "james" or username == "admin" then
print ('Wohoo! off you go')
end
end
[/Lua]
There is obviously another way to solve the problem (perhaps using boolean values), but I wanted to try getting this to work.
[QUOTE=jameZplays;49758880]I'm still learning and can't seem to get my head round the concept of using the 'or' operator correctly.
What I'm trying to do here is:
User inputs something,
If the user input [B]is not[/B] "james" or "admin" then print something and ask for the input again,
If the input [B]is[/B] "james" or "admin" then print something and move on.
[Lua]
print ('Enter your username:')
username = io.read()
while username ~= "james" or username ~= "admin" do
print ("Sorry, don't recognise that name.")
username = io.read()
if username == "james" or username == "admin" then
print ('Wohoo! off you go')
end
end
[/Lua]
There is obviously another way to solve the problem (perhaps using boolean values), but I wanted to try getting this to work.[/QUOTE]
What output are you getting?
[QUOTE=wholegamer;49758909]What output are you getting?[/QUOTE]
It's just going back to asking for the input again.
I've tried a different approach and nearly solved it with this mess:
[Lua]
print ('Enter your username:')
key = false
while key == false do
print ("Sorry, don't recognise that name.")
username = io.read()
if username == "james" then
key = true
elseif input == "admin" then
key = true
else key = false
print ("Ah Ah Ahhh!")
username = io.read()
end
if key == true then
print ('Wohoo! off you go')
end
end
[/Lua]
[QUOTE=jameZplays;49758880]I'm still learning and can't seem to get my head round the concept of using the 'or' operator correctly.
What I'm trying to do here is:
User inputs something,
If the user input [B]is not[/B] "james" or "admin" then print something and ask for the input again,
If the input [B]is[/B] "james" or "admin" then print something and move on.
[Lua]
print ('Enter your username:')
username = io.read()
while username ~= "james" or username ~= "admin" do
print ("Sorry, don't recognise that name.")
username = io.read()
if username == "james" or username == "admin" then
print ('Wohoo! off you go')
end
end
[/Lua]
There is obviously another way to solve the problem (perhaps using boolean values), but I wanted to try getting this to work.[/QUOTE]
[Lua]
while username ~= "james" or username ~= "admin" do
[/Lua]
Your variable can't be == james and == admin
2 solutions:
[Lua]
while username == "james" or username == "admin" do
[/Lua]
or
[Lua]
while username ~= "james" and username ~= "admin" do
[/Lua]
[QUOTE=guigui;49758993][Lua]
while username ~= "james" or username ~= "admin" do
[/Lua]
Your variable can't be == james and == admin
2 solutions:
[Lua]
while username == "james" or username == "admin" do
[/Lua]
or
[Lua]
while username ~= "james" and username ~= "admin" do
[/Lua][/QUOTE]
No, and is not going to work as a string cannot have two values simultaneously.
Is it printing "Sorry, don't recognise that name."?
[editline]17th February 2016[/editline]
Also, I wrote this, it's hypothetical, may not work.
[LUA]
local names = {}
names[1] = "james"
names[2] = "admin"
while true do
username = io.read()
for k,v in pairs(names) do
if (username == names[v]) then print("Wohoo! off you go") end
end
end
[/LUA]
[QUOTE=wholegamer;49759109]No, and is not going to work as a string cannot have two values simultaneously.
Is it printing "Sorry, don't recognise that name."?
[editline]17th February 2016[/editline]
Also, I wrote this, it's hypothetical, may not work.
[LUA]
local names = {}
names[1] = "james"
names[2] = "admin"
while true do
username = io.read()
for k,v in pairs(names) do
if (username == names[v]) then print("Wohoo! off you go") end
end
end
[/LUA][/QUOTE]
Unfortunetly it didn't.
I've tried to hump it into submission with the following, but still no joy:
[Lua]
local names = {}
names[1] = "james"
names[2] = "admin"
key = false
while key == false do
print ("Enter your username")
username = io.read()
for k,v in pairs(names) do
if (username == names[v]) then key = true
print("Wohoo! off you go") end
end
end
[/Lua]
Try running stuff on this site: [url]http://www.tutorialspoint.com/execute_lua_online.php[/url]
[QUOTE=wholegamer;49759109]No, and is not going to work as a string cannot have two values simultaneously.
[/QUOTE]
You should reread my answers, this is exactly what I’m saying and why
[Lua]
username ~= "james" or username ~= "admin"
[/Lua]
will never be "false"
Ah FFS!
Change the 'or' to 'and':
[Lua]
print ('Enter your username:')
username = io.read()
while username ~= "james" and username ~= "admin" do
print ("Sorry, don't recognise that name.")
username = io.read()
if username == "james" and username == "admin" then
print ('Wohoo! off you go')
end
end
[/Lua]
I'm happy now : D
[QUOTE=jameZplays;49759483]Ah FFS!
Change the 'or' to 'and':
[Lua]
print ('Enter your username:')
username = io.read()
while username ~= "james" and username ~= "admin" do
print ("Sorry, don't recognise that name.")
username = io.read()
if username == "james" and username == "admin" then
print ('Wohoo! off you go')
end
end
[/Lua]
I'm happy now : D[/QUOTE]
You might want to put a delay in there or it's going to very quickly take up a lot of I/O and processing, and people don't type instantly.
[QUOTE=Ghost_Sailor;49760593]You might want to put a delay in there or it's going to very quickly take up a lot of I/O and processing, and people don't type instantly.[/QUOTE]
except reading from stdin makes it wait until you press enter...
[QUOTE=jameZplays;49758880]I'm still learning and can't seem to get my head round the concept of using the 'or' operator correctly.
What I'm trying to do here is:
User inputs something,
If the user input [B]is not[/B] "james" or "admin" then print something and ask for the input again,
If the input [B]is[/B] "james" or "admin" then print something and move on.
[Lua]
print ('Enter your username:')
username = io.read()
while username ~= "james" or username ~= "admin" do
print ("Sorry, don't recognise that name.")
username = io.read()
if username == "james" or username == "admin" then
print ('Wohoo! off you go')
end
end
[/Lua]
There is obviously another way to solve the problem (perhaps using boolean values), but I wanted to try getting this to work.[/QUOTE]
[code]while not ( username == "james" or username == "admin" )[/code]
The main thing is we want to test if username is either value - so we perform both tests inside parenthesis to obey order of operations. Since we only want to repeat when it is neither of those names, we'll invert it.
So, if we assume that username = "bill" then the following is what is checked:
[code]while not ( "bill" == "james" or "bill" == "admin" ) do
while not ( false or false ) do
while not false do
while true do[/code]
But if it matches either condition, then
[code]while not ( "admin" == "james" or "admin" == "admin" ) do
while not ( false or true ) do
while not true do
while false do[/code]
[code]
local icon = vgui.Create( "DModelPanel" )
icon:SetSize( 800, 600 )
icon:Center()
icon:SetModel( LocalPlayer():GetModel() ) -- you can only change colors on playermodels
icon:GetEntity():SetBodygroup(0,LocalPlayer():GetBodygroup(0))
icon:GetEntity():SetBodygroup(1,LocalPlayer():GetBodygroup(1))
function icon:LayoutEntity( Entity ) return end -- disables default rotation
function icon.Entity:GetPlayerColor() return LocalPlayer():GetColor() end --we need to set it to a Vector not a Color, so the values are normal RGB values divided by 255.
icon:GetEntity():SetBodygroup(0,1)
[/code]
This isnt setting the icons bodygroup
I'm sorry if this is the wrong place to ask, but I'm trying to make some basic NPCs for garry's mod.
Before the gm13 update, this code worked. Now I managed to fix the "ValidEntity" error, but now it says it can't find the model specified.
I want it to look for males 1 - 9 on one set and males 1 - 11 on another set and randomly pick one when the NPC is spawned.
[code]
local Category = "Star Wars"
local NPC = {
Name = "Rebel Trooper",
Class = "npc_citizen",
Model = "models/SGG/Starwars/r_trooper/male_01.mdl",
Category = Category,
SpawnFlags = SF_CITIZEN_RANDOM_HEAD,
KeyValues = { citizentype = CT_REBEL, trooper = 1 },
Weapons = { "weapon_pistol", "weapon_ar2", "weapon_smg1", "weapon_ar2", "weapon_shotgun" }
}
list.Set( "NPC", "Rebel_Trooper", NPC )
hook.Add("PlayerSpawnedNPC", "trooper_initmodel", function(pl, npc)
if IsValid(npc) then
local keyValues = npc:GetKeyValues()
if keyValues["trooper"] then
local nTrooper = tonumber(keyValues["trooper"])
if nTrooper == 1 then
npc:SetModel("models/SGG/Starwars/r_trooper/male0" .. math.random(1,9) .. ".mdl")
end
end
end
end)
[/code]
Hello,
does anyone have some hints on how to create a simple defibrillator?
Which functions are useful to revive the player to the spot where he has been revived?
How can i set the bodygroups of a modelpanel?
[QUOTE=Googlez;49766628]How can i set the bodygroups of a modelpanel?[/QUOTE]
DModelPane:GetEntity():SetBodygroup(), basically the same way you'd do it for any entity.
[QUOTE=thejjokerr;49766369][img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/PLAYER/Spawn]PLAYER/Spawn[/url]
Depending on what gamemode you are running, you may also have to get the position of the ragdoll as it may have been moved.
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/GetPos]Entity:GetPos[/url]
In DarkRP there is a sleeping ragdoll:
[url]https://github.com/FPtje/DarkRP/blob/master/gamemode/modules/sleep/sv_sleep.lua#L62[/url][/QUOTE]
That helped a lot, thanks!
Does anybody know how I can refuse players to respawn? (left click)
[QUOTE=P4sca1;49767402]That helped a lot, thanks!
Does anybody know how I can refuse players to respawn? (left click)[/QUOTE]
[URL="https://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index8cd4-2.html"]https://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index8cd4-2.html[/URL]
[QUOTE=Robotboy655;49767233]DModelPane:GetEntity():SetBodygroup(), basically the same way you'd do it for any entity.[/QUOTE]
I tried this doesnt work. ;-;
[QUOTE=Robotboy655;49767233]DModelPane:GetEntity():SetBodygroup(), basically the same way you'd do it for any entity.[/QUOTE]
This doesnt work, i tried it.
[QUOTE=Shenesis;49689563]Has anyone encountered an issue with ClientsideModels where they sometimes "lag" behind their intended position?
Here's a video of it happening:
[vid]https://my.mixtape.moe/bgqwhy.webm[/vid][/QUOTE]
I have that same issue for items attached to player models. In my tests, I have evidence that points that it may be related to LagCompensation, as it ALWAYS happens with anything that enables it. It's almost like when it's enabled the bone positions retrieved for the model change to the bone positions used by lag compensation(when it goes back in time to a 'ping ago' to run the traces again). Which doesn't really make sense, as that's server sided..
It's very odd.
[QUOTE=Googlez;49768947]This doesnt work, i tried it.[/QUOTE]
You sure that the model that you are teying to modify has bodygroups?
Okay so heres the scenario
So Im loading my Main table data from the players data, but for each key in the main table they have their own table,[B][U] for example[/U][/B]
[CODE]GMI.Businesses = {
Lemonade = {
name = 'lemonade',
price = 1,
amount = 0,
income = 1,
timerlength = 1,
timerstart = false
},
Mail = {
name = 'Mail',
price = 20,
amount = 0,
income = 6,
timerlength = 60,
timerstart = false
}
}[/CODE]
but when I load the data, then try and print the data with this
[CODE]for k, v in pairs(business) do --business is the players data verison of the GMI.Business
print(" ~"..k)
for key, val in pairs(v) do
print(' '..key.." : ".. val )
end
end[/CODE]
[B]i get an error of[/B]
[QUOTE]
[ERROR] addons/gminvest/lua/gmodinvest/cli_init.lua:47: bad argument #1 to 'pairs' (table expected, got number)
1. pairs - [C]:-1
2. func - addons/gminvest/lua/gmodinvest/cli_init.lua:47
3. unknown - lua/includes/extensions/net.lua:32
[/QUOTE]
[B]So I changed the print out to this[/B]
[CODE]for k, v in pairs(business) do --business is the players data verison of the GMI.Business
print(k)
for key, val in pairs(v) do
print(key)
end
end[/CODE]
[B]and the output was this
[/B]
[QUOTE]Mail
table: 0x29780108
BabySitter
table: 0x2977ff28
Lemonade
table: 0x29780018
Movies
table: 0x2977fe38[/QUOTE]
So my question is, how can I get it to actually print the table instead of the (table: 0x29780108)
[QUOTE=funnygamemake;49772829]badly indented code[/QUOTE]
uh. i have no idea what's going on here...
for one, swapping out the printing thing you have there shouldn't have fixed the error because you're still using pairs, which is what the error is complaining about
and then, with the supposed output, it appears the keys are actually tables??
either i'm going crazy or you have no idea how to code
[QUOTE=funnygamemake;49772829]
So my question is, how can I get it to actually print the table instead of the (table: 0x29780108)[/QUOTE]
The first error is weird because changing what you did shouldn't have fixed it.
As for the printing, that's because the default print function doesn't print the keys and values, just the table's address. Use [IMG]http://wiki.garrysmod.com/favicon.ico[/IMG] [URL="http://wiki.garrysmod.com/page/Global/PrintTable"]Global.PrintTable[/URL] instead
[QUOTE=bigdogmat;49772941]It prints that because the default print function doesn't print tables, just their addresses. Use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/PrintTable]Global.PrintTable[/url] instead[/QUOTE]
he's printing the table's [U]keys[/U] though, so why would it print tables?
the only logical answer would be that the table's keys are tables, he's either saving the tables wrong or ballsing up the code completely
[QUOTE=TrenchFroast;49772954]he's printing the table's [U]keys[/U] though, so why would it print tables?
the only logical answer would be that the table's keys are tables, he's either saving the tables wrong or ballsing up the code completely[/QUOTE]
Oh I didn't notice, his example table must be wrong.
Sorry, you need to Log In to post a reply to this thread.