[QUOTE=Apozen;38562970]Unfortunately that does not work either :I Even when trying with different fonts.[/QUOTE]
Then are you sure self.DrawText is true? It seems to work fine without that if statement
Where would I add this DSP:
[QUOTE]for _,ply in pairs(player.GetAll()) do
ply:SetDSP( 30, false )
end[/QUOTE]
in rcs_base?
I've got a DTextEntry, and want it to work like a "Real Name" typer. Which way would be most effective way of doing it? Like, max characters around 20, one space required and no weird characters nor numbers? I bet Rabbish has a nice way or something.
You'd probably need to use regular expressions to check for letters only.
You ruined my day :(
I am porting GibSplat to Gmod 13 and I am working on gs_initialize.lua right now.
One of the errors was the datastream module not available anymore, so I went ahead and made one that acts like the original.
[code]//Description: send bones to decap to the client
function GSSendDecapBones( Ent, Bones )
//"Bones" is a table containing all the bones to send
local Sent = {} //table of sent values so we don't send them twice
net.Start( "GSRecieveBones" )
net.WriteEntity( Ent )
net.WriteLong( table.Count( Bones ) )
for _, bone in pairs( Bones ) do //Loop through them
if ( !table.HasValue( Sent, bone ) ) then
net.WriteLong( bone )
table.insert( Sent, bone )
end
end
net.Broadcast() // Send it to all players
end[/code]
I then found out net.WriteLong was removed. What should I use instead?
Here's the script itself:
[code]//Description: load all the default bonetrees from textfiles
GSBonetrees = {} //Create a global table for all the bonetrees (GS = GibSplat)
local Files = file.Find( "GibSplat/bone_trees/*.txt", "DATA" ) //Find all the text files in the bonetrees folder
for _, File in pairs( Files ) do
local Name = File:sub( 0, File:len() - 4 ) //Remove the extension for the name
GSBonetrees[ Name ] = {} //Create a new table inside the global one for the contents of this file
local Text = file.Read( "GibSplat/bone_trees/" .. File, "DATA" ) //Get the text from the current file
for __, Line in pairs( string.Explode( "\n", Text ) ) do //Loop through every line of the file (\n == new line)
if ( Line:Trim() == "" || Line:sub( 0, 2 ) == "//" ) then //If the line's a comment or if it's empty we don't want to use it
else //But if it isn't a comment it's valuable
local KeyValue = string.Explode( "=", Line ) //Explode it into a table containing two strings; the childbone and the paretnbone
local key, value = string.Trim( KeyValue[ 1 ] ), string.Trim( KeyValue[ 2 ] ) //Make two variables containing the childbone and the parentbone. Also remove possible spaces
GSBonetrees[ Name ][ key ] = value //Insert them into this files table
end
end
end
//Description: loads info on diferent materialtypes from files
GSBodyInfo = {}
local Files = file.Find( "GibSplat/body_data/*.txt", "DATA" )
for _, File in pairs( Files ) do
local Name = File:sub( 0, File:len() - 4 )
GSBodyInfo[ Name ] = {}
local Text = file.Read( "GibSplat/body_data/" .. File, "DATA" )
local INFO = string.Explode( "\n", Text )
GSBodyInfo[ Name ].Decal = INFO[ 1 ] || ""
GSBodyInfo[ Name ].Effect = INFO[ 2 ] || ""
end
//Description: send bones to decap to the client
function GSSendDecapBones( Ent, Bones )
//"Bones" is a table containing all the bones to send
local Sent = {} //table of sent values so we don't send them twice
net.Start( "GSRecieveBones" )
net.WriteEntity( Ent )
net.WriteLong( table.Count( Bones ) )
for _, bone in pairs( Bones ) do //Loop through them
if ( !table.HasValue( Sent, bone ) ) then
net.WriteLong( bone )
table.insert( Sent, bone )
end
end
net.Broadcast() // Send it to all players
end[/code]
net.WriteInt(integer, bits)
[QUOTE=Persious;38564018]You ruined my day :([/QUOTE]
local whiteliststring = "abcdefghijklmnopqrstuvwxyz" local whitelist = string.Explode( "", whiteliststring ) --Never tried exploding with "", I assume it works. local String = " This myNamE!" local String = string.TrimLeft( String ) local String = string.TrimRight( String ) --No leading/trailing spaces. local stringtbl = string.Explode( " ", String ) if stringtbl > 1 then return false end --No more than one space. for k, v in pairs( stringtbl ) do v = string.lower( v ) local length = string.len( v ) local firstletter = string.left( v, 1 ) local String = string.upper( firstletter ) .. string.right( v, length-1 ) end
I know... It can be done much better with patterns and those little % symbol thingies, but I'm not that smart! Figured this might help with something, probably not though haha
[editline]23rd November 2012[/editline]
[B]I'm done.[/B] :suicide:
[QUOTE=Persious;38563319]I've got a DTextEntry, and want it to work like a "Real Name" typer. Which way would be most effective way of doing it? Like, max characters around 20, one space required and no weird characters nor numbers? I bet Rabbish has a nice way or something.[/QUOTE]
[lua]local textentry = vgui.Create("DTextEntry")
function textentry:OnEnter()
local text = string.Trim(self:GetText())
if string.match(text, "^%a+ %a+$") then
-- do whatever
else
-- chastise this recalcitrant knave
end
end[/lua]
Although it's probably better, depending on your userbase, to automatically do the formatting yourself, collapse whitespace, etc
I'm trying to recode my old Fretta gamemode for 13. Does anyone have the old round system and mapvote from Fretta? All I need is rounds and mapvote, the rest is easy to re-code.
-snip-
Is there any way passing a variable to a timer function?
[lua]
local str = "lal"
timer.Create(ply:UniqueID().."_playtime",1,0,function(str) print(str) end)
// prints nil
[/lua]
[lua]
local str = "lal"
timer.Create(ply:UniqueID().."_playtime",1,0,print(str))
// bad argument #4 to Create, function expected, got no value
[/lua]
Why did the old way have to be changed? :/
[QUOTE=Luni;38565923][lua]local textentry = vgui.Create("DTextEntry")
function textentry:OnEnter()
local text = string.Trim(self:GetText())
if string.match(text, "^%a+ %a+$") then
-- do whatever
else
-- chastise this recalcitrant knave
end
end[/lua]
Although it's probably better, depending on your userbase, to automatically do the formatting yourself, collapse whitespace, etc[/QUOTE]
Formatting fucks up my brain. I want to learn it, but I just get confused. Currently I can type one space, but if I type a letter after, it disables the button. Is it possible letting it type more letters after a space?
I spent like an hour trying to figure this out but got nowhere.
I'm trying to make a gamemode where you have to move props with the cursor and I can't seem to figure out a way to do this.
All I really need is what I should use and how to use it. So I don't need someone to make the code for me.
I tried doing trace stuff clientside and moving the prop but it keeps telling me that the PhysObj false when I do IsValid(physobj) check. So I thought maybe I can only do it serverside but not really sure how since mouse clicks are clientside.
It's probably obvious what I have to do but I just can't figure it out.
[QUOTE=ollie;38566247]Is there any way passing a variable to a timer function?
[lua]
local str = "lal"
timer.Create(ply:UniqueID().."_playtime",1,0,function(str) print(str) end)
// prints nil
[/lua]
[lua]
local str = "lal"
timer.Create(ply:UniqueID().."_playtime",1,0,print(str))
// bad argument #4 to Create, function expected, got no value
[/lua]
Why did the old way have to be changed? :/[/QUOTE]
I [I]think[/I] you can send one argument through timer doing it the old way, I might be thinking of something else though.
timer.Create( id, 1, 0, MyFunction, argument)
This is clearly wrong, but I have no clue on how to make it work (I did look around for quite some time)
Saving - What I think it's wrong
[lua]
for i=1,40 do
local amount = ply.amount[ply.inv[i]]
if !amount then amount = 0 end
local id = ply.inv[i]
if !id then id = "nil" end
sql.Query( "INSERT INTO inventory ( `".. uniqueID .."`, `n`, `amount`, `id` ) VALUES ( '".. uniqueID .."', '"..i.."', '"..amount.."', '"..id.."' )" )
print(sql.Query( "SELECT id FROM inventory WHERE steamid = '".. uniqueID .."', n = '"..i.."'" )) -- returns false
print(sql.Query( "SELECT amount FROM inventory WHERE steamid = '".. uniqueID .."', n = '"..i.."'" )) -- returns false
end
[/lua]
Rest of it - Possibly right
[lua]
function sqlinventory( ply )
local uniqueID = ply:UniqueID()
for i = 1,40 do
ply.inv[i] = sql.QueryValue( "SELECT id FROM inventory WHERE steamid = '".. uniqueID .."', n = '"..i.."'" )
ply.amount[i] = sql.QueryValue( "SELECT amount FROM inventory WHERE steamid = '".. uniqueID .."', n = '"..i.."'" )
if ply.inv[i] == "false" or ply.inv[i] == "nil" or !ply.inv[i] then
print(i.." nop")
ply.inv[i] = nil
ply.amount[i] = nil
else
print(i.." ok")
print(ply.inv[i])
print(ply.amount[i])
end
end
end
function checktables()
for k, v in pairs (ents.FindByClass("func_breakable")) do v:Remove() end
if !sql.TableExists("inventory") then
sql.Query( "CREATE TABLE inventory ( uniqueid string, n int, amount int, id string )" )
if sql.TableExists("inventory") then
Msg("Table `inventory` successfuly created!\n")
else
Msg("Could create table `inventory`!\n")
end
end
end
hook.Add("InitPostEntity", "checktables", checktables )
function newsqlinv( SteamID, ply )
local uniqueID = ply:UniqueID()
for i=1,40 do
local amount = ply.amount[ply.inv[i]]
if !amount then amount = 0 end
local id = ply.inv[i]
if !id then id = "nil" end
sql.Query( "INSERT INTO inventory ( `uniqueID`, `n`, `amount`, `id` ) WHERE uniqueID = '".. uniqueID .."' VALUES ( '".. uniqueID .."', '"..i.."', '"..amount.."', '"..id.."' )" )
end
end
function sqlstart( ply )
local uniqueID = ply:UniqueID()
Result = sql.Query( "SELECT uniqueID, n, amount, id FROM inventory WHERE uniqueID = '".. uniqueID .."'" )
if (Result) then
print("works")
sqlinventory( ply )
else
print("need new")
newsqlinv( uniqueID, ply )
end
end
hook.Add("PlayerSpawn","spawnthatfag", function(ply)
timer.Simple( 0.2, function()
sqlstart( ply )
end)
end)
[/lua]
Hey guys, I just have REALLY quick question on how to fix this one timer.simple.
[ERROR] bad argument #1 to '?' (Entity expected, got no value)
1. unknown - [C]:-1
Timer Failed! [Simple][@lua/weapons/molotov_cocktail/shared.lua (line 77)]
Here is the code.
1|local Molotov = ents.Create( "sent_molotov" )
2| Molotov:SetOwner( Player )
3| Molotov:SetPos( Player:GetShootPos() )
4|-- Molotov:SetAngel( Player:GetAimVector() )
5| Molotov:Spawn()
6|
7| local mPhys = Molotov:GetPhysicsObject()
8| local Force = Player:GetAimVector() * 2555
9|
10| mPhys:ApplyForceCenter( Force )
11|
12| self.Weapon:EmitSound( "WeaponFrag.Throw" )
13| self.Weapon:SendWeaponAnim( ACT_VM_THROW )
[B]14|[/B] timer.Simple( 0.3, self.Weapon.SendWeaponAnim, self, ACT_VM_IDLE )
15| self.Weapon:SetNextPrimaryFire( CurTime() + 3 )
16| self.Weapon:SetNextSecondaryFire( CurTime() + 2 )
17|end
It be great if someone could help. This is the only error I get.
[QUOTE=Halokiller38;38568522]Hey guys, I just have REALLY quick question on how to fix this one timer.simple.
[ERROR] bad argument #1 to '?' (Entity expected, got no value)
1. unknown - [C]:-1
Timer Failed! [Simple][@lua/weapons/molotov_cocktail/shared.lua (line 77)]
Here is the code.
1|local Molotov = ents.Create( "sent_molotov" )
2| Molotov:SetOwner( Player )
3| Molotov:SetPos( Player:GetShootPos() )
4|-- Molotov:SetAngel( Player:GetAimVector() )
5| Molotov:Spawn()
6|
7| local mPhys = Molotov:GetPhysicsObject()
8| local Force = Player:GetAimVector() * 2555
9|
10| mPhys:ApplyForceCenter( Force )
11|
12| self.Weapon:EmitSound( "WeaponFrag.Throw" )
13| self.Weapon:SendWeaponAnim( ACT_VM_THROW )
[B]14|[/B] timer.Simple( 0.3, self.Weapon.SendWeaponAnim, self, ACT_VM_IDLE )
15| self.Weapon:SetNextPrimaryFire( CurTime() + 3 )
16| self.Weapon:SetNextSecondaryFire( CurTime() + 2 )
17|end
It be great if someone could help. This is the only error I get.[/QUOTE]
timer.Simple changed with the update. Here, give this a shot:
[lua]timer.Simple(0.3, function() self.Weapon:SendWeaponAnim(ACT_VM_IDLE) end) [/lua]
[QUOTE=me-name-bob;38568565]timer.Simple changed with the update. Here, give this a shot:
[lua]timer.Simple(0.3, function() self.Weapon:SendWeaponAnim(ACT_VM_IDLE) end) [/lua][/QUOTE]
Yup fixed, thanks.
I'm trying to color weapon view and world models that a player is holding, I tried using GetActiveWeapon():SetColor( myColor ) but it didn't do anything...
[lua]-- A function to also set the color of the viewmodel of the player.
-- color: The color :D
function Ply:SetWholeColor( color )
if !self:IsValid() or !self:Alive() then return end
self:SetColor( color )
if self:GetActiveWeapon() then self:GetActiveWeapon():SetColor( color ) end
if color.a < 255 then self:SetRenderMode( RENDERMODE_TRANSALPHA ) end
end[/lua]
snip fuck life
hey, quick question here:
[url]http://pastebin.com/GJYS3Yqq[/url]
This prints the health of the entity when it spawns, but it doesn't print the current health of the entity afterwards. Is it possible to make it print the health whenever it changes?
[QUOTE=CrashLemon;38568693]I'm trying to color weapon view and world models that a player is holding, I tried using GetActiveWeapon():SetColor( myColor ) but it didn't do anything...[/QUOTE]
You will need to set the color of the viewmodel entity itself, which you can get with ply:GetViewModel(). Not so sure about how to handle color on the world model if just setting the color won't work. Afaik there isn't a hook for pre/post draw on world models.
[QUOTE=cabbiethefirst;38569422]hey, quick question here:
[url]http://pastebin.com/GJYS3Yqq[/url]
This prints the health of the entity when it spawns, but it doesn't print the current health of the entity afterwards. Is it possible to make it print the health whenever it changes?[/QUOTE]
Health isn't networked. You will need to send that information to the client yourself.
[QUOTE=brickyross;38548196]I'm new to LUA, and the problem I'm having is not knowing where to put things (tutorials don't give you directories). I run a TTT server.. where do I put the code for connecting to a MySQL Database and querying it?[/QUOTE]
any serverside file. Go learn how to use MySQLoo v8 and use that to connect and query a database.
I've been trying to figure this out for hours, all I want is a message to say what weapon you were killed by (in trouble in terrorist town)... It's like getting a weapon name is impossible..
[QUOTE=brickyross;38575192]I've been trying to figure this out for hours, all I want is a message to say what weapon you were killed by (in trouble in terrorist town)... It's like getting a weapon name is impossible..[/QUOTE]
[lua]
local meta = FindMetaTable("Player")
if not meta then return end
function meta:GetWeaponName() -- Not sure if this is already taken
if self:GetActiveWeapon() and self:GetActiveWeapon():IsValid() then
local name = ""
if self:GetActiveWeapon().PrintName then
name = self:GetActiveWeapon().PrintName
else
if self:GetActiveWeapon().GetClass and self:GetActiveWeapon():GetClass() then
-- This will need some modifying, depending on what type of class name you have
name = string.gsub(self:GetActiveWeapon():GetClass(), "weapon_", "")
name = string.gsub(name, "_", " ")
end
end
return name
end
end
[/lua]
[QUOTE=CrashLemon;38568693]I'm trying to color weapon view and world models that a player is holding, I tried using GetActiveWeapon():SetColor( myColor ) but it didn't do anything...
[lua]-- A function to also set the color of the viewmodel of the player.
-- color: The color :D
function Ply:SetWholeColor( color )
if !self:IsValid() or !self:Alive() then return end
self:SetColor( color )
if self:GetActiveWeapon() then self:GetActiveWeapon():SetColor( color ) end
if color.a < 255 then self:SetRenderMode( RENDERMODE_TRANSALPHA ) end
end[/lua][/QUOTE]
As far as I remember the viewmodel is a clientside entity.
In other words: Call the function on the client too.
How do I make an entity [I]incompatible[/I] with the duplicator? As in, completely ignored when you make a save or use the duplicator on it? Even though duplicator.IsAllowed() is returning nil with the entity, the game still insists on letting you use the default saving on it, which just leaves half-working versions of the entity behind.
EDIT: Never mind, managed to figure it out:
[lua]duplicator.RegisterEntityClass( "entityname", function( ply, data )
//don't do anything!
end, "Data" )[/lua]
I'm running a custom chat box for my server and whenever you use commands such as "ulx tsay" (sends messages through the chat box) it doesn't send it. It also won't send other various lua scripts that send messages through your chat. Is there any way to fix this? Thanks in advance.
sounds like the custom chatbox doesn't support a variation of argument types that can be passed to chat.AddText
Sorry, you need to Log In to post a reply to this thread.