• What do you need help with V4
    639 replies, posted
[QUOTE=Sorlag;35828466]Egoistically bumping this in order to make people notice it [B]inb4 ban[/B][/QUOTE] in the shared file in the first 10 - 20 lines there will be a function called "DeriveGamemode". Change the argument from "base" to sandbox
[QUOTE=James xX;35836186]in the shared file in the first 10 - 20 lines there will be a function called "DeriveGamemode". Change the argument from "base" to sandbox[/QUOTE] Now I feel stupid for not noticing that hahaha! Amazing, thanks a lot! [B]EDIT:[/B] Hm, how do you change the reload time and/or add a reload delay for a SWEP without animation? The swep creates an effect on function SWEP:Reload() but since there is no delay it spams the effect and it becomes laggy.
How would I colorize the viewmodel of a SWEP? I'm the developer of Metastrike and I want a visual effect for when your weapon is "overheated" with the Overheating Guns mod.
[lua] MERCHANT_ATTACK = ai_schedule.New("Merchant_Attack") MERCHANT_ATTACK:EngTask( "TASK_STOP_MOVING",0 ) MERCHANT_ATTACK:EngTask( "TASK_FACE_ENEMY",0 ) MERCHANT_ATTACK:EngTask( "TASK_RANGE_ATTACK1",0 ) MERCHANT_ATTACK:EngTask( "TASK_ANNOUNCE_ATTACK",0 ) MERCHANT_ATTACK:EngTask( "TASK_RELOAD",0 ) [/lua] For some reason the game Crashes because of "TASK_RANGE_ATTACK1" i have no idea why, is it a bug? or is there a workaround?
[QUOTE=silenced deat;35577962]So i am trying to fix up base wars but there is a problem, everytime i goto use the drug refinery, gun factory or any of those i get [LmaoLlamaBaseWars\gamemode\physables.lua:178] attempt to call method 'CanRefine' (a nil value) error. [lua] function ccSetRefineryMode( ply, cmd, args ) if (args[1]==nil || args[2] == nil) then return end mode = tostring(args[2]) if !ValidEntity(ents.GetByIndex(args[1])) || (mode!="money" && mode!="offense" && mode!="defense" && mode!="weapmod" && mode!="eject" && mode!="uber") then return end local vault = ents.GetByIndex(args[1]) if (vault:GetClass()!="drugfactory" || ply:GetPos():Distance(vault:GetPos())>300) then return end local ref = vault:CanRefine(mode,ply) if (ref==true) then vault:SetMode(mode) else Notify(ply,4,3,ref) end umsg.Start( "killdrugfactorygui", ply ); umsg.Short( args[1] ) umsg.End() end concommand.Add( "setrefinerymode", ccSetRefineryMode ); [/lua] That is the code.[/QUOTE]Because the one you downloaded from dramaunlimited was the one that i never finished. It would take less time to rescript the entire gamemode. Sorry to disapoint.
A while back, Garry added a set of functions that allowed you to always locate a specific entity on the map (Given that Entity() is dependant on MaxPlayers() and usually changes each game.CleanUpMap()) However, I can't find any info on the backup wiki. Can anyone remember what they were?
I'm in need of a method of making an entity move to a set of coordinates at a set speed. I've tried using ApplyForceCenter, but I can't seem to find a reliable way to move it. The speed will variate depending on the distance, and some objects will attempt to roll. I think this should be enough to describe what I need, but I'll include some other stuff in case it'll be of help. The entity should be able to be any kind of model, and there's only need for rotation around yaw(? left and right, not up and down or doing a roll). I've tried using constraint.Keepupright, but I can't get this to work. I've got no need for the speed to scale (f.ex. a smooth start, or slow end). edit: My main problem with applyforcecenter is that I found no clean way to set the speed, and there was really unnecessary ground friction. Something like the Hammer movelinear (I think it was) would be quite ideal. I need no collision, though it'd be nice if one could reduce the speed for a while, and then set the speed up again.
[QUOTE=Warsheep;35867116]I'm in need of a method of making an entity move to a set of coordinates at a set speed. I've tried using ApplyForceCenter, but I can't seem to find a reliable way to move it. The speed will variate depending on the distance, and some objects will attempt to roll. I think this should be enough to describe what I need, but I'll include some other stuff in case it'll be of help. The entity should be able to be any kind of model, and there's only need for rotation around yaw(? left and right, not up and down or doing a roll). I've tried using constraint.Keepupright, but I can't get this to work. I've got no need for the speed to scale (f.ex. a smooth start, or slow end). edit: My main problem with applyforcecenter is that I found no clean way to set the speed, and there was really unnecessary ground friction. Something like the Hammer movelinear (I think it was) would be quite ideal. I need no collision, though it'd be nice if one could reduce the speed for a while, and then set the speed up again.[/QUOTE] Disable gravity on the physics object, set it's position to x units above the ground then set it's velocity instead of applying force. Have a timer to check when it's near it's destination and stop it or simply lerp it from one point to the other, from the sound of things you should probably lerp it. and now for some untested written in browser code: [lua] function lerpObject(obj, objDest, objStart, timeToDest, lerpStartTime) if obj and ValidEntity(obj) then if !objDest then return end if !objStart then objStart = obj:GetPos() + Vector(0,0,10) end if !timeToDest then timeToDest = 2 end if !lerpStartTime then lerpStartTime = CurTime() end local lerpDelta = CurTime() - lerpStartTime lerpPerc = math.Clamp(lerpDelta / timeToDest, 0, 1) local objPhys = obj:GetPhysicsObject() if objPhys and objPhys:IsValid() then if lerpPerc < 1 then objPhys:EnableGravity(false) else objPhys:EnableGravity(true) end end obj:SetPos(LerpVector(lerpPerc, objStart, objDest)) if lerpPerc < 1 then timer.Simple(0.1, lerpObject, obj, objDest, objStart, timeToDest, lerpStartTime) end end end [/lua] the idea is that because it loops with a timer you run this on multiple things at a time and each will finish after x time, usage: lerpObject(myProp, Vector(234,1234,3432), , 2) -- that should move the myProp ent to vector(234,1234, 3432) over 2 seconds time hope that works and hope that helps, i'll test/ clean it later if it doesn't work and repost it. [editline] edited: [/editline] So just realized that's gonna be jerky only running once every tenth of a second, you can play with the setting till it looks good or you can even add some velocity to the object so it will reach the next point on it's own before the next iteration of the function runs.
[QUOTE=Fantym420;35867690]Disable gravity on the physics object, set it's position to x units above the ground then set it's velocity instead of applying force. Have a timer to check when it's near it's destination and stop it or simply lerp it from one point to the other, from the sound of things you should probably lerp it. and now for some untested written in browser code: [lua] function lerpObject(obj, objDest, objStart, timeToDest, lerpStartTime) if obj and ValidEntity(obj) then if !objDest then return end if !objStart then objStart = obj:GetPos() + Vector(0,0,10) end if !timeToDest then timeToDest = 2 end if !lerpStartTime then lerpStartTime = CurTime() end local lerpDelta = CurTime() - lerpStartTime lerpPerc = math.Clamp(lerpDelta / timeToDest, 0, 1) local objPhys = obj:GetPhysicsObject() if objPhys and objPhys:IsValid() then if lerpPerc < 1 then objPhys:EnableGravity(false) else objPhys:EnableGravity(true) end end obj:SetPos(LerpVector(lerpPerc, objStart, objDest)) if lerpPerc < 1 then timer.Simple(0.1, lerpObject, obj, objDest, objStart, timeToDest, lerpStartTime) end end end [/lua] the idea is that because it loops with a timer you run this on multiple things at a time and each will finish after x time, usage: lerpObject(myProp, Vector(234,1234,3432), , 2) -- that should move the myProp ent to vector(234,1234, 3432) over 2 seconds time hope that works and hope that helps, i'll test/ clean it later if it doesn't work and repost it.[/QUOTE] That seems really nice, thanks! :D I'll be heading to bed but I'll read over and implement it tomorrow. I think I got a good idea of how it works so I should be able to fix it myself should there be any issues. Again, thanks! :)
I'm not really sure on File.Read as I've not really used it. However just now I have this: [lua] local SpecialGuys = { {steamid = "STEAM_0:0:22688997", team = 1, vip = 3}, {steamid = "BOT", team = 1, vip = 3}, {steamid = "STEAM_0:1:16970247", team = 9, vip = 3}, } [/lua] I'm wanting to change that from a Variable to being stored in a TXT file so I can run a function to read from that file and update the settings. I've gotten this so far and got stuck since I need team=9 etc. [lua] local function getAdmins() if !file.Exists("admins.txt") then return {} end return string.Explode(";;", file.Read("tagthinger/admins.txt")) end [/lua] I'm not sure what to do here.
You could always do [lua] local myTable={"hi","hello"} file.Write("mytable.txt",glon.encode(myTable) ) local table2=glon.decode(file.Read("mytable.txt")) PrintTable(table2)[/lua] [code]Output: hi hello [/code]
[QUOTE=ArmageddonScr;35868168]You could always do [lua] local myTable={"hi","hello"} file.Write("mytable.txt",glon.encode(myTable) ) local table2=glon.decode(file.Read("mytable.txt")) PrintTable(table2) [/lua][/QUOTE] I still don't understand from that how you would store this {steamid = "STEAM_0:1:16970247", team = 9, vip = 3} in each one of the txt files. Isn't what you posted doing pretty much the same as mine?
[QUOTE=Mrkrabz;35868801]I still don't understand from that how you would store this {steamid = "STEAM_0:1:16970247", team = 9, vip = 3} in each one of the txt files. Isn't what you posted doing pretty much the same as mine?[/QUOTE] Not the same at all. Full article on GLON: [URL]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexd93c.html?title=Glon&oldid=51465[/URL] By encoding things, it means you can write objects to a file and read in objects from a file much easier, without having to parse things yourself. It also makes your objects "human readable". (Good reference: [URL]http://en.wikipedia.org/wiki/JSON[/URL]) A nice example with a JSON API: [URL]http://api.tumblr.com/v2/blog/david.tumblr.com/info?api_key=PyezS3Q4Smivb24d9SzZGYSuhMNPQUhMsVetMC9ksuGPkK1BTt[/URL] If you bring that output into python or whatever language and use a JSON decoder on it, you'll get a series of objects ready to use. Makes things tons easier.
[QUOTE=wizardsbane;35868942]Not the same at all. Full article on GLON: [URL]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexd93c.html?title=Glon&oldid=51465[/URL] By encoding things, it means you can write objects to a file and read in objects from a file much easier, without having to parse things yourself. It also makes your objects "human readable". (Good reference: [URL]http://en.wikipedia.org/wiki/JSON[/URL]) A nice example with a JSON API: [URL]http://api.tumblr.com/v2/blog/david.tumblr.com/info?api_key=PyezS3Q4Smivb24d9SzZGYSuhMNPQUhMsVetMC9ksuGPkK1BTt[/URL] If you bring that output into python or whatever language and use a JSON decoder on it, you'll get a series of objects ready to use. Makes things tons easier.[/QUOTE] Could I get an example of how I would use that in this situation? I vaguely understand it.
You setup your table, encode it and write to a file with that data And then you then decode it along with file.Read, modify your new table and then re-encode it to a file.
[QUOTE=ArmageddonScr;35869423]You setup your table, encode it and write to a file with that data And then you then decode it along with file.Read, modify your new table and then re-encode it to a file.[/QUOTE] Well what I was preferring to do was Manually edit a TXT file and have a function read from the txt file (into my original function).
1. file.Write( blah, util.TableToKeyValues(your table) ); 2. file.Read(blah); 3. util.KeyValuesToTable(file text)
How should I tell the client to draw an effect, f.ex. an entity shooting? Send the event in an usermessage to the client? I'm just wondering because then it seems like I might want to do some syncing stuff. edit: Also, on the server: [code] umsg.Start(self.Entity:EntIndex() .. PERIODIC, self.Entity:GetOwner()) umsg.Long = tonumber(self.target:EntIndex()) umsg.Long = self.Energy umsg.Long = math.random(1, 10) umsg.End() [/code] and on the client, inside ENT:Initialize (so I can get the entindex) [code] usermessage.Hook(tostring(self.Entity:EntIndex()) .. PERIODIC, function(data) self.Target = data:ReadLong() self.Energy = data:ReadLong() self.Kills = data:ReadLong() print("\nRecieved: ",tostring(self.Target), tostring(self.Energy), tostring(self.Kills)) end) [/code] But it doesn't seem like any code is sent. The recieved part prints, but with nil's and 0's. Basically it seems to be sending empty data. The reason I've put this inside of initialize on the client is to be able to use "self.". I didn't manage to find a way to call a function such as ENT:Periodic(data), with variations of ENT. and including self as a parameter. My goal is to sync some data between the server side and the client side of an entity.
Might as well try my luck here. Posted in questions but no answer yet. Only been two days but I'm kind of impatient :v: [lua] for KeyIcon, Model in pairs (ModelList) do local Icon = vgui.Create( "Spawnicon" ) Icon:SetModel( Model ) Icon:SetToolTip ("Spawn this!") Icon.DoClick = function() print(Model) RunConsoleCommand( "gm_spawn", Model ) end Icon.OnCursorEntered = function() Hover[Icon] = true end Icon.OnCursorExited = function() Hover[Icon] = false end Icon.Paint = function() if Hover[Icon] == true then draw.RoundedBox( 8, 0, 0, 64, 64, Color( 100, 0, 0, 200 ) ) else draw.RoundedBox( 8, 0, 0, 64, 64, Color( 0, 0, 0, 200 ) ) end end DermaList:AddItem( Icon ) end [/lua] Icon.OnCursorExited and Entered both work fine. So does Icon.Paint. What doesn't work however is DoClick. Nothing happens when I press the icons (no errors either), Yet they get colored red when hovered perfectly fine and if I change the tooltip to "model" it'll display the appropriate model path. DoClick simply Isn't working. If I were to create all the icons individually instead of a loop it'd work which doesn't make sense to me. What am I missing here?
[QUOTE=kp3;35970044]Might as well try my luck here. Posted in questions but no answer yet. Only been two days but I'm kind of impatient :v: [lua] for KeyIcon, Model in pairs (ModelList) do local Icon = vgui.Create( "Spawnicon" ) Icon:SetModel( Model ) Icon:SetToolTip ("Spawn this!") Icon.DoClick = function() print(Model) RunConsoleCommand( "gm_spawn", Model ) end Icon.OnCursorEntered = function() Hover[Icon] = true end Icon.OnCursorExited = function() Hover[Icon] = false end Icon.Paint = function() if Hover[Icon] == true then draw.RoundedBox( 8, 0, 0, 64, 64, Color( 100, 0, 0, 200 ) ) else draw.RoundedBox( 8, 0, 0, 64, 64, Color( 0, 0, 0, 200 ) ) end end DermaList:AddItem( Icon ) end [/lua] Icon.OnCursorExited and Entered both work fine. So does Icon.Paint. What doesn't work however is DoClick. Nothing happens when I press the icons (no errors either), Yet they get colored red when hovered perfectly fine and if I change the tooltip to "model" it'll display the appropriate model path. DoClick simply Isn't working. If I were to create all the icons individually instead of a loop it'd work which doesn't make sense to me. What am I missing here?[/QUOTE] Show your ModelList table Edit: change RunConsoleCommand( "gm_spawn", Model ) to LocalPlayer():ConCommand("gm_spawn "..Model)
[QUOTE=brandonj4;35970308]Show your ModelList table Edit: change RunConsoleCommand( "gm_spawn", Model ) to LocalPlayer():ConCommand("gm_spawn "..Model)[/QUOTE] ModelList is basically {"path/to/model.bla", "path/to/model2.bla", "path/to/model3.bla"} etc. I'll try doing what you said but the fact that I'm not getting the printed message either makes me believe it wont change anything. I'll edit in a minute. [editline]Edit:[/editline] Didn't work :/ For some reason whatever i put inside DoClick never seems to happen but it's weird as i know DoClick work on spawn-models as I tested it and the other Paint and OnCursorEntered both work inside the loop. This would normally make me believe it's a syntax error or something but I copy and pasted the exact line from already working code so there is no error of that kind. Something in the loop makes DoClick not work properly.
I made a function which should allow me to set model of a player depending on his team: [lua] function AddTeam(ID, Name, Model, Loadout, Salary, Color) table.insert(Teams, {ID = ID, Name = Name, Model = Model, Loadout = Loadout, Salary = Salary, Color = Color}) end [/lua] And to return the model I've tried a lot, but never got it working: [lua] function GM:PlayerSetModel(pl) pl:SetModel(Teams[(pl:Team().Model)]) end [/lua] This thing gives me [gamemodes\Testing\gamemode\server\player.lua:3] attempt to index a number value(Hook: PlayerSetModel)
pl:Team( ) returns the number index of their team, not the table.
[QUOTE=Kogitsune;35971240]pl:Team( ) returns the number index of their team, not the table.[/QUOTE] Im realy confused, lol.
[QUOTE=thejjokerr;35971604]change [lua]pl:SetModel(Teams[(pl:Team().Model)])[/lua] to [lua]pl:SetModel(Teams[pl:Team()].Model)[/lua][/QUOTE] Ah, thank you. [editline]16th May 2012[/editline] Okay, one more question. If the Loadout is a table, how would I go about giving the person all the weapons from there? This is to give a single weapon [lua]pl:Give(Teams[pl:Team()].Loadout)[/lua] - I'm pretty sure that it's a loop, tho I'm bad at thinking.
[lua] for k, v in pairs(Teams[pl:Team()].Loadout) do ply:Give(v) end [/lua] EDIT: Didn't tab, written in browser. Also look at dat postcount. [editline]15th May 2012[/editline] Is using PData all the time less efficient than assigning ply.Variable = ply:GetPData("Variable") at the beginning and then setting the PData on DC?
Ah, I'm stupid. Why didn't I think about that. Appreciate a lot!
I've seen other people do all kinds of "spawn-list" looking things, Even inventories should be done in some kind of loop. How are other people doing it since my way isn't working?
After trying it, it says that the table isn't there [code][@gamemodes\test\gamemode\server\player.lua:9] bad argument #1 to 'pairs' (table expected, got nil)(Hook: PlayerLoadout) [/code]
Can you do [lua] function MyConCommand(ply, _, args) blah end concommand.Add("blah", MyConCommand) [/lua] as in set cmd to _, in the style of setting k to _ in a for loop. 1k posts.
Sorry, you need to Log In to post a reply to this thread.