[QUOTE=G4MB!T;52835971]Use hooks.[/QUOTE]
pls not hooks in gamemode
[IMG]https://i.imgur.com/SoYldvX.png[/IMG]
[CODE] local visibleMaxPlayers = tonumber( ) )
if ( #player.GetAll( ) >= visibleMaxPlayers and !NOOB_ADMIN_VIPTABLE[steamID] ) then
return false, "You were unable to join the server, it's full."
else
return true
end
end
end )[/CODE]
I get that tonumber() needs a value and the obvious unexpected symbol, but my question is what do i put inbetween the brackets.(I dont own the code) Not really sure what the intentions were for this line, any help is appreciated.
after I delete the unexpected symbol:
[IMG]https://i.imgur.com/bAbyHTV.png[/IMG]
Full code:
[CODE]NOOB_ADMIN_BANTABLE = NOOB_ADMIN_BANTABLE or { }
NOOB_ADMIN_VIPTABLE = NOOB_ADMIN_VIPTABLE or { }
hook.Add( "NOOBRP_MySQL_Connected", "NoobAdminBansSQL", function()
mySQLControl:CreateTable( "noobadmin_ranks", { "steamid varchar(255) UNIQUE KEY", "rank varchar(255)" } );
mySQLControl:CreateTable( "noobadmin_bans", { "steamid varchar(255)", "time int", "reason varchar(255)", "adminname varchar(255)", "bantime int" } );
mySQLControl:TableExists( "noobadmin_bans", function( tblCount )
if ( #tblCount > 0 ) then
mySQLControl:Query( "SELECT * FROM noobadmin_bans WHERE time > " .. os.time( ) .. ";", function( data )
if ( #data > 0 ) then
for index, dat in pairs ( data ) do
NOOB_ADMIN_BANTABLE[dat.steamid] = { time = tonumber( dat.time ), reason = dat.reason, adminName = dat.adminname }
end
MsgC( Color( 150, 150, 245 ), "[NOOBADMIN] ", Color( 245, 150, 150 ), "has loaded ", Color( 255, 255, 255 ), #data, Color( 245, 150, 150 ), " bans.\n" )
end
mySQLControl:Query( "SELECT * FROM noobadmin_bans WHERE time = 0;", function( innerData )
if ( #innerData > 0 ) then
for index, dat in pairs ( innerData ) do
NOOB_ADMIN_BANTABLE[dat.steamid] = { time = 0, reason = dat.reason, adminName = dat.adminname }
end
MsgC( Color( 150, 150, 245 ), "[NOOBADMIN] ", Color( 245, 150, 150 ), "has loaded ", Color( 255, 255, 255 ), #innerData, Color( 245, 150, 150 ), " permanent bans.\n" )
end
end )
end )
end
end )
mySQLControl:Query( "SELECT steamid FROM noobadmin_ranks WHERE rank = 'vip' OR rank = 'admin' OR rank = 'superadmin';", function( data )
if ( #data > 0 ) then
for index, dat in pairs ( data ) do
NOOB_ADMIN_VIPTABLE[dat.steamid] = true
end
end
end )
end );
/*timer.Create( "Noob_CheckForBans", 1, 0, function()
mySQLControl:Query( "SELECT * FROM noobadmin_bans;", function( data )
for k, v in pairs( data ) do
if ( v.time <= 0 ) then continue; end -- game genies don't get a #chance at it nigga
if ( v.time < os.time() ) then
mySQLControl:Query( "DELETE FROM noobadmin_bans WHERE steamid = '"..v.steamid.."';", function( data )
print( "unbanned "..v.steamid );
end );
end
end
end );
end );*/
/*hook.Add( "PlayerAuthed", "NoobCheckForBan", function( pl, steamid, uniqueid )
mySQLControl:Query( "SELECT * FROM noobadmin_bans WHERE steamid = ".."'"..steamid.."';", function( data )
if ( #data > 0 ) then
local time_exp = ( data[ 1 ].time > 0 and ( ( data[ 1 ].time - os.time() ) / 60 ) ) or "never";
pl:NoobKick( "You've been banned by: "..data[ 1 ].adminname, "Reason: "..data[ 1 ].reason, "Ban expires in: "..math.floor( time_exp ).." minute(s)" );
end
end );
end );*/
hook.Add( "CheckPassword", "NOOBRP_RejectBannedPlayers_CheckPassword", function( steam64, ipAddress, svPassword, clPassword, name )
if ( svPassword and svPassword ~= "" and clPassword ~= svPassword ) then
return false, "You entered the incorrect password."
end
local steamID = util.SteamIDFrom64( steam64 )
if ( NOOB_ADMIN_BANTABLE[steamID] ) then
local banInfo = NOOB_ADMIN_BANTABLE[steamID]
if ( banInfo.time == 0 ) then
return false, "You're permanently banned from this server.\nReason: " .. banInfo.reason .. "\nAdmin: " .. banInfo.adminName
end
if ( banInfo.time > os.time( ) ) then
// Player is still banned.
local timeLeft = string.NiceTime( banInfo.time - os.time( ) )
return false, "You're banned from this server.\nReason: " .. banInfo.reason .. "\nTime Left: " .. timeLeft .. "\nAdmin: " .. banInfo.adminName
else
// Player is no longer banned.
NOOB_ADMIN_BANTABLE[steamID] = nil
return true
end
else
local visibleMaxPlayers = tonumber( ) )
if ( #player.GetAll( ) >= visibleMaxPlayers and !NOOB_ADMIN_VIPTABLE[steamID] ) then
return false, "You were unable to join the server, it's full."
else
return true
end
end
end )
hook.Add( "PlayerInitialSpawn", "NoobCheckForRank", function( pl )
mySQLControl:Query( "SELECT * FROM noobadmin_ranks WHERE steamid = "..pl:EncloseSteamID()..";", function( data )
if ( #data > 0 ) then
pl:SetRank( data[ 1 ].rank, false );
end
end );
end );
[/CODE]
Line is probably meant to be:
[code]local visibleMaxPlayers = GetConVarNumber( "sv_maxvisibleplayers" )[/code]
Anyone know the best way to check if 2 render targets are the same? Trying to make a RT refresh only if the source was changed...
[QUOTE=Ilyaaa;52842326]Anyone know the best way to check if 2 render targets are the same? Trying to make a RT refresh only if the source was changed...[/QUOTE]
You could write them both as jpgs and manually compare the pixel data, but that would be incredibly slow. I don't think there's a way to access the pixel buffer from the Lua state, nor a way to compare textures.
Any ideas on getting a networked table? I'm trying to setup a medal system, and when the player spawns it creates an empty table which then I wanted to fill with some other tables that had details about the medals (textures, sounds, etc..), problem is that while the table is set on the Server no problem, I can't quite get it to set on the CLIENT using the net.WriteTable function. Even more annoying that sometimes the player entity returns nil in the client but not in the server, screwing with me even more. Any suggestions?
[QUOTE=buu342;52842623]Any ideas on getting a networked table? I'm trying to setup a medal system, and when the player spawns it creates an empty table which then I wanted to fill with some other tables that had details about the medals (textures, sounds, etc..), problem is that while the table is set on the Server no problem, I can't quite get it to set on the CLIENT using the net.WriteTable function. Even more annoying that sometimes the player entity returns nil in the client but not in the server, screwing with me even more. Any suggestions?[/QUOTE]
Could you post code? Also, you should avoid using WriteTable if possible.
[QUOTE=code_gs;52841125]Line is probably meant to be:
[code]local visibleMaxPlayers = GetConVarNumber( "sv_maxvisibleplayers" )[/code][/QUOTE]
Makes the server seem full, anyway to make it so it doesnt?
Make the convar number higher.
[QUOTE=code_gs;52842961]Make the convar number higher.[/QUOTE]
Hey what are some other places you can link your workshop for fastdl?
The script I currently have ( [url]https://github.com/SurelyExploding/noobonicplague[/url] ) seems to have their workshop enabled for fastdl, but I can't seem to find where they would possibly put it.
Server console says there is no workshop link but when entering the server and downloading the files it displays 'via workshop'.
[IMG]https://i.imgur.com/RqH1Kg2.png[/IMG]
[QUOTE=lubatron;52843368]Hey what are some other places you can link your workshop for fastdl?
The script I currently have ( [url]https://github.com/SurelyExploding/noobonicplague[/url] ) seems to have their workshop enabled for fastdl, but I can't seem to find where they would possibly put it.
Server console says there is no workshop link but when entering the server and downloading the files it displays 'via workshop'.
[IMG]https://i.imgur.com/RqH1Kg2.png[/IMG][/QUOTE]
[url]https://github.com/SurelyExploding/noobonicplague/blob/bb851fbc429f82d10e6dd96c18595ac336e67592/gamemode/modules/noob/sv_resources.lua#L110[/url]
The error refers to your host workshop collection, which is what the server downloads. AddWorkshop is what the client downloads.
[QUOTE=code_gs;52842709]Could you post code? Also, you should avoid using WriteTable if possible.[/QUOTE]
Here it is.
Essentially I want to have a single function which draws the medal on the screen, and I was going to make a table that kept the table with the settings it should draw (the name, texture, colors, etc...). This would essentially create a pile of medals to display, and I would remove the top-most medal every 3 seconds and shift the rest of the medals up, to show the next medal that the player earned. Though while I am able to do this serversided with absolutely no problems, this completely fails clientside. As the player always returns as nil. I've also tried WriteEntity to write the player but with no luck. If there was just a SetNWTable function that would probably solve my problems, but alas, networking is the way to go. Annoying since it makes my code longer every time I want to add a new medal.
[lua]
local MedalFirstFrag = {
"First frag", // Text
"vgui/medals/MedalFirstFrag.png", // Texture
"gameplay/medals/MedalFirstFrag.mp3", // Sound
255, // R
105, // G
0 // B
}
hook.Add( "HUDPaint", "DrawMedals", function()
//local alpha = 255//((LocalPlayer():GetNWFloat("MedalFirstFrag")-CurTime())/MedalShowTime)*255
//surface.SetDrawColor( Color(255,255,255,alpha) )
//surface.SetMaterial( Material( "vgui/medals/MedalFirstFrag.png" ) )
//draw.SimpleTextOutlined( "First frag","Chilly", ScrW()/2, 24, Color(255,105,0,alpha), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 2, Color(0,0,0,alpha))
//surface.DrawTexturedRect( ScrW()/2-64, 32, 128, 128 )
end)
hook.Add( "PlayerDeath", "PlayerDeathMedals", function(victim, inflictor, attacker)
if attacker != victim then
table.insert( attacker.MedalTable, table.Count(attacker.MedalTable), MedalFirstFrag )
net.Start("MedalTable")
net.WriteTable(MedalFirstFrag)
net.Send(attacker)
end
end)
hook.Add( "PlayerSpawn", "PlayerSpawnMedals", function(ply)
if ply.MedalTable == nil then
ply.MedalTable = {}
net.Start("MedalTableCreateClient")
net.Send(ply)
end
end)
if SERVER then
util.AddNetworkString( "MedalTable" )
util.AddNetworkString( "MedalTableCreateClient" )
end
net.Receive( "MedalTable", function( len, pl )
local Medal = net.ReadTable()
table.insert( pl.MedalTable, table.Count(pl.MedalTable), Medal )
end)
net.Receive( "MedalTableCreateClient", function( len, pl )
print(pl) // Over here for some reason the player returns as nil.
pl.MedalTable = {} // So this line fails...
end)
[/lua]
Firstly, you should really separate things into their proper realms - you're uselessly adding net callbacks serverside when they should be clientside only. Same situation with the hooks. Secondly, networking server->client doesn't provide a player variable in the net callback - you'll have to use LocalPlayer. In this situation, however, you can just use an OnEntityCreated hook to create the medal table on the player. Lastly, since you know the table structure in advance, you can just network each part individually.
Fixed code (I also got a bit carried away and added a small system to register and network medals efficiently):
[code]local tMedalTypes = {}
local function RegisterMedalType(sName, flShowTime, sText, sTexture, sSound, col)
local bUniqueMedal = tMedalTypes[sName] == nil
if (SERVER) then
tMedalTypes[sName] = true
if (bUniqueMedal) then
util.AddNetworkString("MedalTable-" .. sName)
end
else
tMedalTypes[sName] = {flShowTime, sText, Material(sTexture), sSound, col}
-- Prevent two network callbacks being registered
if (bUniqueMedal) then
net.Receive("MedalTable-" .. sName, function()
local pPlayer = LocalPlayer()
if (pPlayer:IsValid()) then
local tMedals = pPlayer.MedalTable
local iLen = tMedals[0] + 1 -- Increment the table length
tMedals[0] = iLen + 1
local tMedal = tMedalTypes[sName]
tMedals[iLen] = {RealTime() + tMedal[1], tMedal}
surface.PlaySound(tMedal[4])
end
end
end
end
end
RegisterMedalType("first", 5, "First frag", "vgui/medals/MedalFirstFrag.png", "gameplay/medals/MedalFirstFrag.mp3", Color(255, 105, 0))
if (SERVER) then
local function NetworkMedal(sName, pPlayer)
net.Start("MedalTable-" .. sName)
net.Send(pPlayer)
end
hook.Add("PlayerDeath", "PlayerMedals", function(pVictim, _, pAttacker)
-- Attacker is a player and they didn't kill themselves
if (pAttacker:IsPlayer() and pVictim ~= pAttacker) then
if (pAttacker:Frags() == 1) then
NetworkMedal("first", pAttacker)
else
-- Add more conditions here..
end
end
end)
else
hook.Add("OnEntityCreated", "PlayerMedals", function(pEntity)
if (pEntity:IsPlayer()) then
pEntity.MedalTable = {}
end
end)
hook.Add("HUDPaint", "PlayerMedals", function()
local pPlayer = LocalPlayer()
if (pPlayer:IsValid()) then
local tMedals = pPlayer.MedalTable
local iLen = tMedals[0]
if (iLen == 0) then
return
end
local flTime = RealTime()
local i = 0
repeat
i = i + 1
local tMedal = tMedals[i]
-- Remove medals if they exceed the show time
while (flTime > tMedal[1]) do
table.remove(tMedals, i) -- Shift everything down in order
iLen = iLen - 1
-- Out of medals to draw
if (i > iLen) then
goto MedalsDone
end
tMedal = tMedals[i]
end
surface.SetDrawColor(tMedal[5])
surface.SetMaterial(tMedal[3])
draw.SimpleTextOutlined(tMedal[2], "Chilly", --[[Draw stuff here]])
until (i == iLen)
::MedalsDone::
tMedals[0] = iLen -- Update the length
end
end)
end[/code]
[QUOTE=code_gs;52843851]Firstly, you should really separate things into their proper realms - you're uselessly adding net callbacks serverside when they should be clientside only. Same situation with the hooks. Secondly, networking server->client doesn't provide a player variable in the net callback - you'll have to use LocalPlayer. In this situation, however, you can just use an OnEntityCreated hook to create the medal table on the player. Lastly, since you know the table structure in advance, you can just network each part individually.
Fixed code (I also got a bit carried away and added a small system to register and network medals efficiently):
Lump of code
[/QUOTE]
Bloody awesome of you, thanks a lot! Original code wasn't meant to look pretty as I was trying out ideas, but looking at how you separated the two worlds it's quite neat and I'll adopt something similar in the future.
I can't install a gmod server on my local machine.
[code]
Redirecting stderr to 'A:\Folder\logs\stderr.txt'
ILocalize::AddFile() failed to load file "public/steambootstrapper_english.txt".
[ 0%] Checking for available update...
[----] Downloading update (0 of 9,642 KB)...
[ 0%] Downloading update (0 of 9,642 KB)...
[ 0%] Downloading update (0 of 9,642 KB)...
[ 0%] Downloading update (662 of 9,642 KB)...
[ 6%] Downloading update (1,900 of 9,642 KB)...
[ 19%] Downloading update (3,144 of 9,642 KB)...
[ 32%] Downloading update (4,688 of 9,642 KB)...
[ 48%] Downloading update (6,206 of 9,642 KB)...
[ 64%] Downloading update (7,568 of 9,642 KB)...
[ 78%] Downloading update (9,234 of 9,642 KB)...
[ 95%] Downloading update (9,642 of 9,642 KB)...
[100%] Download Complete.
[----] Applying update...
[----] Extracting package...
[----] Extracting package...
[----] Extracting package...
[----] Extracting package...
[----] Extracting package...
[----] Installing update...
[----] Installing update...
[----] Installing update...
[----] Cleaning up...
[----] Update complete, launching...
Redirecting stderr to 'A:\Folder\logs\stderr.txt'
[ 0%] Checking for available updates...
[----] Verifying installation...
[ 0%] Downloading update...
[ 0%] Checking for available updates...
[----] Downloading update (0 of 6,216 KB)...
[ 0%] Downloading update (0 of 6,216 KB)...
[ 0%] Downloading update (0 of 6,216 KB)...
[ 0%] Downloading update (24 of 6,216 KB)...
[ 0%] Downloading update (952 of 6,216 KB)...
[ 15%] Downloading update (1,901 of 6,216 KB)...
[ 30%] Downloading update (3,112 of 6,216 KB)...
[ 50%] Downloading update (4,519 of 6,216 KB)...
[ 72%] Downloading update (5,982 of 6,216 KB)...
[ 96%] Downloading update (6,216 of 6,216 KB)...
[100%] Download complete.
[----] Extracting package...
[----] Extracting package...
[----] Extracting package...
[----] Extracting package...
[----] Extracting package...
[----] Installing update...
[----] Installing update...
[----] Installing update...
[----] Cleaning up...
[----] Update complete, launching Steamcmd...
Redirecting stderr to 'A:\Folder\logs\stderr.txt'
[ 0%] Checking for available updates...
[----] Verifying installation...
Steam Console Client (c) Valve Corporation
-- type 'quit' to exit --
Loading Steam API...OK.
Steam>login anonymous
Connecting anonymously to Steam Public...Logged in OK
Waiting for user info...OK
Steam>force_install_dir A:\Gmod
Steam>app_update 4020
Update state (0x3) reconfiguring, progress: 0.00 (0 / 0)
Update state (0x3) reconfiguring, progress: 0.00 (0 / 0)
Error! App '4020' state is 0x2 after update job.
Steam>app_update 4020 validate
Update state (0x0) : Timed out waiting for update to start, bailing.
Error! App '4020' state is 0x2 after update job.
Steam>app_update 4020 validate
Update state (0x0) : Timed out waiting for update to start, bailing.
Error! App '4020' state is 0x2 after update job.
[/code]
The error first came about when using the GUI Release on Github.
When installing CMD i noticed this error;
[code]ILocalize::AddFile() failed to load file "public/steambootstrapper_english.txt".[/code]
I feel like that should not cause this issue?
Just launched with Administrator Perms, seems to be working. Probably UAC being a pain.
Hello, i am still having a problem with my code. net.SendToServer and net.Receive doesn't work for me. Could anyone help me?
INIT.LUA
[CODE]
AddCSLuaFile("cl_init.lua");
util.AddNetworkString("druglab_toserver")
include("shared.lua")
DEFINE_BASECLASS("lab_base")
ENT.SeizeReward = 350
function ENT:Initialize()
BaseClass.Initialize(self)
self.SID = self:Getowning_ent().SID
end
function ENT:Use( ply, caller )
umsg.Start( "DrawTheMenu", ply )
umsg.Short( "1" )
umsg.End()
end
net.Receive( "druglab_toserver", ENT:createItem )
function ENT:createItem()
local drugType = net.ReadString()
local drugPos = self:GetPos()
local drug = ents.Create(drugType)
drug:SetPos(Vector(drugPos.x, drugPos.y, drugPos.z + 35))
drug.nodupe = true
drug:Spawn()
end
[/CODE]
CL_INIT
[CODE]
include("shared.lua")
function ENT:Draw()
self.Entity:DrawModel()
local dis = 512
hook.Add( "PreDrawHalos", "AddHalos", function()
--cache a trace
local tr = LocalPlayer():GetEyeTrace()
--make sure the trace hit an entity, make sure that it didn't hit the world, then we get teh squared distance which is way faster than getting the regular distance :D
if (tr.Entity and tr.HitNonWorld and IsValid(tr.Entity) and LocalPlayer():GetPos():DistToSqr(tr.Entity:GetPos()) <= (dis * dis)) then
halo.Add({self.Entity}, Color( 255, 0, 0 ))
end
end)
end
local function DrawTheMenu()
if ( !frame ) then
local frame = vgui.Create( "DFrame" )
frame:SetSize( 280, 280 )
frame:Center()
frame:SetVisible( true )
frame:MakePopup()
frame:SetTitle( "Drug Lab" )
frame:SetDeleteOnClose( true )
buttonLSD = vgui.Create( "DButton", frame )
buttonLSD:SetText( "LSD" )
buttonLSD:SetSize( 110, 50 )
buttonLSD:SetPos( 20, 45 )
buttonLSD.DoClick = function()
net.Start( "druglab_toserver" )
net.WriteString( "durgz_lsd" )
net.SendToServer()
end
buttonHeroin = vgui.Create( "DButton", frame )
buttonHeroin:SetText( "Heroin" )
buttonHeroin:SetSize( 110, 50 )
buttonHeroin:SetPos( 20, 100 )
buttonHeroin.DoClick = function()
net.Start( "druglab_toserver" )
net.WriteString("durgz_heroin")
net.SendToServer()
end
buttonMeth = vgui.Create( "DButton", frame )
buttonMeth:SetText( "Meth" )
buttonMeth:SetSize( 110, 50 )
buttonMeth:SetPos( 20, 155 )
buttonMeth.DoClick = function()
net.Start( "druglab_toserver" )
net.WriteString("durgz_meth")
net.SendToServer()
end
buttonCocaine = vgui.Create( "DButton", frame )
buttonCocaine:SetText( "Cocaine" )
buttonCocaine:SetSize( 110, 50 )
buttonCocaine:SetPos( 20, 210 )
buttonCocaine.DoClick = function()
net.Start( "druglab_toserver" )
net.WriteString("durgz_cocaine")
net.SendToServer()
end
buttonPCP = vgui.Create( "DButton", frame )
buttonPCP:SetText( "PCP" )
buttonPCP:SetSize( 110, 50 )
buttonPCP:SetPos( 150, 45 )
buttonPCP.DoClick = function()
net.Start( "druglab_toserver" )
net.WriteString("durgz_pcp")
net.SendToServer()
end
buttonMushroom = vgui.Create( "DButton", frame )
buttonMushroom:SetText( "Mushroom" )
buttonMushroom:SetSize( 110, 50 )
buttonMushroom:SetPos( 150, 100 )
buttonMushroom.DoClick = function()
net.Start( "druglab_toserver" )
net.WriteString("durgz_mushroom")
net.SendToServer()
end
buttonWeed = vgui.Create( "DButton", frame )
buttonWeed:SetText( "Weed" )
buttonWeed:SetSize( 110, 50 )
buttonWeed:SetPos( 150, 155 )
buttonWeed.DoClick = function()
net.Start( "druglab_toserver" )
net.WriteString("durgz_weed")
net.SendToServer()
end
buttonCigarettes = vgui.Create( "DButton", frame )
buttonCigarettes:SetText( "Cigarettes" )
buttonCigarettes:SetSize( 110, 50 )
buttonCigarettes:SetPos( 150, 210 )
buttonCigarettes.DoClick = function()
net.Start( "druglab_toserver" )
net.WriteString("durgz_cigarette")
net.SendToServer()
end
end
end
usermessage.Hook( "DrawTheMenu", DrawTheMenu )
[/CODE]
SHARED.LUA
[CODE]
ENT.Base = "lab_base"
ENT.PrintName = "Drug Lab"
function ENT:initVars()
self.model = "models/props_lab/crematorcase.mdl"
self.initialPrice = 100
self.labPhrase = DarkRP.getPhrase("drug_lab")
self.itemPhrase = DarkRP.getPhrase("drugs")
self.noIncome = true
self.camMul = -39
end
[/CODE]
Not sure where to find the problem here but the hud draws the money and hunger at 0 while not being able to spend more than what we spawn with. I have mysql hooked up and it seems like my money is stuck at 1000, I cannot lower it or higher it by any means, for example if I were to buy something it'd stay at 1000 and if I were to try to raise it with /setmoney, nothing happens. I can however edit mysql through myphpadmin in my local setup and edit it through there and it'd all work out.
Could this be a database responsive issue?
There are no errors that (I think) link to this in any way, how would I go about finding the root of the problem?
edit; the scoreboard also doesn't respond when trying to change jobs, it'd stay at citizen.
thanks in advance.
[url]https://github.com/SurelyExploding/noobonicplague/tree/bb851fbc429f82d10e6dd96c18595ac336e67592/gamemode[/url]
[QUOTE=m0uka;52844082]Hello, i am still having a problem with my code. net.SendToServer and net.Receive doesn't work for me. Could anyone help me?
lods of code
[/QUOTE]
Try
[lua]
net.Receive( "druglab_toserver", function()
local drugType = net.ReadString()
local drugPos = self:GetPos()
local drug = ents.Create(drugType)
drug:SetPos(Vector(drugPos.x, drugPos.y, drugPos.z + 35))
drug.nodupe = true
drug:Spawn()
end)
[/lua]
Hi, I'm trying to make a small ammo counter for a gamemode, but it only draws after I save the file after creating a game? No idea why this is happening, and some help would be appreciated!
ply = LocalPlayer()
[lua]
function GM:HUDPaint()
if ( IsValid( ply ) ) then
if IsValid(ply) and ply:Alive() and ply:GetActiveWeapon() ~= NULL then
local wep = ply:GetActiveWeapon()
local col = team.GetColor(ply:Team())
draw.RoundedBox(15,ScrW()/2 + 420, ScrH()/2 + 170,210,130,Color(0,0,0,122))
draw.SimpleText(wep:Clip1(), "WeaponAmmoCounter", ScrW()/2 + 430, ScrH()/2 + 200, col)
draw.SimpleText(ply:GetAmmoCount(wep:GetPrimaryAmmoType()) , "WeaponAmmoCounter", ScrW()/2 + 520, ScrH()/2 + 200, col)
draw.SimpleText("/", "WeaponAmmoCounter", ScrW()/2 + 500, ScrH()/2 + 200, col)
surface.SetDrawColor(col)
surface.DrawRect(ScrW()/2 + 420, ScrH()/2 + 255, 210, 5 )
surface.DrawRect(ScrW()/2 + 420, ScrH()/2 + 203, 210, 5 )
draw.SimpleText(ply:GetAmmoCount(wep:GetSecondaryAmmoType()) , "WeaponAmmoCounter", ScrW()/2 + 430, ScrH()/2 + 250, col)
draw.SimpleText(string.upper(wep:GetPrintName()), "WeaponName", ScrW()/2 + 425, ScrH()/2 +170, col)
end
end
end
[/lua]
[QUOTE=JA4AKE;52845354]Hi, I'm trying to make a small ammo counter for a gamemode, but it only draws after I save the file after creating a game? No idea why this is happening, and some help would be appreciated!
ply = LocalPlayer()
[lua]
function GM:HUDPaint()
if ( IsValid( ply ) ) then
if IsValid(ply) and ply:Alive() and ply:GetActiveWeapon() ~= NULL then
local wep = ply:GetActiveWeapon()
local col = team.GetColor(ply:Team())
draw.RoundedBox(15,ScrW()/2 + 420, ScrH()/2 + 170,210,130,Color(0,0,0,122))
draw.SimpleText(wep:Clip1(), "WeaponAmmoCounter", ScrW()/2 + 430, ScrH()/2 + 200, col)
draw.SimpleText(ply:GetAmmoCount(wep:GetPrimaryAmmoType()) , "WeaponAmmoCounter", ScrW()/2 + 520, ScrH()/2 + 200, col)
draw.SimpleText("/", "WeaponAmmoCounter", ScrW()/2 + 500, ScrH()/2 + 200, col)
surface.SetDrawColor(col)
surface.DrawRect(ScrW()/2 + 420, ScrH()/2 + 255, 210, 5 )
surface.DrawRect(ScrW()/2 + 420, ScrH()/2 + 203, 210, 5 )
draw.SimpleText(ply:GetAmmoCount(wep:GetSecondaryAmmoType()) , "WeaponAmmoCounter", ScrW()/2 + 430, ScrH()/2 + 250, col)
draw.SimpleText(string.upper(wep:GetPrintName()), "WeaponName", ScrW()/2 + 425, ScrH()/2 +170, col)
end
end
end
[/lua][/QUOTE]
if I'm not mistaken, LocalPlayer() is nil when cl files are initiated, try defining ply inside the hudpaint func, or just use LocalPlayer() and not assign it to a variable.
[QUOTE=JA4AKE;52845354]Hi, I'm trying to make a small ammo counter for a gamemode, but it only draws after I save the file after creating a game? No idea why this is happening, and some help would be appreciated!
ply = LocalPlayer()
[lua]
function GM:HUDPaint()
if ( IsValid( ply ) ) then
if IsValid(ply) and ply:Alive() and ply:GetActiveWeapon() ~= NULL then
local wep = ply:GetActiveWeapon()
local col = team.GetColor(ply:Team())
draw.RoundedBox(15,ScrW()/2 + 420, ScrH()/2 + 170,210,130,Color(0,0,0,122))
draw.SimpleText(wep:Clip1(), "WeaponAmmoCounter", ScrW()/2 + 430, ScrH()/2 + 200, col)
draw.SimpleText(ply:GetAmmoCount(wep:GetPrimaryAmmoType()) , "WeaponAmmoCounter", ScrW()/2 + 520, ScrH()/2 + 200, col)
draw.SimpleText("/", "WeaponAmmoCounter", ScrW()/2 + 500, ScrH()/2 + 200, col)
surface.SetDrawColor(col)
surface.DrawRect(ScrW()/2 + 420, ScrH()/2 + 255, 210, 5 )
surface.DrawRect(ScrW()/2 + 420, ScrH()/2 + 203, 210, 5 )
draw.SimpleText(ply:GetAmmoCount(wep:GetSecondaryAmmoType()) , "WeaponAmmoCounter", ScrW()/2 + 430, ScrH()/2 + 250, col)
draw.SimpleText(string.upper(wep:GetPrintName()), "WeaponName", ScrW()/2 + 425, ScrH()/2 +170, col)
end
end
end
[/lua][/QUOTE]
You probably forgot to add a hook
[QUOTE=blackwidowman;52845532]You probably forgot to add a hook[/QUOTE]
The entire method is a hook
Is there a way to detect if the a Player is falling down?
Been playing with the Move hook.
For some reason the script below always returns 0... Even when I'm moving vertically.
[code]-- Server-side file
hook.Add( "Move", "test", function ( ply, mv )
print( mv:GetUpSpeed() )
end )[/code]
[QUOTE=Kanchi;52845853]Is there a way to detect if the a Player is falling down?
Been playing with the Move hook.
For some reason the script below always returns 0... Even when I'm moving vertically.
[code]-- Server-side file
hook.Add( "Move", "test", function ( ply, mv )
print( mv:GetUpSpeed() )
end )[/code][/QUOTE]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/GetVelocity]Entity:GetVelocity[/url]().z will be the vertical speed. Negative is falling.
[QUOTE=Kanchi;52845853]Is there a way to detect if the a Player is falling down?
Been playing with the Move hook.
For some reason the script below always returns 0... Even when I'm moving vertically.
[code]-- Server-side file
hook.Add( "Move", "test", function ( ply, mv )
print( mv:GetUpSpeed() )
end )[/code][/QUOTE]
[QUOTE=txike;52847103][img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/GetVelocity]Entity:GetVelocity[/url]().z will be the vertical speed. Negative is falling.[/QUOTE]
You also have [img]http://wiki.garrysmod.com/favicon.ico[/img][url=https://wiki.garrysmod.com/page/Entity/IsOnGround]Entity:IsOnGround[/url]() which you can use to check if the player is no longer falling, as sometimes GetVelocity().z will return a really small number, meaning the player is still "technically" falling.
Is there an easy way to find where a bullet ended up? Trying to add accurate contrails to a SWEP.
I'm trying to set entity owner when somebody buys it.
I used this:
[CODE]
hook.Add("playerBoughtCustomEntity", "SetOwnerOnEntBuy", function(ply, enttbl, ent, price)
ent:CPPISetOwner(ply)
end)[/CODE]
But now i want to set owner only to specified entities.(e.g mediaplayer_tv etc)
And i created a table and added some functions, in result i got this:
[CODE]local entTable = { "mediaplayer_tv", "boost_printer" }
hook.Add("playerBoughtCustomEntity", "SetOwnerOnEntBuy", function(ply, enttbl, ent, price)
if table.HasValue(entTable,ent.GetClass()) then
ent:CPPISetOwner(ply)
end
end)[/CODE]
But this code doesn't seem to work i've got error:
[CODE][ERROR] lua/autorun/server/setown.lua:5: Tried to use a NULL entity!
1. GetClass - [C]:-1
2. fn - lua/autorun/server/setown.lua:5
3. Call - addons/ulib/lua/ulib/shared/hook.lua:109
4. callback - gamemodes/darkrp/gamemode/modules/base/sh_createitems.lua:364
5. callback - gamemodes/darkrp/gamemode/modules/chat/sv_chat.lua:17
6. unknown - gamemodes/darkrp/gamemode/modules/chat/sv_chat.lua:255
7. unknown - lua/includes/modules/concommand.lua:54[/CODE]
P.s sorry for my bad english
:snip: i'm dumb
[QUOTE=MPan1;52850263]This is the problem:
[CODE]
if table.HasValue(entTable,ent.GetClass()) then
[/CODE]
entTable should be enttbl.
[CODE]
if table.HasValue( enttbl, ent.GetClass() ) then
[/CODE][/QUOTE]
[CODE][ERROR] lua/autorun/server/setown.lua:4: Tried to use a NULL entity!
1. GetClass - [C]:-1
2. fn - lua/autorun/server/setown.lua:4
3. Call - addons/ulib/lua/ulib/shared/hook.lua:109
4. callback - gamemodes/darkrp/gamemode/modules/base/sh_createitems.lua:364
5. callback - gamemodes/darkrp/gamemode/modules/chat/sv_chat.lua:17
6. unknown - gamemodes/darkrp/gamemode/modules/chat/sv_chat.lua:255
7. unknown - lua/includes/modules/concommand.lua:54
[/CODE]
Sorry, try this:
[CODE]
local entTable = {
mediaplayer_tv = true,
boost_printer = true
}
hook.Add( "playerBoughtCustomEntity", "SetOwnerOnEntBuy", function( ply, enttbl, ent, price )
if entTable[ ent:GetClass() ] then
ent:CPPISetOwner( ply )
end
end )
[/CODE]
Sorry, you need to Log In to post a reply to this thread.