Anyone have any idea how to fix these issues?
Tooltips and dropdown are being drawn behind the panel. This didn't happen in GM12. I tried setting Zpos of the panels and setting DrawOnTop to false for the parent panels.
[IMG]http://i.imgur.com/5TCPm.png[/IMG]
Second issue is the DColorMixer. The background image for the alpha bar is extending far beyond the alpha bar.
[IMG]http://i.imgur.com/4Cmsa.png[/IMG]
-snip-
I am running this code, but it isn't working properly
maps.lua
[Lua]
local Map = game.GetMap()
function GM:PlayerLoadout( pl )
if Map!= "mg_ka_trains" then
ply:Give( "weapon_crowbar" )
end
[/Lua]
[QUOTE=Gamz365;38582546]I am running this code, but it isn't working properly
maps.lua
[Lua]
local Map = game.GetMap()
function GM:PlayerLoadout( pl )
if Map!= "mg_ka_trains" then
ply:Give( "weapon_crowbar" )
end
[/Lua][/QUOTE]
Based on the information you provided, I have come to the conclusion that you're missing an end.
EDIT: Also, you're being inconsistent with the name of your player variable. That should have returned an error, are you sure you're running the code properly?
[QUOTE=Dark Slayre;38575491][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]
This is using GetActiveWeapon correct? That means it is not possible to record kills from Grenades, C4, etc..
I need a quick help, once I've added image files through resource.AddFile("dir"), how do I access them to use .pngs as materials?
I tried [lua]resource.AddFile("icons/spellicon.png")[/lua]
Then on the client:
[lua]function DrawClassIcons( self )
surface.SetMaterial( Material( "icons/spellicon.png" ) );
surface.SetDrawColor( Color(255, 255, 255, 255) );
surface.DrawTexturedRect( 128, 128, 64, 64 );
end[/lua]
[QUOTE=brickyross;38582831]This is using GetActiveWeapon correct? That means it is not possible to record kills from Grenades, C4, etc..[/QUOTE]
Of course it's possible to record kills from weapons. Just do something like this:
[lua]function GM:PlayerDeath(pl, attacker, dmginfo)
if not IsValid(pl) then return end
local inflictor = dmginfo:GetInflictor()
if IsValid(attacker) then -- You can track whatever you want from the weapon, I chose the class
if inflictor.GetClass and inflictor:GetClass() then
local inflictorclass = inflictor:GetClass()
attacker.WeaponKills = attacker.WeaponKills or {}
attacker.WeaponKills[inflictorclass] = (attacker.WeaponKills[inflictorclass] + 1) or 1
end
end
end[/lua]
If you want to get how many kills a weapon has, just do:
[lua]attacker.WeaponKills["weapon_mp5"][/lua]
That would be all the kills the attacker has with the weapon mp5, if any. Be sure if you're calling that, WeaponKills is already defined (might want to define it on PlayerInitialSpawn).
[QUOTE=CrashLemon;38583237]That didn't change anything unfortunatly...[/QUOTE]
Try putting it in HUDPaint.
How do you make a longish (4-5 second) sound loop in a SWEP while you hold down the fire button?
Any attempts I make end up making the sound not stop properly.
Trying to make this swep disappear off of view while reloading, then return after it's finished reloading. I can get it to disappear, but not come back. Can anyboy help?
[code]function SWEP:Reload()
if (self.Weapon:DefaultReload(ACT_VM_RELOAD)) then -- These are the lines
self.Owner:DrawViewModel(false) -- These are the lines
end -- These are the lines
-- Ignore this really)
if ( self.Reloadaftershoot > CurTime() ) then return end
-- If you're firering, you can't reload
self.Weapon:DefaultReload(ACT_VM_RELOAD)
if ( self.Weapon:Clip1() < self.Primary.ClipSize ) and self.Owner:GetAmmoCount(self.Primary.Ammo) > 0 then
-- When the current clip < full clip and the rest of your ammo > 0, then
self.Owner:SetFOV( 0, 0.5 )
-- Zoom = 0
self:EmitSound( "weapons/laserrifle/wpn_riflelaser_reloadinout.wav" )
self:SetIronsights(false)
-- Set the ironsight to false
end
end[/code]
[QUOTE=Persious;38583674]Try putting it in HUDPaint.[/QUOTE]
The problem is that I just can't manage to get my custom image... no matter what I put in the material path it always return the freaking pink and black checker...
The file is located in "mygamemode/content/materials/icons/missing_spell_icons.png"
The client downloaded the file.
Here's the code
[lua] surface.SetDrawColor( Color(255, 255, 255, 255))
surface.SetMaterial( Material( "icons/missing_spell_icon.png" ) );
surface.DrawTexturedRect( self.IconX[k], IconY, 64, 64 );[/lua]
[QUOTE=CrashLemon;38584683]The problem is that I just can't manage to get my custom image... no matter what I put in the material path it always return the freaking pink and black checker...
The file is located in "mygamemode/content/materials/icons/missing_spell_icons.png"
The client downloaded the file.
Here's the code
[lua] surface.SetDrawColor( Color(255, 255, 255, 255))
surface.SetMaterial( Material( "icons/missing_spell_icon.png" ) );
surface.DrawTexturedRect( self.IconX[k], IconY, 64, 64 );[/lua][/QUOTE]
I don't know if it was a simple typo... but the filepath in your code is missing an 's' on icons. That would pretty much wreck everything.
It also needs to be in materials/icons/, not gamemodes/mygamemode/content/materials/icons, if you want the client to download it.
So, I'm having a few issues with an swep script that keeps getting banned because of this error I can't figure out
Here's the error that is shown:
lua/weapons/weapon_life-ender_admin/shared.lua:105: attempt to call field 'Create' (a nil value)
aaaand here's the snippit of code that its from:
//SWEP:SecondaryFire()\\
function SWEP:SecondaryAttack()
if ( !self:CanSecondaryAttack() ) then return end
local rnda = -self.Secondary.Recoil
local rndb = self.Secondary.Recoil * math.random(-1, 1)
self.Owner:ViewPunch( Angle( rnda,rndb,rnda ) )
local eyetrace = self.Owner:GetEyeTrace()
self.Weapon:EmitSound ( self.Secondary.Sound )
self:ShootEffects()
local explode = ents.Create("env_explosion") <-------------- Here's the suspected bad line
explode:SetPos( eyetrace.HitPos )
explode:SetOwner( self.Owner )
explode:Spawn()
explode:SetKeyValue("iMagnitude","175")
explode:Fire("Explode", 0, 0 )
explode:EmitSound("weapon_AWP.Single", 400, 400 )
self.Weapon:SetNextPrimaryFire( CurTime() + self.Secondary.Delay )
self.Weapon:SetNextSecondaryFire( CurTime() + self.Secondary.Delay )
self:TakePrimaryAmmo(self.Secondary.TakeAmmo)
end
//SWEP:SecondaryFire()\\
[[b][/b]code]
[editline]25th November 2012[/editline]
or, even better: [[b][/b]lua]
How would I go about counting how many people bought something here?
Also, how would I set it if a player can't buy something rather tha the wjole server, like ply:CanBuy()?
[CODE]local _date = os.date("%b") .. os.date("%d")
local _R = debug.getregistry()
function _R.Player:StoreInitialize( )
tmysql.query( "SELECT value FROM tokens WHERE steamid = '" .. self:SteamID() .. "'", function( tokens )
if !tokens or #tokens == 0 then
tmysql.query( "INSERT INTO tokens VALUES( '" .. self:Nick() .. "', '" .. self:SteamID() .. "', '" .. 5 .. "' )" )
self:SetNWInt("tokens", 5)
else
self:SetNWInt("tokens", tonumber( tokens[1][1] ) )
end
end)
tmysql.query( "SELECT value FROM lastjoin WHERE steamid = '" .. self:SteamID() .. "'", function( date )
if !date or !date[1] then
tmysql.query( "INSERT INTO lastjoin VALUES( '" .. self:SteamID() .. "', '" .. tmysql.escape(_date) .. "' )" )
if self:IsAdmin() or self:IsUserGroup("vip") or self:IsUserGroup("mod") then
self:SetNWInt("tokens", self:GetNWInt("tokens") + 20)
else
self:SetNWInt("tokens", self:GetNWInt("tokens") + 1)
end
else
if date[1][1] != _date then
tmysql.query( "UPDATE lastjoin SET value = '" .. tmysql.escape(_date) .. "' WHERE steamid = '" .. self:SteamID() .. "'", SQLHandle )
if self:IsAdmin() or self:IsUserGroup("vip") or self:IsUserGroup("mod") then
self:SetNWInt("tokens", self:GetNWInt("tokens") + 20)
else
self:SetNWInt("tokens", self:GetNWInt("tokens") + 1)
end
end
end
end)
end
function _R.Player:Save( )
local cash = tonumber(self:GetNWInt("tokens"))
tmysql.query( "UPDATE tokens SET value = '" .. cash .. "' WHERE steamid = '" .. self:SteamID() .. "'", SQLHandle )
end
function _R.Player:AddTokens( n )
if !n then return end
math.floor(tonumber(n))
self:SetNWInt("tokens", self:GetNWInt("tokens") + n)
self:Save()
end
function _R.Player:TakeTokens( n )
if !n then return end
math.floor(tonumber(n))
self:SetNWInt("tokens", self:GetNWInt("tokens") - n)
self:Save()
end
function _R.Player:BuyItem( id )
local id = tonumber(id)
if id == 0 then
self:SetCredits(self:GetCredits() + 1)
self:TakeTokens( Store.ItemsTable[id][2] )
self:ChatPrint( "You bought " .. Store.ItemsTable[id][1] .. " for " .. tonumber(Store.ItemsTable[id][2]) .. " tokens." )
elseif id == 1 then
local found = false
if self.ForceDetective then return end
if team.NumPlayers(1) >= 8 then
for k, v in pairs(player.GetAll()) do
if v.ForceTraitor then
self:ChatPrint("Too many people have bought traitor for next round.")
found = true
end
end
if !found then
-- boughtT + 1
self.ForceTraitor = true
self:TakeTokens( Store.ItemsTable[id][2] )
self:ChatPrint( "You bought " .. Store.ItemsTable[id][1] .. " for " .. tonumber(Store.ItemsTable[id][2]) .. " tokens" )
self:ChatPrint( "You will be made " .. Store.ItemsTable[id][1] .. " next round." )
end
end
elseif id == 2 then
local found = false
if self.ForceTraitor then return end
if team.NumPlayers(1) >= 8 then
for k, v in pairs(player.GetAll()) do
if v.ForceDetective then
self:ChatPrint("Too many people have bought detective for next round.")
found = true
return
end
end
if !found then
self.ForceDetective = true
self:TakeTokens( Store.ItemsTable[id][2] )
self:ChatPrint( "You bought " .. Store.ItemsTable[id][1] .. " for " .. tonumber(Store.ItemsTable[id][2]) .. " tokens" )
self:ChatPrint( "You will be made " .. Store.ItemsTable[id][1] .. " next round." )
end
end
end[/CODE]
[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
print(amount)
sql.Query( "UPDATE inventory SET n = `"..i.."`, amount = `"..amount.."`, id = `"..id.."` WHERE uniqueid = "..tostring(uniqueID).."" )
print(sql.LastError()) -- no such column: 1, 2, 3 and so on every line[/lua]
What's wrong with it?
[QUOTE=Wolfo;38586556][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
print(amount)
sql.Query( "UPDATE inventory SET n = `"..i.."`, amount = `"..amount.."`, id = `"..id.."` WHERE uniqueid = "..tostring(uniqueID).."" )
print(sql.LastError()) -- no such column: 1, 2, 3 and so on every line[/lua]
What's wrong with it?[/QUOTE]
`` are for column names
'' are for strings
[QUOTE=CrashLemon;38584683]The problem is that I just can't manage to get my custom image... no matter what I put in the material path it always return the freaking pink and black checker...
The file is located in "mygamemode/content/materials/icons/missing_spell_icons.png"
The client downloaded the file.
Here's the code
[lua] surface.SetDrawColor( Color(255, 255, 255, 255))
surface.SetMaterial( Material( "icons/missing_spell_icon.png" ) );
surface.DrawTexturedRect( self.IconX[k], IconY, 64, 64 );[/lua][/QUOTE]
don't call Material inside draw/paint functions, put local mat = Material( "whatever" ) outside the function then use mat instead.
[QUOTE=Darkwater124;38586758]`` are for column names
'' are for strings[/QUOTE]
So should I replace every ` with ' since I want to add data to inventory?
[QUOTE=CrashLemon;38584683]The problem is that I just can't manage to get my custom image... no matter what I put in the material path it always return the freaking pink and black checker...
The file is located in "mygamemode/content/materials/icons/missing_spell_icons.png"
The client downloaded the file.
Here's the code
[lua] surface.SetDrawColor( Color(255, 255, 255, 255))
surface.SetMaterial( Material( "icons/missing_spell_icon.png" ) );
surface.DrawTexturedRect( self.IconX[k], IconY, 64, 64 );[/lua][/QUOTE]
Material() defaults to the materials diretory, looks like you're using the icons directory instead (Judging from the resource.AddFile you posted earlier)
Try this:
[lua]Material( "../icons/missing_spell_icon.png" )[/lua]
[QUOTE=Wolfo;38587664]So should I replace every ` with ' since I want to add data to inventory?[/QUOTE]
In that code snippet, yes.
Basically, before the = you use `` and after it you use ''. (`` are optional, but recommended for consistency).
Don't forget to escape [B]EVERYTHING[/B] the user can input (including names!) to prevent SQL injecting. If you want to store a username in a database and you don't escape it, someone can change his name to '; DROP TABLE inventory; and it's byebye inventories.
-snip-
[QUOTE=G4MB!T;38587818]png files are not materials
use a DImage for pngs[/QUOTE]
[quote=The page at http://wiki.garrysmod.com/page/Global/Material]
Supports vmt and png.
[/quote]
oh, i didnt know :) sorry
[QUOTE=Halokiller38;38584616]Trying to make this swep disappear off of view while reloading, then return after it's finished reloading. I can get it to disappear, but not come back. Can anyboy help?
[code]function SWEP:Reload()
if (self.Weapon:DefaultReload(ACT_VM_RELOAD)) then -- These are the lines
self.Owner:DrawViewModel(false) -- These are the lines
end -- These are the lines
-- Ignore this really)
if ( self.Reloadaftershoot > CurTime() ) then return end
-- If you're firering, you can't reload
self.Weapon:DefaultReload(ACT_VM_RELOAD)
if ( self.Weapon:Clip1() < self.Primary.ClipSize ) and self.Owner:GetAmmoCount(self.Primary.Ammo) > 0 then
-- When the current clip < full clip and the rest of your ammo > 0, then
self.Owner:SetFOV( 0, 0.5 )
-- Zoom = 0
self:EmitSound( "weapons/laserrifle/wpn_riflelaser_reloadinout.wav" )
self:SetIronsights(false)
-- Set the ironsight to false
end
end[/code][/QUOTE]
Can anybody help me with this?
[QUOTE=Darkwater124;38587774]
Don't forget to escape [B]EVERYTHING[/B] the user can input (including names!) to prevent SQL injecting. If you want to store a username in a database and you don't escape it, someone can change his name to '; DROP TABLE inventory; and it's byebye inventories.[/QUOTE]
Sound painful, but what do you mean with [I]escape[/I] everything?
Escape means that you prevent something like if someone's name is "..print('hur').." and you try to load something related to their name, it ends up doing ""..print('hur').."", therefor letting them run Lua. Most mysql modules have a built in function, and the SQLite thing included has sql.SQLStr().
Sorry, you need to Log In to post a reply to this thread.