• What do you need help with? V3
    6,419 replies, posted
can anyone give me a tutorial on meshes?
[QUOTE=fairy;39231764]Does anyone know how I can change the color of the background in a DCollapsibleCategory? I believe it's some weird color of blue by default. Is there a way to change it without making a skin?[/QUOTE] Still need help with this. Also, how can I make a player open a web URL in the Steam in-game browser?
[QUOTE=fairy;39235635]Still need help with this. Also, how can I make a player open a web URL in the Steam in-game browser?[/QUOTE] [URL="http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index2c41.html"]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index2c41.html[/URL]
-fixed it-
How can I use timer.Create() to call the function every x seconds instead of just repeating it x repetitions? If impossible with timer.Create(), what are my other options?
[QUOTE=Orgy;39238641]How can I use timer.Create() to call the function every x seconds instead of just repeating it x repetitions? If impossible with timer.Create(), what are my other options?[/QUOTE] [lua] timer.Create('something', 10, 0, function() -- will be called every 10 seconds forever end) [/lua]
[QUOTE=_Undefined;39238736][lua] timer.Create('something', 10, 0, function() -- will be called every 10 seconds forever end) [/lua][/QUOTE] Er, thanks, but I forgot to mention that I only want it to repeat every x seconds [i]for y seconds[/i] an example in php: [code] while (time() < time() + 30) { //will count for 30 seconds print "1 second\n"; sleep(1); //will now wait another second before the next repetition } [/code]
[QUOTE=Orgy;39238752]Er, thanks, but I forgot to mention that I only want it to repeat every x seconds [i]for y seconds[/i] an example in php: [code] while (time() < time() + 30) { //will count for 30 seconds print "1 second\n"; sleep(1); //will now wait another second before the next repetition } [/code][/QUOTE] [lua] timer.Create('something', 1, 30, function() -- will be called every 1 second for 30 seconds end) [/lua]
[QUOTE=Orgy;39238752]Er, thanks, but I forgot to mention that I only want it to repeat every x seconds [i]for y seconds[/i] an example in php: [code] while (time() < time() + 30) { //will count for 30 seconds print "1 second\n"; sleep(1); //will now wait another second before the next repetition } [/code][/QUOTE] I'm pretty sure that's an infinite loop. Anyways if you want a timer to run every x seconds for a total of y seconds, the number of repetitions would just be y/x.
[QUOTE=infinitywrai;39238774]I'm pretty sure that's an infinite loop. Anyways if you want a timer to run every x seconds for a total of y seconds, the number of repetitions would just be y/x.[/QUOTE] You're right, my bad. Wasn't thinking. Should set time + 30 before that as a variable and go from there. You understand, I'm sure. [editline]16th January 2013[/editline] [QUOTE=_Undefined;39238767][lua] timer.Create('something', 1, 30, function() -- will be called every 1 second for 30 seconds end) [/lua][/QUOTE] I'll try that, thanks
[QUOTE=Sharkie;39235431]How would I center this text? [lua] function GM:DonateTab() local lines = {} lines[30] = "VIP: $15" -- Requires Centering, Bold, Italic -- lines[45] = "Five E2 Chips\n" lines[60] = "$25000 Ingame Money\n" lines[75] = "Donator Jobs\n" lines[90] = "Donator Forums Rank\n" lines[105] = "Donator Entities\n" lines[120] = "Donator Cars\n" lines[135] = "Gets Access to the Beta Test Server\n" lines[200] = "E2 + Money: $6.50\n" -- Requires Centering, Bold, Italic -- lines[215] = "Four E2 Chips\n" lines[230] = "$15000 ingame Money\n" lines[245] = "Some Extra Jobs\n" local DonateTab = vgui.Create("DPanelList") DonateTab:EnableVerticalScrollbar( true ) --Snippity due to my friend would like to keep this code private dueto he writ it himself.-- [/lua] (Inb4 stop trying to make money of your servers) it's my friends he asked me to post it.[/QUOTE] Like you won't get banned anyways for meme reply. Also, that friend of yours got the dumb idea of VIP access (kiddos abusing the jobs and using dumb and/or abusive E2s to kill people). And as voted, DarkRP is not to be discussed here (because we can see that it's DarkRP obviously). [QUOTE=garry;39215754]Ban all DarkRP discussions from this forum? [img]http://www.facepunch.com/fp/ratings/tick.png[/img] or [img]http://www.facepunch.com/fp/ratings/cross.png[/img][/QUOTE] 46 [img]http://www.facepunch.com/fp/ratings/tick.png[/img]'s and 5 [img]http://www.facepunch.com/fp/ratings/cross.png[/img]'s
Is there something wrong with the connection between cl_init and SNPCs? I'm trying to make an SNPC and the cl_init isn't executing at all, i've tried purposely filled it with errors/debugging things and it doesn't even run any of it or come up with errors in the console. (All of the task and schedule crap is from experimenting to get around the broken-ness of the base ai) Init.lua [code]AddCSLuaFile("cl_init.lua") AddCSLuaFile("shared.lua") include('shared.lua') local schdRiot = ai_schedule.New("Riot Patrol") local taskRiot = ai_task.New() --Move taskRiot:InitEngine("TASK_GET_PATH_TO_RANDOM_NODE", 256) taskRiot.TaskID = 1 schdRiot.TaskCount = table.insert(schdRiot.Tasks, taskRiot) taskRiot:InitEngine("TASK_RUN_PATH",0) taskRiot.TaskID = 2 schdRiot.TaskCount = table.insert(schdRiot.Tasks, taskRiot) taskRiot:InitEngine("TASK_WAIT_FOR_MOVEMENT",0) taskRiot.TaskID = 3 schdRiot.TaskCount = table.insert(schdRiot.Tasks, taskRiot) --Find naughty people taskRiot:InitEngine("FindEnemy", {Class = "player", Radius = 2000}) taskRiot.TaskID = 4 schdRiot.TaskCount = table.insert(schdRiot.Tasks, taskRiot) taskRiot:InitEngine("TASK_GET_PATH_TO_ENEMY_LKP_LOS", 0) taskRiot.TaskID = 5 schdRiot.TaskCount = table.insert(schdRiot.Tasks, taskRiot) taskRiot:InitEngine("TASK_RUN_PATH", 0) taskRiot.TaskID = 6 schdRiot.TaskCount = table.insert(schdRiot.Tasks, taskRiot) taskRiot:InitEngine("TASK_SOUND_ANGRY", 0) taskRiot.TaskID = 7 schdRiot.TaskCount = table.insert(schdRiot.Tasks, taskRiot) taskRiot:InitEngine("TASK_WAIT_FOR_MOVEMENT", 0) taskRiot.TaskID = 8 schdRiot.TaskCount = table.insert(schdRiot.Tasks, taskRiot) --Fire at will taskRiot:InitEngine("TASK_GET_PATH_TO_ENEMY_LOS", 0) taskRiot.TaskID = 9 schdRiot.TaskCount = table.insert(schdRiot.Tasks, taskRiot) taskRiot:InitEngine("TASK_STRAFE_PATH", 0) taskRiot.TaskID = 10 schdRiot.TaskCount = table.insert(schdRiot.Tasks, taskRiot) taskRiot:InitEngine("TASK_STOP_MOVING", 0 ) taskRiot.TaskID = 11 schdRiot.TaskCount = table.insert(schdRiot.Tasks, taskRiot) taskRiot:InitEngine("TASK_FACE_ENEMY", 0 ) taskRiot.TaskID = 12 schdRiot.TaskCount = table.insert(schdRiot.Tasks, taskRiot) taskRiot:InitEngine("TASK_ANNOUNCE_ATTACK", 0 ) taskRiot.TaskID = 13 schdRiot.TaskCount = table.insert(schdRiot.Tasks, taskRiot) taskRiot:InitEngine("TASK_RANGE_ATTACK1", 0 ) taskRiot.TaskID = 14 schdRiot.TaskCount = table.insert(schdRiot.Tasks, taskRiot) taskRiot:InitEngine("TASK_RELOAD", 0 ) taskRiot.TaskID = 15 schdRiot.TaskCount = table.insert(schdRiot.Tasks, taskRiot) function ENT:Initialize() self:SetModel("models/player/ct_gign.mdl") self:SetHullType(HULL_HUMAN); self:SetHullSizeNormal(); self:SetSolid(SOLID_BBOX) self:SetMoveType(MOVETYPE_STEP) self:CapabilitiesAdd(bit.bor(CAP_MOVE_GROUND,CAP_OPEN_DOORS,CAP_TURN_HEAD,CAP_USE_SHOT_REGULATOR,CAP_AIM_GUN)) self:SetHealth(200) self:Give("weapon_rp_heavyrifle") end function ENT:OnTakeDamage( dmginfo ) return true end function ENT:SelectSchedule() self:StartSchedule(schdRiot) end[/code] shared.lua [code]ENT.Base = "base_entity" -- this has been base_gmodentity, base_ai and base_entity ENT.Type = "ai" ENT.PrintName = "Riot Police" ENT.Author = "sawukoa" ENT.Contact = "go away" ENT.Purpose = "for internal use in uRP" ENT.Instructions = "" ENT.AutomaticFrameAdvance = false function ENT:OnRemove() end function ENT:PhysicsCollide(data,physobj) end function ENT:PhysicsUpdate(physobj) end function ENT:SetAutomaticFrameAdvance(bUsingAnim) self.AutomaticFrameAdvance = bUsingAnim end[/code] cl_init.lua [code]include('shared.lua') ENT.RenderGroup = RENDERGROUP_BOTH function ENT:Initialize() print("clientside cop init") end function ENT:Draw() self:DrawModel() local Ang = self:Forward() local Pos = self:GetPos() + Vector(0,0,90) + Ang:Up() surface.SetFont("HUDNumber5") Ang:RotateAroundAxis(Ang:Forward(), 90) Ang:RotateAroundAxis(Ang:Right(), 90) local TextWidth = surface.GetTextSize("Riot Police") cam.Start3D2D(Pos + Ang, TextAng, 10) draw.WordBox(2, TextWidth * 0.5, -30, "Riot Police", "HUDNumber5", Color(0, 0, 255, 100), Color(255,255,255,255)) cam.End3D2D() end function ENT:DrawTranslucent() self:Draw() end function ENT:BuildBonePositions(NumBones, NumPhysBones) --// end function ENT:SetRagdollBones(bIn) self.m_bRagdollSetup = bIn end function ENT:DoRagdollBone(PhysBoneNum,BoneNum) --// end[/code]
Quick question, When spawning npcs with a lua script why does it look as if they fall from the sky when they are created? And is there a fix to it?
[QUOTE=Gaming_Unlim;39242533]Quick question, When spawning npcs with a lua script why does it look as if they fall from the sky when they are created? And is there a fix to it?[/QUOTE] [lua]npc:DropToFloor()[/lua]
[QUOTE=Hyper Iguana;39242680][lua]npc:DropToFloor()[/lua][/QUOTE] Thanks alot. Works like a charm.
Hey all! I have the following problem with my server: I have 1 server with the gamemode "jailbreak" but when people starting to shoot each other the server has a strange lag. Its not fps lag or what ever. For example if there are like 5 people in the server and 2 people shooting each other then the other 3 people are like moving on there on when they standing still. A friend of my said: when somebody fires a gun, there is a random chance that this will cause the server to stutter and all players will experience momentary packet loss My download speed is 43 mbps My upload speed is 3.63 mbps I have a xeon procesor dual socket 2011 and 64 GB intern memory ddr3 windows server 2008 R2 64 bit You can see it your self if you want join the server: 83.84.141.141:27016 or see it on this video [URL="http://www.youtube.com/watch?v=Cr_V0mBK4Rw"]http://www.youtube.com/watch?v=Cr_V0mBK4Rw[/URL] [IMG]http://s1.postimage.org/xi4xlptwf/Naamloos.png[/IMG]
Pretty much this [url]http://facepunch.com/showthread.php?t=1240119[/url] Ive looked at some code for gmod, but I'm not to good with lua. If anyone knows how to do this I would love to know.
If some one gets this fixed i will pay you 50 euro's on paypal. Hey all! I have the following problem with my server: I have 1 server with the gamemode "jailbreak" but when people starting to shoot each other the server has a strange lag. Its not fps lag or what ever. For example if there are like 5 people in the server and 2 people shooting each other then the other 3 people are like moving on there on when they standing still. A friend of my said: when somebody fires a gun, there is a random chance that this will cause the server to stutter and all players will experience momentary packet loss My download speed is 43 mbps My upload speed is 3.63 mbps I have a xeon procesor dual socket 2011 and 64 GB intern memory ddr3 windows server 2008 R2 64 bit You can see it your self if you want join the server: 83.84.141.141:27016 or see it on this video [URL="http://www.youtube.com/watch?v=Cr_V0mBK4Rw"]http://www.youtube.com/watch?v=Cr_V0mBK4Rw[/URL] [IMG]http://s1.postimage.org/xi4xlptwf/Naamloos.png[/IMG]
A few questions... Why is it that when TrapFire is called, regardless of what the spread or number of bullets fired is (and I've run tests on this and found that it always is set properly) always have 0 spread? Also, is there a way to increase the speed of the think hook being called? At the moment it only seems to be doing it about every 0.2 seconds (tested, not a logic error) in the entity that calls trapfire, and I have no idea why this is. Finally is there a reason the "magneto-stick" in TTT can pick up the weapon entity, but not this entity? It sort of gets picked up a little and immediately dropped after. [lua]include("shared.lua") AddCSLuaFile("shared.lua") AddCSLuaFile("cl_init.lua") ENT.Model="models/combine_helicopter/helicopter_bomb01.mdl" ENT.TrapWeaponFireDuration=2 ENT.TrapWeaponStats={weaponent="weapon_crowbar",delay=0.5,numbullets=1,spread=Vector(0.02,0.02,0),damage=1,force=2,firesound=Sound( "Weapon_M3.Single" )} --Change this when assigned the weapon function ENT:Initialize() self:SetModel(self.Model) self.Entity:PhysicsInit( SOLID_VPHYSICS ) self.Entity:SetMoveType( MOVETYPE_VPHYSICS ) self.Entity:SetSolid( SOLID_VPHYSICS ) --self.Entity:SetCollisionGroup( COLLISION_GROUP_WEAPON ) local phys = self.Entity:GetPhysicsObject() if IsValid( phys ) then phys:Wake() phys:SetVelocity( Vector( 0, 0, 0 ) ) end end ENT.LastBulletFired=0 function ENT:TrapFire() if IsValid(self) then --Maybe go BEEP if no weapon? if self.LastBulletFired+self.TrapWeaponStats.delay<CurTime() then --print(self.TrapWeaponStats.delay,self.TrapWeaponStats.numbullets) local bulletDir=vector_origin local bulletPos=vector_origin local muzzle=self:GetAttachment(self:LookupAttachment("muzzle_flash")) if muzzle then bulletDir=muzzle.Ang:Forward() bulletPos=muzzle.Pos else bulletPos=self:GetPos() bulletDir=self:GetAngles():Forward() end local bullet={} bullet.Num=self.TrapWeaponStats.numbullets bullet.Spread=self.TrapWeaponStats.spread bullet.Damage=self.TrapWeaponStats.damage bullet.Force=self.TrapWeaponStats.force bullet.Src=bulletPos bullet.Dir=bulletDir self:FireBullets(bullet) self:EmitSound(self.TrapWeaponStats.firesound) self.LastBulletFired=CurTime() --self:NextThink(CurTime()) end end end [/lua] Thanks!
Is there any documentation on the new HTML functions shipped with GM13 and further updates? (I reckon reading about some HTML -> Lua stuffs)
[QUOTE=Ylsid;39245000]A few questions... Why is it that when TrapFire is called, regardless of what the spread or number of bullets fired is (and I've run tests on this and found that it always is set properly) always have 0 spread? Also, is there a way to increase the speed of the think hook being called? At the moment it only seems to be doing it about every 0.2 seconds (tested, not a logic error) in the entity that calls trapfire, and I have no idea why this is. Finally is there a reason the "magneto-stick" in TTT can pick up the weapon entity, but not this entity? It sort of gets picked up a little and immediately dropped after. -asdfcode- Thanks![/QUOTE] Is self.TrapWeaponStats.spread a Vector?
[QUOTE=fawakabrother;39243108]Hey all! I have the following problem with my server: I have 1 server with the gamemode "jailbreak" but when people starting to shoot each other the server has a strange lag. Its not fps lag or what ever. For example if there are like 5 people in the server and 2 people shooting each other then the other 3 people are like moving on there on when they standing still. A friend of my said: when somebody fires a gun, there is a random chance that this will cause the server to stutter and all players will experience momentary packet loss My download speed is 43 mbps My upload speed is 3.63 mbps I have a xeon procesor dual socket 2011 and 64 GB intern memory ddr3 windows server 2008 R2 64 bit You can see it your self if you want join the server: 83.84.141.141:27016 or see it on this video [URL="http://www.youtube.com/watch?v=Cr_V0mBK4Rw"]http://www.youtube.com/watch?v=Cr_V0mBK4Rw[/URL] [IMG]http://s1.postimage.org/xi4xlptwf/Naamloos.png[/IMG][/QUOTE] You're not giving us enough information. We can't examine the problem with just what you've given us really.
Which DTextEntry hook is called when the value changes? OnValueChange and OnValueChanged don't seem to work for me. EDIT: OnKeyCode did what I wanted. I kind of expected OnValueChange to also be called when the user typed something in though.
[QUOTE=infinitywrai;39249426]Which DTextEntry hook is called when the value changes? OnValueChange and OnValueChanged don't seem to work for me. EDIT: OnKeyCode did what I wanted. I kind of expected OnValueChange to also be called when the user typed something in though.[/QUOTE] from: \garrysmod\lua\vgui\dtextentry.lua [lua]--[[--------------------------------------------------------- OnChange -----------------------------------------------------------]] function PANEL:OnChange() end[/lua] and [lua]--[[--------------------------------------------------------- Name: For Override -----------------------------------------------------------]] function PANEL:OnValueChange( strValue ) end[/lua]
-snip- I was being stupid, problem solved ^_^
[QUOTE=Hyper Iguana;39248648]You're not giving us enough information. We can't examine the problem with just what you've given us really.[/QUOTE] What is it you want to know more if you give me the information i give you the information you need :)
Hey guys, I have my NPC working after it gave an engine error, a workaround was posted, I applied that and now the zombie atleast runs and tries to hit people. Anyways, after a while the zombie suddenly stops moving and gets stuck in the running animation, it just freezes, then this error is spammed in console: [code][ERROR] gamemodes/base/entities/entities/base_ai/schedules.lua:119: attempt to compare nil with number 1. NextTask - gamemodes/base/entities/entities/base_ai/schedules.lua:119 2. DoSchedule - gamemodes/base/entities/entities/base_ai/schedules.lua:75 3. unknown - gamemodes/base/entities/entities/base_ai/schedules.lua:22[/code] When I remove the NPC then spawn another, it just stands there, freezed and idle, and the error keeps spamming into console. Does anybody know a fix for this? It would be very appreciated.
[QUOTE=Weapon317;39252569]Hey guys, I have my NPC working after it gave an engine error, a workaround was posted, I applied that and now the zombie atleast runs and tries to hit people. Anyways, after a while the zombie suddenly stops moving and gets stuck in the running animation, it just freezes, then this error is spammed in console: [code][ERROR] gamemodes/base/entities/entities/base_ai/schedules.lua:119: attempt to compare nil with number 1. NextTask - gamemodes/base/entities/entities/base_ai/schedules.lua:119 2. DoSchedule - gamemodes/base/entities/entities/base_ai/schedules.lua:75 3. unknown - gamemodes/base/entities/entities/base_ai/schedules.lua:22[/code] When I remove the NPC then spawn another, it just stands there, freezed and idle, and the error keeps spamming into console. Does anybody know a fix for this? It would be very appreciated.[/QUOTE] It would also help if you pasted some of your NPC code.
[QUOTE=Lerpaderp;39252649]It would also help if you pasted some of your NPC code.[/QUOTE] I have no idea what part I needed to post, so I will just paste the whole thing. sv_auto.lua: [lua] AddCSLuaFile("cl_auto.lua"); AddCSLuaFile("sh_auto.lua"); -- Called when the entity is spawned. function ENT:SpawnFunction(player, trace) if (!trace.Hit) then return; end; local spawnPos = trace.HitPos + trace.HitNormal * 20; local entity = ents.Create("bb_basezombie"); entity:SetModel("models/zombie/classic.mdl"); entity:SetPos(spawnPos) entity:Spawn(); entity:Activate(); return entity; end; -- Called when the entity has initialized. function ENT:Initialize() self:SetHullType(HULL_HUMAN); self:SetHullSizeNormal(); self:SetSolid(SOLID_BBOX); self:SetMoveType(MOVETYPE_STEP); self:CapabilitiesAdd(bit.bor(CAP_MOVE_GROUND, CAP_ANIMATEDFACE, CAP_TURN_HEAD, CAP_USE_SHOT_REGULATOR, CAP_AIM_GUN)); self:SetMaxYawSpeed(5000); self:SetHealth( math.random(60, 120) ); end; -- A function to emit a voice sound. function ENT:VoiceSound(sound, volume) self:EmitSound( sound, Vector(0,0,0), volume or 75, math.random(75, 100) ); end; -- Called when the entity's death should be done. function ENT:DoDeath() local chance = math.random(1, 50); local randomItems = { "Apple", "Melon", "Anti-Viral", "Antibiotics", "Beans", "Weed", "Human Meat", "Steak", "Egg", "Beer", "Water", "Bandage", "Bacon", "Human Meat", "Painkillers", "Sprunk", "Milk Jug", "Chicken Stick", "Hotdog", "Human Meat", "Orange Juice", "Apple Juice", "empty_plasbottle", "human_skull", "empty_wine", "Human Meat" }; if (!self.IsDead) then self.IsDead = true; self:VoiceSound( table.Random(self.DeathSounds) ); self.DamageForce = BLACKBOX:ConvertForce(self.DamageForce * 192); if (chance >= 48) then blackbox.entity.CreateItem( nil, (table.Random(randomItems)), self:GetPos() + Vector(0, 0, 8) ); else -- Nothing end; local ragdoll = blackbox.entity.MakeIntoRagdoll( self, nil, (self:GetVelocity() * 1.5) + self.DamageForce, self:GetAngles() - Angle(0, -45, 0) ); if ( IsValid(ragdoll) ) then ragdoll:SetCollisionGroup(COLLISION_GROUP_WEAPON); blackbox.entity.Decay(ragdoll, 15); self:Remove(); end; end; end; -- Called when the entity takes damage. function ENT:OnTakeDamage(damageInfo) local damagePosition = damageInfo:GetDamagePosition(); local damageAmount = damageInfo:GetDamage(); local damageForce = damageInfo:GetDamageForce(); self:SetHealth( math.max(self:Health() - damageAmount, 1) ); if (self:Health() > 1) then self:VoiceSound( table.Random(self.PainSounds) ); else self.DamageForce = damageForce; end; -- BLACKBOX:CreateBloodEffects(damagePosition, 1, self, damageForce); end; -- Called each frame. function ENT:Think() local curTime = CurTime(); if (!self.NextDropToFloor) then self.NextDropToFloor = curTime + 1; else self:DropToFloor(); self.NextDropToFloor = nil; end; if (!self.NextTauntTime) then self.NextTauntTime = curTime + math.random(16, 32); elseif (curTime >= self.NextTauntTime) then self:VoiceSound( table.Random(self.TauntSounds) ); self.NextTauntTime = nil; end; if ( self.DamageForce and IsValid(self) ) then self:DoDeath(); end; if (!self.NextRunSound) then self.NextRunSound = curTime + math.random(0.1, 0.2); if (!self.NextRunFoot or self.NextRunFoot == 0) then self.NextRunFoot = 1; else self.NextRunFoot = 0; end; elseif (curTime >= self.NextRunSound) then if ( self:GetSequence() == self:LookupSequence("run_all") and self:IsOnGround() ) then if (self.NextRunFoot == 0) then local randomSounds = {1, 3, 5}; local randomNumber = math.random(1, 3); self:VoiceSound( "npc/metropolice/gear"..randomSounds[randomNumber]..".wav", math.random(50, 75) ); else local randomSounds = {2, 4, 6}; local randomNumber = math.random(1, 3); self:VoiceSound( "npc/metropolice/gear"..randomSounds[randomNumber]..".wav", math.random(50, 75) ); end; self.NextRunSound = nil; end; end; end; -- Called when a sequence should be played. function ENT:TaskStart_PlaySequence(data) local sequenceID = data.ID; local curTime = CurTime(); if (data.Name) then sequenceID = self:LookupSequence(data.Name); end; self:ResetSequence(sequenceID); self:SetNPCState(NPC_STATE_SCRIPT); local duration = self:SequenceDuration(); if (data.Speed and data.Speed > 0) then self:SetPlaybackRate(data.Speed); duration = duration / data.Speed; end; self.TaskSequenceEnd = curTime + duration; end; -- A function to set the last enemy. function ENT:SetLastEnemy(enemy) self.LastEnemy = enemy; end; -- A function to get the last enemy. function ENT:GetLastEnemy() return self.LastEnemy; end; -- Called when an enemy is needed. function ENT:TaskStart_FindEnemy(data) local position = self:GetPos(); local closest = nil; for k, v in ipairs( g_Player.GetAll() ) do local playerPosition = v:GetPos(); local distance = playerPosition:Distance(position); if (v:Alive() and ( self:Visible(v) or v:Visible(self) ) and v:GetMoveType() != MOVETYPE_NOCLIP) then if ( !closest or distance < closest[2] ) then closest = {v, distance}; end; end; end; for k, v in ipairs( ents.FindInSphere(position, 1024) ) do if ( v:GetClass() == "bb_flare" and ( self:Visible(v) or v:Visible(self) ) ) then local flarePosition = v:GetPos(); local distance = flarePosition:Distance(position); if ( !closest or distance < closest[2] or closest[1]:IsPlayer() ) then closest = {v, distance}; end; end; end; if (closest) then self:SetEnemy( closest[1] ); self:SetLastEnemy( closest[1] ); self:UpdateEnemyMemory( closest[1], closest[1]:GetPos() ); else self:SetEnemy(NULL); self:SetLastEnemy(NULL); end; self:TaskComplete(); end; -- Called when a sequence is playing. function ENT:Task_PlaySequence(data) local curTime = CurTime(); if (curTime < self.TaskSequenceEnd) then return; end; self:TaskComplete(); self:SetNPCState(NPC_STATE_NONE); self.TaskSequenceEnd = nil; end; local sharedtasks_e = { } sharedtasks_e["TASK_INVALID"] = 0 sharedtasks_e["TASK_RESET_ACTIVITY"] = 1 sharedtasks_e["TASK_WAIT"] = 2 sharedtasks_e["TASK_ANNOUNCE_ATTACK"] = 3 sharedtasks_e["TASK_WAIT_FACE_ENEMY"] = 4 sharedtasks_e["TASK_WAIT_FACE_ENEMY_RANDOM"] = 5 sharedtasks_e["TASK_WAIT_PVS"] = 6 sharedtasks_e["TASK_SUGGEST_STATE"] = 7 sharedtasks_e["TASK_TARGET_PLAYER"] = 8 sharedtasks_e["TASK_SCRIPT_WALK_TO_TARGET"] = 9 sharedtasks_e["TASK_SCRIPT_RUN_TO_TARGET"] = 10 sharedtasks_e["TASK_SCRIPT_CUSTOM_MOVE_TO_TARGET"] = 11 sharedtasks_e["TASK_MOVE_TO_TARGET_RANGE"] = 12 sharedtasks_e["TASK_MOVE_TO_GOAL_RANGE"] = 13 sharedtasks_e["TASK_MOVE_AWAY_PATH"] = 14 sharedtasks_e["TASK_GET_PATH_AWAY_FROM_BEST_SOUND"] = 15 sharedtasks_e["TASK_SET_GOAL"] = 16 sharedtasks_e["TASK_GET_PATH_TO_GOAL"] = 17 sharedtasks_e["TASK_GET_PATH_TO_ENEMY"] = 18 sharedtasks_e["TASK_GET_PATH_TO_ENEMY_LKP"] = 19 sharedtasks_e["TASK_GET_CHASE_PATH_TO_ENEMY"] = 20 sharedtasks_e["TASK_GET_PATH_TO_ENEMY_LKP_LOS"] = 21 sharedtasks_e["TASK_GET_PATH_TO_ENEMY_CORPSE"] = 22 sharedtasks_e["TASK_GET_PATH_TO_PLAYER"] = 23 sharedtasks_e["TASK_GET_PATH_TO_ENEMY_LOS"] = 24 sharedtasks_e["TASK_GET_FLANK_RADIUS_PATH_TO_ENEMY_LOS"] = 25 sharedtasks_e["TASK_GET_FLANK_ARC_PATH_TO_ENEMY_LOS"] = 26 sharedtasks_e["TASK_GET_PATH_TO_RANGE_ENEMY_LKP_LOS"] = 27 sharedtasks_e["TASK_GET_PATH_TO_TARGET"] = 28 sharedtasks_e["TASK_GET_PATH_TO_TARGET_WEAPON"] = 29 sharedtasks_e["TASK_CREATE_PENDING_WEAPON"] = 30 sharedtasks_e["TASK_GET_PATH_TO_HINTNODE"] = 31 sharedtasks_e["TASK_STORE_LASTPOSITION"] = 32 sharedtasks_e["TASK_CLEAR_LASTPOSITION"] = 33 sharedtasks_e["TASK_STORE_POSITI
Just a quick general question, how do you optimize? Like what do you look out for. I want to code a gamemode but in the most efficient way possible.
Sorry, you need to Log In to post a reply to this thread.