[QUOTE=Garrison;46941022]How do I delete the players dead body from a "PlayerDeath" hook?[/QUOTE]
[url]http://wiki.garrysmod.com/page/Player/GetRagdollEntity[/url]
nvm figure out out. Thanks!
I'm trying to make gyroscope and I'm failing with yaw angle.
I'm applying force towards offset if entity's pitch angle isn't 0(same for roll and yaw).
[CODE]function ENT:Think()
if (self:GetNWBool("on")) then
if (!self.nextJet or CurTime() >= self.nextJet) then
local tr = {}
tr.start = self:GetPos()-Vector(0, 0, 0);
tr.endpos = self:GetPos()-Vector(0, 0, 16384);
tr.filter = self;
tr = util.TraceLine(tr);
if (tr.HitWorld) then
local finalPos = self:GetPos():Distance(tr.HitPos);
print(finalPos);
if (finalPos < self:GetNWInt("altitude")) then
self:GetPhysicsObject():SetVelocity(Vector(0, 0, self:GetNWInt("speed_z")));
elseif (finalPos > self:GetNWInt("altitude")) then
if (!self.nextJetZ or CurTime() >= self.nextJetZ) then
self:GetPhysicsObject():SetVelocity(Vector(0, 0, -(self:GetNWInt("speed_z")/2)));
self.nextJetZ = CurTime() + (self:GetNWInt("speed_time_z")*4);
end;
end;
if (finalPos > 0) then
for k, v in pairs(player.GetAll()) do
self:SetNWInt("target_p", v:GetAngles().p);
self:SetNWInt("target_r", v:GetAngles().p);
self:SetNWInt("target_y", math.NormalizeAngle(v:GetAngles().y));
end;
if (self:GetAngles().p != self:GetNWInt("target_p")) then
if (self:GetAngles().p < self:GetNWInt("target_p")) then
self:GetPhysicsObject():ApplyForceOffset(self:GetForward()*-self:GetNWInt("speed_f"), self:GetPos()+(self:GetUp()*-32)+(self:GetForward()*32));
elseif (self:GetAngles().p > self:GetNWInt("target_p")) then
self:GetPhysicsObject():ApplyForceOffset(self:GetForward()*self:GetNWInt("speed_f"), self:GetPos()+(self:GetUp()*-32)+(self:GetForward()*32));
end;
end;
if (self:GetAngles().r != self:GetNWInt("target_r")) then
if (self:GetAngles().r < self:GetNWInt("target_r")) then
self:GetPhysicsObject():ApplyForceOffset(self:GetRight()*-self:GetNWInt("speed_f"), self:GetPos()+(self:GetUp()*-32)+(self:GetRight()*32));
elseif (self:GetAngles().r > self:GetNWInt("target_r")) then
self:GetPhysicsObject():ApplyForceOffset(self:GetRight()*self:GetNWInt("speed_f"), self:GetPos()+(self:GetUp()*-32)+(self:GetRight()*32));
end;
end;
if (self:GetAngles().y != self:GetNWInt("target_y")) then --Problems begin here.
if (self:GetAngles().y < self:GetNWInt("target_y")) then
self:GetPhysicsObject():ApplyForceOffset(self:GetForward()*self:GetNWInt("speed_f"), self.skeletonS_R:GetPos()+self:GetForward()*8); -- Located on right side of entity
elseif (self:GetAngles().y > self:GetNWInt("target_y")) then
self:GetPhysicsObject():ApplyForceOffset(self:GetForward()*self:GetNWInt("speed_f"), self.skeletonS_L:GetPos()+self:GetForward()*8); -- Located ofc on left side of entity.
end;
end;
self.nextJet = CurTime() + self:GetNWInt("speed_time");
end;
end;
end;
end;
end;[/CODE]
As you see I'm trying to rotate it as player yaw but it starts rotating and doesn't stop. math.NormalizeAngle() didn't help too. Any ideas?
Instead of all of this.... Add a hook on CalcView, then have the view modified to move with the gyroscope instead of using a ton of GetNWs because they can cause lag...
Even attaching an invisible prisoner_pod or seat would work.
Does anyone else wish Source's Angle system was 0-359 degrees instead of whatever whacky bullshit it is now with the negatives and the inconsistencies and the headaches?
I don't understand the way gmod handles else if statements. I want my script to work like this
[CODE]
isfemale = false
isalien = false
if(isfemale)then
haveballs = false
isalien = false
end
else if(isalien)then
haveballs = false
isalien = true
end
[/CODE]
but the else if statement outputs errors if I don't just leave it as a basic if statement.
[lua]
isfemale = false
isalien = false
if(isfemale) then
haveballs = false
isalien = false
elseif(isalien) then
haveballs = false
isalien = true
end
[/lua]
elseif needs to be written together otherwise it means else, then if starts meaning you need 2 ends instead of 1. Additionally you have if female then .. end which means else / elseif can't come after an end.
Tabbing helps it make sense. Your code:
[code]isfemale = false
isalien = false
if(isfemale)then
haveballs = false
isalien = false
end
else
if(isalien)then
haveballs = false
isalien = true
end
[/code]
"fixed"
[code]isfemale = false
isalien = false
haveballs = false;
if ( isfemale ) then
// Female doesn't change anything, logically we don't need this.
elseif ( isalien ) then
// Alien only changes 1 thing
isalien = true
end [/code]
I'd recommend using tables to store data...
Here are some starting references, and after the references some examples:
-------------------------------------------------------------
Generalized Lua Help ( Links to Wikis, Answers the question of "Where do I post a simple question or DarkRP Specific question", links to other resources compiled by forum members )
[url]https://dl.dropboxusercontent.com/u/26074909/tutoring/___welcome_docs/_welcome_general_lua_learning.lua.html[/url]
Useful Programs ( SteamCMD, Autosizer, Desktops, Process Explorer ) and Notepad++ Upgrades
[url]https://dl.dropboxusercontent.com/u/26074909/tutoring/___welcome_docs/_welcome_useful_programs_and_notepadpp_upgrades.lua.html[/url]
[url]https://dl.dropboxusercontent.com/u/26074909/tutoring/strings/string_concatenation.lua.html[/url]
[url]https://dl.dropboxusercontent.com/u/26074909/tutoring/tables/quick_intro_to_tables.lua.html[/url]
[url]https://dl.dropboxusercontent.com/u/26074909/tutoring/time/understanding_time%20and_basic_time_calculations.lua.html[/url]
[url]https://dl.dropboxusercontent.com/u/26074909/tutoring/logic/ternary_operations.lua.html[/url]
And, this is my coding standards doc but it includes some things which you may find helpful ( such as the Lua to GLua changes where BOTH sets work, function creation, etc.. ): [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/_tutorial_quizzes/_coding_standards.lua.html[/url]
HUD Stuff: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/vgui/proper_hud_creation.lua.html[/url]
[url]https://dl.dropboxusercontent.com/u/26074909/tutoring/vgui/understanding_hardcoding_of_screensizes.lua.html[/url]
[url]https://dl.dropboxusercontent.com/u/26074909/tutoring/hud/basic_healthbar.lua.html[/url]
[b]Hopefully these tutorials and information helps. As always, to view the Lua from any of my tutorials to enable copy/pasting ( HTML doesn't copy/paste well in terms of HTML / CSS Highlighted Lua ), remove .html from the url.[/b]
[editline]16th January 2015[/editline]
[QUOTE=PortalGod;46943285][lua]
isfemale = false
isalien = false
if(isfemale) then
haveballs = false
isalien = false
elseif(isalien) then
haveballs = false
isalien = true
end
[/lua][/QUOTE]
-ninja'd- but nail on the head for correcting the code.
[QUOTE=Acecool;46943309]-huge amount of literature second in length only to the Bible-
[editline]16th January 2015[/editline]
-ninja'd- but nail on the head for correcting the code.[/QUOTE]
Acecool how do you ever not get ninja'd writing such long posts. You might as well just say you're ninja'd before editing it.
[QUOTE=bobbleheadbob;46943419]Acecool how do you ever not get ninja'd writing such long posts. You might as well just say you're ninja'd before editing it.[/QUOTE]
Ctrl+C, Ctrl+V
[QUOTE=Phoenixf129;46943662]Ctrl+C, Ctrl+V[/QUOTE]
Actually for the tut links they're in dropbox so I right click > copy public link. For the 2 resource links it is a bbcode mod that pastes it using right click > custom bbcode > help/resources
The rest is typed.
Alright, this is some grade-A bullshit. I've had this problem with two lua scripts I've made. They work perfectly fine when I drop them in garrysmod/lua/autorun but they refuse to work if I make an addon folder for them. For example here is a greentexting addon I made located at garrysmod/lua/autorun/greentext.lua:
[code]
function greentext( player, strText, bTeamOnly, bPlayerIsDead )
--
-- I've made this all look more complicated than it is. Here's the easy version
--
-- chat.AddText( player, Color( 255, 255, 255 ), ": ", strText )
--
local tab = {}
if ( bPlayerIsDead ) then
table.insert( tab, Color( 255, 30, 40 ) )
table.insert( tab, "*DEAD* " )
end
if ( bTeamOnly ) then
table.insert( tab, Color( 30, 160, 40 ) )
table.insert( tab, "( TEAM ) " )
end
if ( IsValid( player ) ) then
table.insert( tab, player )
else
table.insert( tab, "Console" )
end
table.insert( tab, Color( 255, 255, 255 ) )
table.insert( tab, ": ")
if (string.sub(strText,1,1) == ">") then
table.insert( tab, Color( 120, 153, 34 ) )
end
table.insert( tab, strText)
chat.AddText( unpack( tab ) )
return true
end
hook.Add( "OnPlayerChat", "Greentext", greentext)
AddCSLuaFile()
[/code]
It works perfectly fine but if I try to move the file to garrysmod/addons/Greentext/lua/autorun/greentext.lua it no longer works on the server. Same with this simple godmode script located at garrysmod/lua/autorun/godmode.lua:
[code]
function shouldDamage(ply, attacker)
return not attacker.ULXHasGod
end
hook.Add("PlayerShouldTakeDamage","GodCheckDamage",shouldDamage)
[/code]
If I try to move it to garrysmod/addons/Godmode/lua/autorun/godmode.lua it doesn't work either. Can anyone help me out here?
[url]http://wiki.garrysmod.com/page/Player_Classes[/url]
How are you meant to get player class information (other than the name)?
[editline]16th January 2015[/editline]
I tried [url]http://wiki.garrysmod.com/page/player_manager/GetPlayerClass[/url] but that only appears to get the name of the class, not the actual info about it.
You have to make functions that return it like such:
[lua]DEFINE_BASECLASS( "player_default" )
local PLAYER = {}
PLAYER.DisplayName = 'Civilian'
PLAYER.DropWeaponOnDie = false
PLAYER.WalkSpeed = 200
PLAYER.RunSpeed = 300
PLAYER.MaxHealth = 100
PLAYER.Salary = 50
function PLAYER:SetupDataTables()
self.Player:NetworkVar("Int",0,"IDNum")
end
function PLAYER:Spawn()
print('Spawned as civilian')
end
function PLAYER:Loadout()
self.Player:Give('weapon_physgun')
self.Player:Give('weapon_physcannon')
end
function PLAYER:GetSalary()
return self.Salary or 0
end
function PLAYER:GetJobName()
return self.DisplayName or 'Nothing'
end
function PLAYER:ResetWalkSpeed()
return self.Player:SetWalkSpeed(self.WalkSpeed)
end
function PLAYER:ResetRunSpeed()
return self.Player:SetRunSpeed(self.RunSpeed)
end
player_manager.RegisterClass('civilian', PLAYER, 'player_default')[/lua]
[QUOTE=michaelrule4;46943950]Alright, this is some grade-A bullshit. I've had this problem with two lua scripts I've made. They work perfectly fine when I drop them in garrysmod/lua/autorun but they refuse to work if I make an addon folder for them. For example here is a greentexting addon I made located at garrysmod/lua/autorun/greentext.lua:
[code]
function greentext( player, strText, bTeamOnly, bPlayerIsDead )
--
-- I've made this all look more complicated than it is. Here's the easy version
--
-- chat.AddText( player, Color( 255, 255, 255 ), ": ", strText )
--
local tab = {}
if ( bPlayerIsDead ) then
table.insert( tab, Color( 255, 30, 40 ) )
table.insert( tab, "*DEAD* " )
end
if ( bTeamOnly ) then
table.insert( tab, Color( 30, 160, 40 ) )
table.insert( tab, "( TEAM ) " )
end
if ( IsValid( player ) ) then
table.insert( tab, player )
else
table.insert( tab, "Console" )
end
table.insert( tab, Color( 255, 255, 255 ) )
table.insert( tab, ": ")
if (string.sub(strText,1,1) == ">") then
table.insert( tab, Color( 120, 153, 34 ) )
end
table.insert( tab, strText)
chat.AddText( unpack( tab ) )
return true
end
hook.Add( "OnPlayerChat", "Greentext", greentext)
AddCSLuaFile()
[/code]
It works perfectly fine but if I try to move the file to garrysmod/addons/Greentext/lua/autorun/greentext.lua it no longer works on the server. Same with this simple godmode script located at garrysmod/lua/autorun/godmode.lua:
[code]
function shouldDamage(ply, attacker)
return not attacker.ULXHasGod
end
hook.Add("PlayerShouldTakeDamage","GodCheckDamage",shouldDamage)
[/code]
If I try to move it to garrysmod/addons/Godmode/lua/autorun/godmode.lua it doesn't work either. Can anyone help me out here?[/QUOTE]
I forgot to mention that I've tried with an addon.txt file in the addon folder but that hasn't changed anything.
[lua]print( os.date( "%l:%M %p", os.time( ) ) )[/lua]
Why does this crash my game? I'm running the base gamemode with no addons. I tried that line with both a script and with lua_run. Am I doing something stupid I shouldn't be doing?
[QUOTE=zeaga;46944332][lua]print( os.date( "%l:%M %p", os.time( ) ) )[/lua]
Why does this crash my game? I'm running the base gamemode with no addons. I tried that line with both a script and with lua_run. Am I doing something stupid I shouldn't be doing?[/QUOTE]
[URL="https://github.com/Facepunch/garrysmod-issues/issues/329"]See here[/URL]
Does anyone know how to change the skin of gibs spawned with Entity.GibBreakClient? They always come out with the default gib skin instead of the one that corresponds to the skin before it breaks.
-snip-
[QUOTE=michaelrule4;46944881]-snip-[/QUOTE]
What have you got against gays???
[QUOTE=StonedPenguin;46944356][URL="https://github.com/Facepunch/garrysmod-issues/issues/329"]See here[/URL][/QUOTE]
Oh, wow. That must be why I've never had this issue before. I've only ever used os.date on a Linux server, but this was on my Windows PC. Thanks! I appreciate it.
[QUOTE=zeaga;46945872]Oh, wow. That must be why I've never had this issue before. I've only ever used os.date on a Linux server, but this was on my Windows PC. Thanks! I appreciate it.[/QUOTE]
Notice that some flags with the same format char will be different on each OS. Cross reference between [url]http://linux.die.net/man/3/strftime[/url] and [url]http://msdn.microsoft.com/en-us/library/fe06s4ak.aspx[/url].
I ended up just solving the laser issue by adding an extra file separate from the nextbot, not ideal but oh well. It's fun working withe nextbots, I don't understand why more people don't use them. On a related note, is there any way to manage hitgroups and damage scaling with them? They don't trigger ScaleNPCDamage or ScalePlayerDamage, and those are the only functions that use hitgroups to my knowledge, so will I have to do some hacky thing like whenever the nextbot gets injured, check the position and measure the distance to the head bone or something? That seems sorta imprecise, but I might have to just go with it
[QUOTE=Ericson666;46946519]I ended up just solving the laser issue by adding an extra file separate from the nextbot, not ideal but oh well. It's fun working withe nextbots, I don't understand why more people don't use them. On a related note, is there any way to manage hitgroups and damage scaling with them? They don't trigger ScaleNPCDamage or ScalePlayerDamage, and those are the only functions that use hitgroups to my knowledge, so will I have to do some hacky thing like whenever the nextbot gets injured, check the position and measure the distance to the head bone or something? That seems sorta imprecise, but I might have to just go with it[/QUOTE]
[lua]
function ENT:OnLimbHit( hitgroup, dmginfo )
if not IsValid( self ) then return end
if hitgroup == HITGROUP_HEAD then
dmginfo:ScaleDamage( 2.75 )
elseif hitgroup == HITGROUP_CHEST then
dmginfo:ScaleDamage( 1.25 )
elseif hitgroup == HITGROUP_STOMACH then
dmginfo:ScaleDamage( 0.75 )
else
dmginfo:ScaleDamage( 0.50 )
end
end
[/lua]
If I remember correctly. I use these in my zombie nextbots. It looks like it's undocumented too.
Why don't files in '\garrysmod\addons\addon_test\lua\autorun\client' and '\garrysmod\lua\autorun\client' autorun when joining a server with sv_allowcslua 1?
Shouldn't servers that allow client lua allow the client to run said lua in the autorun folders?
[QUOTE=Pandaman09;46948807]Why don't files in '\garrysmod\addons\addon_test\lua\autorun\client' and '\garrysmod\lua\autorun\client' autorun when joining a server with sv_allowcslua 1?[/QUOTE]
Because Garry.
[QUOTE=Robotboy655;46948817]Because Garry.[/QUOTE]
Can it be 'fixed' now that Garry isn't around much :P
That would be a very bad feature in my opinion. Having all my shitty addons loaded when I join a server? Just make a loader, then lua_openscript_cl your loader, which loads other lua files you want to load. For example your addons.
I agree; it'd be terrible. I personally unsubscribed to all addons on my client so the server I join can decide and so it is only installed once, maybe twice.
The only issue I have because of that, if I want to add contents to my server collection the easiest way is by being subscribed to the addon..
[QUOTE=Pandaman09;46948807]Why don't files in '\garrysmod\addons\addon_test\lua\autorun\client' and '\garrysmod\lua\autorun\client' autorun when joining a server with sv_allowcslua 1?
Shouldn't servers that allow client lua allow the client to run said lua in the autorun folders?[/QUOTE]
Because the files are supposed to be ran before that convar is replicated, I think, so it couldn't check to see if the convar is enabled because that hasn't been established yet.
Sorry, you need to Log In to post a reply to this thread.