@ROFLBURGER
You need to clamp the eye angles that you're setting to stop that error.
I don't recall what the maximum values are though.
Does anyone know how to change a bot's playermodel? SetModel doesn't work.
[QUOTE=Jeezy;46036583]@ROFLBURGER
You need to clamp the eye angles that you're setting to stop that error.
I don't recall what the maximum values are though.[/QUOTE]
I just normalized the angle. Works fine.
[editline]20th September 2014[/editline]
Oh I had to put the setmodel on a timer to work, it seems.
I am trying to create my own fuel system for all cars. Does anyone know what hook I would need to mess with to do this, or if I need to create a custom entity with the variables on it?
I was thinking I could somehow set a fuel variable on the vehicle spawn and then if it ever runs to 0 set its velocity to (0,0,0).
[QUOTE=bran92don;46037161]
I was thinking I could somehow set a fuel variable on the vehicle spawn and then if it ever runs to 0 set its velocity to (0,0,0).[/QUOTE]
But wut if they get out and push it
[editline]21st September 2014[/editline]
DON'T DO THAT, fire the "HandBrakeOn" or "TurnOff" input on a loop instead:
[url]https://developer.valvesoftware.com/wiki/Prop_vehicle_jeep[/url]
[QUOTE=BFG9000;46038060]But wut if they get out and push it
[editline]21st September 2014[/editline]
DON'T DO THAT, fire the "HandBrakeOn" or "TurnOff" input on a loop instead:
[url]https://developer.valvesoftware.com/wiki/Prop_vehicle_jeep[/url][/QUOTE]
"HandBrakeOn" is a toggle, I don't think that needs to be looped (correct me if I am wrong), but "TurnOff" will need to be looped to prevent people from turning cars on.
Would it be possible to hide certain models from Player Selection menus that use AllValidModels() but have them select-able elsewhere like Pointshop?
Is it possible to make only ONE Texture ID on a Model invisible?
I want to take a v_(X) weapon model and blank out the hands.
[QUOTE=WalkingZombie;46042541]Is it possible to make only ONE Texture ID on a Model invisible?
I want to take a v_(X) weapon model and blank out the hands.[/QUOTE]
You can replace certain textures during the draw call of the weapon ( reset it after the draw to prevent other instances of the same weapon / texture from also being replaced ) to one that is invisible...
What is the exact purpose; what are you trying to do specifically? There may be a better solution... What do you mean by take a v_ weapon model and blank out the hands? You could move the model off the screen, you can unequip a weapon, etc...
I'm trying to get access to CBasePlayer/Entity through a lua module.
What is the userdata.data member pointing to? I've tried CBaseEntity and CBasePlayer and CHandle/EHANDLE.
[code]
UserData *ud = (UserData*)LUA->GetUserdata( 1 );
Msg( "ud: type %i : data 0x%x\n", ud->type, ud->data );
CBaseEntity *ent = (CBaseEntity*)ud->data;
[/code]
The type is correct GarrysMod::Lua::Type::ENTITY, and the data pointer points to something weird. It's definitly not CBaseEntity/Player.
tl;dr Anyone know how to access the player object in lua modules?
EDIT: Figured it out. It's a CBaseHandle (Which should work with EHANDLE?).
[code]
int testLuaFunc( lua_State *state ){
UserData *ud = (UserData*)LUA->GetUserdata( 1 );
Msg( "ud: type %i : data 0x%x\n", ud->type, ud->data );
CBaseHandle *hent = (CBaseHandle*)ud->data;
if( !hent ){
Warning( "Failed to find ent\n" );
return 0;
}
edict_t *ent = engine->PEntityOfEntIndex( hent->GetEntryIndex() );
Msg( "%s\n", ent->GetUnknown()->GetBaseEntity()->GetModelName().ToCStr() );
return 0;
}
[/code]
Hello all,
I recently started coding an addon and I need to save some player data on the server. I will use SQL, which I admit I never used yet.
I've read that it's better to use ply:SteamID64() instead of ply:UniqueID() (because the latter is slower?) for the indexes. I'm just wondering (because I never saw it being used) : what's wrong with using ply:SteamID() instead?
I find it would be easier to read a database with SteamID as indexes, so I can easily find which player it is, while a SteamID64 or UniqueID is a bunch of numbers that no one can ever remember.
Your advice ?
[QUOTE=Giraffen93;46017464][IMG]http://i.imgur.com/j4i9Ndl.png[/IMG]
probably really simple, but how do i remove that button? tried using list.set on the main table but to no avail
google doesn't help[/QUOTE]
Did you figure it out yet?
If not, you should use the OnContextMenuOpen hook, look through all of g_ContextMenu's childs, look if it's a DIconLayout, then look through all of its childs then set the one that has its label (also a children of the icon) set to "Player Model" to hide or to remove. Probably a little hacky and unpractical but that's all I can think of. I have such code but I'm on phone, sorry.
Good luck :)!!
EDIT:
Here's how I do it:
[lua]
function GM:_RemoveContextMenuPanels()
if g_ContextMenu then
for _, panel in pairs(g_ContextMenu:GetChildren()) do
if panel.ClassName == "DIconLayout" then
for _, icon in pairs(panel:GetChildren()) do
for _, panel in pairs(icon:GetChildren()) do
if panel.ClassName == "DLabel" and panel:GetText() == "Player Model" then
icon:Remove()
break
end
end
end
elseif panel.ClassName == "DMenuBar" then
for _, panel in pairs(panel:GetChildren()) do
if panel:GetText() == "Drawing" then
panel:SetVisible(LocalPlayer():IsAdmin())
elseif panel:GetText() == "NPCs" then
panel:SetVisible(false)
end
end
end
end
end
end
[/lua]
[QUOTE=DEFCON1;46043084]Hello all,
I recently started coding an addon and I need to save some player data on the server. I will use SQL, which I admit I never used yet.
I've read that it's better to use ply:SteamID64() instead of ply:UniqueID() (because the latter is slower?) for the indexes. I'm just wondering (because I never saw it being used) : what's wrong with using ply:SteamID() instead?
I find it would be easier to read a database with SteamID as indexes, so I can easily find which player it is, while a SteamID64 or UniqueID is a bunch of numbers that no one can ever remember.
Your advice ?[/QUOTE]
I'm personally using SteamID64() these days, It returns the community id number, as opposed to the old SteamID() which returns their steam ID (something like STEAM:1:0:12345678).
IIRC UniqueID() is the players entity number, or unique identifier on the server atleast. But I could be wrong there.
Use wiki.garrysmod.com to get the exact information on all the functions. But I'd recommend using SteamID64()
[QUOTE=DEFCON1;46043084]Hello all,
I recently started coding an addon and I need to save some player data on the server. I will use SQL, which I admit I never used yet.
I've read that it's better to use ply:SteamID64() instead of ply:UniqueID() (because the latter is slower?) for the indexes. I'm just wondering (because I never saw it being used) : what's wrong with using ply:SteamID() instead?
I find it would be easier to read a database with SteamID as indexes, so I can easily find which player it is, while a SteamID64 or UniqueID is a bunch of numbers that no one can ever remember.
Your advice ?[/QUOTE]
ply:UniqueID() has to calculate the crc32 first, which I guess takes more resource than just using their Steam64, and since it is a hash, there is a tiny chance of collisions. ( no idea how small this chance is, anyone ever worked it out? )
SteamID cannot be stored as an int which I think stops it from being used as an index?
this leaves Steam64, since it only contains numbers and doesn't need to run through a hash.
I use all 3... Steam32, 64 and 3 ( U: )... If you want an easy way to calculate all of them based on ANY input: [url]https://bitbucket.org/Acecool/acecooldev_base/src/7158a106ef63b0eb56067532bd64de0f32db8f51/gamemode/shared/core/util_translatesteamid.lua?at=master[/url]
It'll take 32, 64 or 3 as input, and it'll return all 3...
local _steam32, _steam64, _steam3 = util.TranslateSteamID( input );
I typically just use 32; but I also store 64 and the newest variant into an accounts table. The account id is then linked throughout the database to other things such as bans or other infractions, etc; the account links to characters and characters link to stored items, vehicles and all of the other stuff.
UniqueID as said is slower because it calculates it each time: util.CRC( "gm_" .. _steam32 .. "_gm" ); not to mention that it is one way.... If you want to convert data stored by Get/SetPData in playerpdata sqlite sv.db, to MySQL, you'll need to check for UniqueID first and populate data as users connect... It is a annoying because you won't have all of the information so you'll need to keep certain clauses just to remain backwards compatible until all rows are populated or you scrap the data.. [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/database/converting_sv_db_to_mysql.lua.html[/url]
Edit: Don't store Steam64 or UniqueID as INT in MySQL DB. You'll eventually have users with the same id at the high-side of the value ( one of the flaws of a system I worked on and helped fix; was an annoying bug to find ).
[QUOTE=Acecool;46042823]You can replace certain textures during the draw call of the weapon ( reset it after the draw to prevent other instances of the same weapon / texture from also being replaced ) to one that is invisible...
What is the exact purpose; what are you trying to do specifically? There may be a better solution... What do you mean by take a v_ weapon model and blank out the hands? You could move the model off the screen, you can unequip a weapon, etc...[/QUOTE]
The purpose? The reason? To hide the hands in the v_(x) model. I don't want to make a custom c_ model, too lazy, but I want it to work the same way as one.
[editline]21st September 2014[/editline]
Essentially... I want to change my v_whateverthefuck to a c_whateverthefuck without needing to make a new model, using code.
[QUOTE=Blasteh;46043236]ply:UniqueID() has to calculate the crc32 first, which I guess takes more resource than just using their Steam64, and since it is a hash, there is a tiny chance of collisions. ( no idea how small this chance is, anyone ever worked it out? )
SteamID cannot be stored as an int which I think stops it from being used as an index?
this leaves Steam64, since it only contains numbers and doesn't need to run through a hash.[/QUOTE]
CRC32 is ridiculously fast. The performance impact will be next to nothing.
The chance of colission is incredibly small. (Since the Int32 range is ~20-40 times larger than the amount of steam accounts) but it's still possible.
SteamIDs can be stored as VARCHAR which can be used as an index. VARCHAR indexes the size of SteamIDs are also not significantly slower than int indexes. (unless you have > 100k unique players)
[QUOTE=Acecool;46043287]
Edit: Don't store Steam64 or UniqueID as INT in MySQL DB. You'll eventually have users with the same id at the high-side of the value ( one of the flaws of a system I worked on and helped fix; was an annoying bug to find ).[/QUOTE]
You can store the SteamID64 as an unsigned BIGINT without any problems.
Conclusion: While UniqueID isn't terrible, SteamID64 is safer. It's also smaller (in bytes) than a SteamID32(as string), so SteamID64 is clearly the best option.
I'm trying to recreate the flash bang in CS:S but I'm stuck on one part. I'm trying to make it so that it only triggers if one can see the flashbang, and I'm doing so with checking the player's cone to see if the flashbang entity is in view.
Though the problem is that it goes through walls. Any sugestions? I'm thinking of getting the eye trace of the player and if the distance of eye trace hitpos is less than distance of the flashbang then it wouldn't do anything, but that doesn't mean one can't see it.
[lua]function ENT:Detonate(self,pos)
if not self:IsValid() then return end
local effectdata = EffectData()
effectdata:SetStart( pos + Vector(0,0,100)) // not sure if we need a start and origin (endpoint) for this effect, but whatever
effectdata:SetOrigin( pos)
effectdata:SetScale( 100 )
effectdata:SetRadius( 5000 )
util.Effect( "HelicopterMegaBomb", effectdata )
self:EmitSound("weapons/flashbang/flashbang_explode2.wav",100,100)
if table.Count(ents.FindInSphere(self:GetPos(),1000)) > 0 then
for k,v in pairs(ents.FindInSphere(self:GetPos(),1000)) do
if v:GetClass() == "player" then
local distancecount = 10 - self:GetPos():Distance(v:GetPos())/100
if distancecount > 0 then
v:TakeDamage(distancecount,self.Owner,self)
for n,f in pairs(ents.FindInCone(v:GetShootPos(), v:GetAimVector(),1000,90)) do
if f == self.Entity then
if distancecount > 1 then
v:SetDSP( 37, false )
end
v:ConCommand("pp_motionblur 1")
v:ConCommand("pp_motionblur_drawalpha 0.99")
v:ConCommand("pp_motionblur_addalpha 0.2")
v:ConCommand("pp_texturize effects/flashbang_white")
timer.Create(v:EntIndex().."flashblind1",distancecount*0.25, 1, function()
v:ConCommand("pp_texturize \"\"")
end)
timer.Create(v:EntIndex().."flashblind2",distancecount, 1, function()
v:ConCommand("pp_motionblur 0")
end)
end
end
end
end
end
end
self:Remove()
end[/lua]
You could try a trace between [URL="http://wiki.garrysmod.com/page/Entity/EyePos"]ply:EyePos()[/URL] and the flashbang. If it doesn't hit anything then it's atleast potentially visible.
The next thing you can do is check if you are looking in the direction of the flashbang.
[LUA]
local direction = flashbang:GetPos()-ply:EyePos()
--Do some trace stuff
local dotProduct = ply:GetAimVector():Dot(direction:GetNormal())
local angle = math.acos(dotProduct)
if(angle <= math.pi/2) then
-- visible
end
[/LUA]
How can I make this work?
[LUA]Player [1][Warrior]:SetLevel( 10 )[/LUA]
I keep getting this error when trying to use RunString
[LUA][ERROR] RunString:1: attempt to index global 'Player' (a function value)[/LUA]
[QUOTE=DarthTealc;46045665]Is it possible to detect (clientside) when someone runs "stopsound" ?
Currently stopsound doesn't kill sounds that are called by sound.PlayURL() so I want to hook into stopsound and use :Stop() on the sound when the player calls it. Can't figure out how to hook into stopsound though, if it is even possible.[/QUOTE]
You "may" if the function is accessible in the concommands table. You'd need to create a copy of the reference pointing to the original function and override it where the override does your hook.Call and then the function calls the original reference as a function.
Other than modifying it like that ( ie, if it is hard-coded, you wouldn't be able to capture it without using a module, or hackery if I recall correctly... I can look into this tomorrow sometime, but hopefully this is enough for you to look at unless someone else answers or this works. )
[editline]22nd September 2014[/editline]
[QUOTE=M60warrior;46046112]How can I make this work?
[LUA]Player [1][Warrior]:SetLevel( 10 )[/LUA]
I keep getting this error when trying to use RunString
[LUA][ERROR] RunString:1: attempt to index global 'Player' (a function value)[/LUA][/QUOTE]
Call it so the first "variable" is a player object... Example, with you in the server: Entity( 1 ):SetLevel( 10 ); would work if SetLevel exists in the Player Metatable.
[QUOTE=Acecool;46046137]
Call it so the first "variable" is a player object... Example, with you in the server: Entity( 1 ):SetLevel( 10 ); would work if SetLevel exists in the Player Metatable.[/QUOTE]
I tried [LUA]local _p = Entity( _ply:EntIndex() );[/LUA] and it still returns the same error.
[LUA][ERROR] RunString:1: attempt to index global 'Player' (a function value)[/LUA]
The RunString:
[LUA]RunString( tostring( _p ) .. ":" .. _code )[/LUA]
[QUOTE=M60warrior;46046190]I tried [LUA]local _p = Entity( _ply:EntIndex() );[/LUA] and it still returns the same error.
[/QUOTE]
What are you even trying to do?
your code above is the same as
[lua]
local _p = _ply
[/lua]
-snip- woops, nevermind. >_>
[QUOTE=Blasteh;46046325]What are you even trying to do?
your code above is the same as
[lua]
local _p = _ply
[/lua][/QUOTE]
I am trying to make a command to run lua on the player calling the command.
Here is the code I am using:
[LUA]
function runLuaSelf( ply, id, code )
if ( !ply:IsSuperAdmin() ) then return; end
local pStr = tostring( ply );
local sep = ":";
local codeStr = table.concat( code );
MsgN( ply );
MsgN(pStr..sep..codeStr);
RunString(pStr..sep..codeStr);
return;
end
concommand.Add( "slua", runLuaSelf )
[/LUA]
If I run the command it will print "Player [1][Warrior]:setLevel(10)"
Then the error shows.
[QUOTE=M60warrior;46050328]I am trying to make a command to run lua on the player calling the command.
Here is the code I am using:
[LUA]
function runLuaSelf( ply, id, code )
if ( !ply:IsSuperAdmin() ) then return; end
local pStr = tostring( ply );
local sep = ":";
local codeStr = table.concat( code );
MsgN( ply );
MsgN(pStr..sep..codeStr);
RunString(pStr..sep..codeStr);
return;
end
concommand.Add( "slua", runLuaSelf )
[/LUA]
If I run the command it will print "Player [1][Warrior]:setLevel(10)"
Then the error shows.[/QUOTE]
I have no idea why you want to do things this way, but here:
[lua]
function runLuaSelf( ply, id, code, fullCMD )
if ( !ply:IsSuperAdmin() ) then return; end
local plyID = tostring(ply:EntIndex())
RunString("Entity("..plyID.."):"..fullCMD);
end
concommand.Add( "slua", runLuaSelf )
[/lua]
:s
[QUOTE=Blasteh;46051036]-stuff-[/QUOTE]
Thank you very much!
How would I completely remove a weapon by classname from a player's inventory?
[QUOTE=zeaga;46051246]How would I completely remove a weapon by classname from a player's inventory?[/QUOTE]
You'd use this function, unless you're speaking of some sort of inventory system that an addon contains.
[url]http://wiki.garrysmod.com/page/Player/StripWeapon[/url]
[QUOTE=Jeezy;46051334]You'd use this function, unless you're speaking of some sort of inventory system that an addon contains.[/QUOTE]
Nope, that's perfect! Thanks!
How bad is it to use a user message inside of a think hook to constantly keep the players hud up to date?
I was trying to avoid doing this because to me it seems like its gonna ddos someones screen to no tomorrow.
If you wondering what I am doing I am trying to send the blood amount of the player to their screen. The thing is the players blood amount is constantly building up over time if it is below 100.
Sorry, you need to Log In to post a reply to this thread.