[QUOTE=bigdogmat;51937576]You have to pass extra arguments as extra arguments to the function, e.g.
[code]
RunConsoleCommand("ulx", "cloak", randomply, "105")
[/code]
Also, `randomply` when converted to a string won't work, considering it's ulx you'll probably have to do something like
[code]
RunConsoleCommand("ulx", "cloak", '$' .. randomply:UserID(), "105")
[/code]
Though it'd be preferred that you just call the function to do this on a player.
Edit: Also also, just use
[code]
local tab = player.GetAll()
local randomPly = tab[math.random(#tab)]
[/code]
Considering that table is always sequential
Edit edit: Seems the code block doesn't want to show the $ in my second example, but it's
'$' .. randomply:UserID()[/QUOTE]
I just tried this but still no luck
[CODE]RunConsoleCommand ("ulx", "csay", randomply:UserID(), "Has been chosen as the hidden he will be cloaked shortly PREPARE....")[/CODE]
That's the line I made to test it, but it doesn't seem to work.
[QUOTE=Scu11y;51937643]I just tried this but still no luck
[CODE]RunConsoleCommand ("ulx", "csay", randomply:UserID(), "Has been chosen as the hidden he will be cloaked shortly PREPARE....")[/CODE]
That's the line I made to test it, but it doesn't seem to work.[/QUOTE]
Like I said, you have to do
'$' .. randomply:UserID()
Because that's how you target by user id in ulx
Going against my snip, how can I prevent, clientside, the player's Y axis from changing? I want to make it so the cursor can only move along the X axis.
[QUOTE=Author.;51644212][IMG]https://u.nya.is/sldwzj.png[/IMG]
[B]Welcome to Problems That Don't Need Their Own Thread v5![/B]
Have a small problem in your Lua code that keeps nagging you, but you feel like it's not worth making a thread for? Well then you've come to the right place! Reply to this thread with your problems and we might just be able to help you out!
[B]How to go about posting your issue[/B]
- Give a good description on the issue
- What have you tried doing to solve the issue? (make a post if you've already tried everything you can)
- Post the necessary code for someone to help you solve the issue (wrap it in [noparse][code]...[/code][/noparse] tags)
- Post any other information that can be helpful for solving the issue (any errors)
- Any media that could better display the issue
Don't ask for help when it's not your own code, contact the creator instead!
[B]Useful sources[/B]
[B]Official Garry's Mod Wiki:[/B] [url=http://wiki.garrysmod.com/page/Main_Page]wiki.garrysmod.org[/url]
[B]Old Garry's Mod Wiki. Has more examples:[/B] [url=https://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index4875.html]maurits.tv (long url)[/url]
[B]Garry's Mod GitHub (The Lua files of Garry's Mod):[/B] [url=https://github.com/garrynewman/garrysmod]github.com/garrynewman/garrysmod[/url]
[B]Previous Threads: [/B]
v1: [url]http://facepunch.com/showthread.php?t=1348923[/url]
v2: [url]http://facepunch.com/showthread.php?t=1411111[/url]
v3: [url]https://facepunch.com/showthread.php?t=1458227[/url]
v4: [url]https://facepunch.com/showthread.php?t=1508566[/url][/QUOTE]
I am working on a gamemode and now out of no where it keeps saying this...
KeyValues Error: LoadFromBuffer: missing { in file gamemodes/swrp2/swrp2.txt
[code]
"swrp2"
{
"base" "sandbox"
"title" "StarWarsRP"
"version" "1.4.0"
"menusystem" "1"
"author_name" "DanK"
"author_email" ""
"author_url" ""
"icon" ""
"info" ""
"hide" "0"
}
[/code]
[QUOTE=dx9er;51940714]I'm not sure, but it also prints something like that in my console when I switch gamemodes (even on known gamemodes such as darkrp).
I might be wrong, but I think the gamemode still runs just fine and you shouldn't really worry about the error, unless there's a fix for it.[/QUOTE]
It's not showing up for me in the dropdown, but I can still change to it (using gamemode swrp2)
Figured out my issue. For those in the future:
[code]
--Remove their ability to look along the Y axis, because it fucks with shit.
hook.Add( "Think", "YAxisRestriction", function()
local ply = LocalPlayer()
local plyAng = ply:EyeAngles()
ply:SetEyeAngles( Angle( 0, plyAng.y, plyAng.r ) )
end )
[/code]
How to calculate player position on minimap? map.png has 3072x3072 resolution.
[QUOTE=VeXan;51941511]Figured out my issue. For those in the future:
[code]
--Remove their ability to look along the Y axis, because it fucks with shit.
hook.Add( "Think", "YAxisRestriction", function()
local ply = LocalPlayer()
local plyAng = ply:EyeAngles()
ply:SetEyeAngles( Angle( 0, plyAng.y, plyAng.r ) )
end )
[/code][/QUOTE]
Not sure exactly but I think you're better off messing with this in CalcView.
[QUOTE=YourStalker;51941543]Not sure exactly but I think you're better off messing with this in CalcView.[/QUOTE]
I know that using the Think hook isn't really all that good, but I tried doing it in CalcView, and I couldn't get it working. Any recommendation? This seems to work just fine.
CalcView will only affect it visually, but players would still be able to aim up and down. I'd say SetupMove (or Move?) is where this should go.
- snip -
Does anyone know how [url=http://wiki.garrysmod.com/page/Enums/_USE]DIRECTIONAL_USE[/url] works? Because in my tests, it simply doesn't work at all.
Is there a reason why PhysicsCollide isn't being called in my entity? Here's a dummy I made for testing:
[code]AddCSLuaFile()
ENT.Spawnable = true
ENT.Type = "anim"
function ENT:Initialize()
self:SetModel("models/weapons/w_eq_fraggrenade_thrown.mdl")
--self:AddEFlags(EFL_DONTBLOCKLOS)
if (SERVER) then
self:SetUseType(USE_TOGGLE)
--self:SetTrigger(true)
else
--self:SetupPhonemeMappings("phonemes")
end
self:SetSolidFlags(FSOLID_NOT_STANDABLE)
self:SetMoveType(MOVETYPE_FLYGRAVITY)
self:SetSolid(SOLID_BBOX)
self:SetCollisionBounds(Vector(-2, -2, -2), Vector(2, 2, 2))
self:SetGravity(0.4)
self:SetFriction(0.2)
self:SetElasticity(0.45)
if (SERVER) then
--self:SetMoveCollide(MOVECOLLIDE_COUNT)
end
end
function ENT:PhysicsCollide()
print("Called")
end[/code]
[QUOTE=code_gs;51945608]Is there a reason why PhysicsCollide isn't being called in my entity? Here's a dummy I made for testing:
[code]self:SetMoveType(MOVETYPE_FLYGRAVITY)[/code][/QUOTE]
Does that go through things? I don't think PhysicsCollide works on stuff in Noclip or something similar.
[QUOTE=VeXan;51945679]Does that go through things? I don't think PhysicsCollide works on stuff in Noclip or something similar.[/QUOTE]
No, but I figured out that PhysicsCollide requires the move type to be MOVETYPE_VPHYSICS and the solid type to SOLID_VPHYSICS. None of this was documented.
I'm having some issues playing a custom sound.
I've got my sound files in [quote]addons/addonname/sound/pickup_health.mp3[/quote] and I'm doing
[code]sound.Add( {
name = "health_pickup",
channel = CHAN_STATIC,
volume = 1.0,
level = 80,
pitch = 100,
sound = "sound/pickup_health.mp3"
} )[/code]
followed by [code]ply:EmitSound( "health_pickup" )[/code] called serverside.
It's spitting this error into the console:
[quote]Failed to load sound "sound\pickup_health.mp3", file probably missing from disk/repository[/quote]
Any idea why this wouldn't work?
Omit the "sound/"
Is there anyway to get the length of a timer by it's identifier?
I know I can get the time remaining of the timer, but I want the value that it started out with.
[QUOTE=kpjVideo;51946659]Is there anyway to get the length of a timer by it's identifier?
I know I can get the time remaining of the timer, but I want the value that it started out with.[/QUOTE]
Nah but you could easily make a function (more like an object) that stores the time on it as well.
[QUOTE=YourStalker;51946751]Nah but you could easily make a function (more like an object) that stores the time on it as well.[/QUOTE]
Valid point, I'm surprised that isn't already a function tbh. Maybe there's a good reason
[QUOTE=kpjVideo;51946784]Valid point, I'm surprised that isn't already a function tbh. Maybe there's a good reason[/QUOTE]
There's likely no reason to be honest. It's just something that's not often needed, used, or thought about. It's something that if you submitted in a pull request they'd probably just say "meh do it yourself".
Someone help: I've written too much boilerplate.
Let me explain,
I have an RPG style gamemode, as far as the "core" of the game goes I need (and have made, more or less):
* Itemsystem (+loot dropping from huntable npc's)
* Inventories (+shop npcs, chests placed around that map that have loot)
* Combat
* Quests (+with multiple paths and whatnot)
* Skills
* Multi-server game world
I find myself spending a lot of time doing:
Weapons, each weapon needs to have swing arcs, which I automatically generate from pac+animation, but they still take forever to write. Here's an example of a super-simple weapon:
[code]
--[[
An hammer weapon
]]
local com = nrequire("core/inventory/common/weapons.lua")
local reg = nrequire("core/inventory/item.lua")
local pac,eff
if SERVER then
pac = nrequire("core/pac/sv_pac.lua")
else
eff = nrequire("core/clienteffects/blocked.lua")
end
local item = {}
--Required, a name, all item names must be unique
item.Name = "Scrap Hammer"
--Optional, a tooltip to display
item.Tooltip = "Bits of scrap put togeather to resemble a hammer"
--Required Returns the data needed to rebuild this item, should only contain the minimum data nessessary since this gets sent over the network
item.Serialize = function(self)
return ""
end
--Required, Rebuilds the item from data created in Serialize, if the item is different from the "main" copy of the item, it should retun a tabl.Copy(self), with the appropriate fields set.
item.DeSerialize = function(self,string)
return self
end
--Optional, when the player clicks this item, a menu will show up, if the menu item is clicked, the function is ran. This is all run client side, so if you want it to do something, you'll need to use the net library.
function item.GetOptions(self)
local options = {}
options["test"] = function() print("You pressed test!") end
options["toast"] = function() print("You pressed toast!") end
options["Drop"] = ART.DropItem(self)
return options
end
function item.DoOnPanel(dimagebutton)
dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe.png")
end
function item.DoOnEquipPanel(dimagebutton)
print("called with panel:",panel)
dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe_eq.png")
end
--Required, the shape of this item.
item.Shape = {
{true,true,true},
{false,true},
{false,true},
}
--Optional, If this item can be equiped in any player slots, put them here.
item.Equipable = "Right Hand"
local swingdata = {
["fwd"] = {
{0.007,Vector(-27,1,9)},
{0.014,Vector(-20,3,16)},
{0.020,Vector(-11,6,22)},
{0.027,Vector(0,7,26)},
{0.032,Vector(15,7,25)},
{0.039,Vector(28,6,21)},
{0.045,Vector(38,4,14)},
{0.052,Vector(46,0,3)},
{0.059,Vector(50,-3,-6)},
{0.065,Vector(52,-6,-15)},
{0.072,Vector(52,-8,-22)},
{0.078,Vector(51,-10,-28)},
{0.084,Vector(50,-11,-31)},
{0.091,Vector(50,-11,-32)},
{0.097,Vector(50,-11,-32)}
},
["lft"] = {
{0.007,Vector(-6,24,2)},
{0.014,Vector(-1,26,2)},
{0.020,Vector(5,28,1)},
{0.027,Vector(12,28,-1)},
{0.035,Vector(19,27,-4)},
{0.042,Vector(27,24,-7)},
{0.048,Vector(37,17,-13)},
{0.055,Vector(42,12,-17)},
{0.061,Vector(45,5,-20)},
{0.068,Vector(48,-2,-23)},
{0.075,Vector(49,-8,-25)},
{0.084,Vector(49,-14,-26)},
{0.091,Vector(49,-19,-27)},
{0.097,Vector(48,-22,-27)},
{0.104,Vector(48,-25,-27)},
{0.110,Vector(48,-26,-27)},
{0.117,Vector(48,-27,-27)},
{0.123,Vector(48,-26,-27)},
{0.131,Vector(48,-26,-27)}
},
["rig"] = {
{0.009,Vector(-3,25,2)},
{0.017,Vector(3,27,1)},
{0.025,Vector(11,28,-1)},
{0.032,Vector(20,27,-4)},
{0.040,Vector(28,24,-7)},
{0.051,Vector(36,19,-12)},
{0.059,Vector(42,11,-17)},
{0.067,Vector(47,2,-22)},
{0.075,Vector(49,-5,-25)},
{0.083,Vector(49,-13,-27)},
{0.090,Vector(49,-19,-28)},
{0.098,Vector(48,-24,-28)},
{0.106,Vector(48,-27,-28)},
{0.114,Vector(48,-28,-28)},
{0.121,Vector(48,-27,-28)},
{0.129,Vector(48,-27,-27)}
},
}
local attacks = {
forward = {
anim = "hammer_swing_up",
animtime = 2.33,
data = swingdata["fwd"],
dammage = 5
},
left = {
anim = "hammer_swing_left",
animtime = 2.33,
data = swingdata["lft"],
dammage = 5
},
right = {
anim = "hammer_swing_right",
animtime = 2.33,
data = swingdata["rig"],
dammage = 5
}
}
--Optional, what to do when the player clicks, and this item is in the slot in inventory. only works for items equipable in left and right hands
item.lastSwing = {}
item.onClick = function(self,owner)
item.lastSwing[owner] = item.lastSwing[owner] or 0
if item.lastSwing[owner] > CurTime() then return end
item.lastSwing[owner] = CurTime()+1.33
local movementtbl = {}
for k,v in pairs(attacks) do
movementtbl[k] = function()
owner:SetLuaAnimation(v.anim)
timer.Simple(v.animtime,function()
owner:StopLuaAnimation(v.anim)
end)
local times, pos = {},{}
for i,j in pairs(v.data) do
times[i] = 1 + j[1]
pos[i] = Vector(j[2])
pos[i]:Rotate(owner:GetAimVector():Angle())
end
if pos[1] == nil then return end
com.swingarc(owner,times,pos,function(tr)
if not tr.Hit then return end
if tr.Entity.Blocking ~= nil and tr.Entity.Blocking == k then
eff()
elseif tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then
tr.Entity:TakeDamage(v.dammage,owner,owner:GetActiveWeapon())
end
end)
end
end
--Empty functions for attacks not defined
for k,v in pairs({"left","right","forward","backward"}) do
if movementtbl[k] == nil then
movementtbl[k] = function() end
end
end
--Do the attack
movementtbl[com.playermovedir(owner)]()
end
--Optional, if we should do something special on equip(like draw the PAC for this weapon)
item.onEquip = function(self,who)
print("woo! i'm being used!")
if SERVER then
who:GetActiveWeapon():SetHoldType("melee2")
pac.ApplyPac(who,"scraphammer")
end
end
--Optional, if we should do something speical on unequip(like setting animations back to normal)
item.onUnEquip = function(self,who)
print("aw, I'm being put away :(")
who:GetActiveWeapon():SetHoldType("normal")
pac.RemovePac(who,"scraphammer")
end
item.onDropped = function(self, ent)
pac.ApplyPac(ent,"scraphammer")
end
print("Hello from scraphammer.lua")
--Don't forget to register the item!
reg.RegisterItem(item)
[/code]
(Excuse the print/debug statements, I just copy/pasted it in wholesale)
As you might imagine, my code is scattered through a lot of files, I often have to go hunting through 3 or 4 files every time I find a bug. Is there a reasonable way to cut down on all the crap and make this simpler? I'm pretty sure I pulled out most of the shared code between weapons, maybe I could do more though.
The other place that I spend a lot of time is writing dialog trees, here's an example of one of them for a simple fetch quest:
[code]
local goodluck = function(ply)
return {
["Name"] = "Tom the Mechanic",
["Message"] = "Thanks, now get out of here, I have work to do!",
["Options"] = {},
}
end;
local howcanihelp = function(ply)
ply:AddMapIcon("materials/art_tech.png","global",Vector( 238, -532, 243 ))
ply.Quests["Subterr_generator"] = 1
ply:SynchronizeQuest("Subterr_generator")
return {
["Name"] = "Tom the Mechanic",
["Message"] = "Bring me a replacement Toggle Chip to fix the generator.\nThe local TECHNICIAN might be able to help you, \nI'll mark his location on your map.",
["Options"] = {
["I'll be right back!"] = goodluck,
},
}
end;
local whatswrong = function(ply)
return {
["Name"] = "Tom the Mechanic",
["Message"] = "This generator is on it's last legs, and I can't figure out how to get it working again!",
["Options"] = {
["Well, good luck!"] = goodluck,
["How can I help?"] = howcanihelp
},
}
end;
local howareyou = function(ply)
return {
["Name"] = "Tom the Mechanic",
["Message"] = "D
Anybody know if it's possible to set a spawned entity on the ground? I want entities to randomly spawn across the world, but they're probably going to spawn in the air and in the ground.
[QUOTE=VeXan;51947364]Anybody know if it's possible to set a spawned entity on the ground? I want entities to randomly spawn across the world, but they're probably going to spawn in the air and in the ground.[/QUOTE]
Make a random vector, make sure its in the map the tracehull down until u hit the ground
[QUOTE=VeXan;51947364]Anybody know if it's possible to set a spawned entity on the ground? I want entities to randomly spawn across the world, but they're probably going to spawn in the air and in the ground.[/QUOTE]
DropToFloor is an entity function you might want to try.
How to calculate player position on minimap? Let's say map.png have 2048x2048 px, map.bsp have 32768x32768 units. So how I can calculate position and angle?
[QUOTE=LisyFOX;51948745]How to calculate player position on minimap? Let's say map.png have 2048x2048 px, map.bsp have 32768x32768 units. So how I can calculate position and angle?[/QUOTE]
Consider the bottom left corner of the picture to be (0, 0), meaning if the map origin was in the center, (-16384, -16384) would map to (0, 0) on the image. Since the map is 32768 units on each axis and the minimap is 2048, you'll have to divide the final position by 32768/2048 = 16. Thus, you can transfer the game's position to the image using ((x + 16384) / 16, (y + 16384) / 16).
If the center of your minimap is not (0, 0) in-game, you'll have to add an additional offset to your current 16384 offset.
[QUOTE=code_gs;51948795]Consider the bottom left corner of the picture to be (0, 0), meaning if the map origin was in the center, (-16384, -16384) would map to (0, 0) on the image. Since the map is 32768 units on each axis and the minimap is 2048, you'll have to divide the final position by 32768/2048 = 16. Thus, you can transfer the game's position to the image using ((x + 16384) / 16, (y + 16384) / 16).
If the center of your minimap is not (0, 0) in-game, you'll have to add an additional offset to your current 16384 offset.[/QUOTE]
Thanks, this code works fine! But how make map rotated, I'm tried use surface.DrawTexturedRectRotatedPoint from surface.DrawTexturedRectRotated gmod wiki, but this don't work properly.
[QUOTE=LisyFOX;51948850]Thanks, this code works fine! But how make map rotated, I'm tried use surface.DrawTexturedRectRotatedPoint from surface.DrawTexturedRectRotated gmod wiki, but this don't work properly.[/QUOTE]
Post your code.