[QUOTE=man with hat;46964073]I don't think you understand how nextbot works in gmod.[/QUOTE]
No, I don't. Not at all. Regardless, wouldn't checking for true still be redundant?
[QUOTE=WalkingZombie;46964079]No, I don't. Not at all. Regardless, wouldn't checking for true still be redundant?[/QUOTE]
No.
Post note, I really do need to learn how to script / program / write / whatever you want to call it, my own NPC's. (I typically refer to it as programming)
[QUOTE=WalkingZombie;46964089]Post note, I really do need to learn how to script / program / write / whatever you call it, my own NPC's.[/QUOTE]
Then you probably shouldn't be acting as if you know.
[QUOTE=ROFLBURGER;46963539]I really don't expect anyone too look at almost 300 lines of code but it's worth a shot posting
[url]http://pastebin.com/6PfWJN2a[/url]
This is my attempted at a nextbot. I always crash when the bot kills me, it leaves no errors. I suspect it's something to do with the while loops (this is the first time ever using them) so if someone can figure out whats making me crash it would be greatly appreciated[/QUOTE]
If I recall correctly, back when I was working with nextbots, they would crash if they were unable to find a path to the player and did not have any sort of delay when searching for one. Although I cannot specifically recall if this reason is correct, you're more than welcome to tear apart my Cat NPCs and check there.
[QUOTE=man with hat;46964097]Then you probably shouldn't be acting as if you know.[/QUOTE]
correct. I mostly just wanted to comment about the amount of lines, and felt like I should try to help out since I am posting... I tried... well anyway, my biggest fear for making SNPC's is creating the inteligence, the actual AI. I want to create intelligent AI, but I'm not even great at counter strike, or even call of duty, so how would I know what an intelligent soldier would do?
[QUOTE=WalkingZombie;46964040]300 lines is nothing, I've got some scripts that are nearing 2000 lines, but every bit of code has a purpose.
Lol, what is the point, line 169, "while true do"? That basically means, if this is running, then run it. It's redundant.
212: if ( !path:IsValid() ) then return "failed" end
214: while ( path:IsValid() ) do
261: if ( !path:IsValid() ) then return "failed" end
263: while ( path:IsValid() ) do
This is interesting to me. Is it necessary to return if the path is not valid? If the path isn't valid, then the while loop wouldn't run it. Maybe you want the while loop to continue running, only skipping the false paths? In which case, "continue" can do the job, I do believe, but the while loop will continue to continue indefinitely.[/QUOTE]
Most of that code was copy/pasted from the [URL="http://wiki.garrysmod.com/page/NextBot_NPC_Creation"]Nextbot Creation Tutorial[/URL] and the nextbot base. I also modified it so it works with my bot but I have no clue how while loops work and would like some help on it.
[QUOTE=Jeezy;46964101]If I recall correctly, back when I was working with nextbots, they would crash if they were unable to find a path to the player and did not have any sort of delay when searching for one. Although I cannot specifically recall if this reason is correct, you're more than welcome to tear apart my Cat NPCs and check there.[/QUOTE]
Yeah what I'm thinking is that it has something to do with no delay or something, but I don't know how while loops work and how to end them properly.
A few things... ents.FindIn* functions are VERY SLOW. I got rid of ents.FindInCone in one of my scripts and gained close to 100% fps ( I used it for the local player to determine if a vehicle was in the cone ); you're using it per nextbot which would be VERY slow!
You shouldn't need while true in RunBehavior, that may be causing the server some issues? I'm not as up to speed on NextBots as I'd like to be, but isn't RunBehavior called when it is needed / use coroutines? All of your other while loops use a yield function...
I need help with a certain thing, basically I want it just as the player is about to die instead of dying enable godmode then disable godmode after a certain function is called that kills the player.
Currently I do not know how to do this as doing the code in DoPlayerDeath doesn't seem to work
acecool no offense but when you post solutions I legitimately do not understand a single thing you're saying
for the record I have absolutely no clue what a coroutines are and this is my first time using while loops
I found out what the problem was, it wasn't setting the self.CurrentEnemy to nil fast enough because it was basically on a 1 second tick when it needed to be on the same tickrate as the while loops
[QUOTE=ROFLBURGER;46964198]Most of that code was copy/pasted from the [URL="http://wiki.garrysmod.com/page/NextBot_NPC_Creation"]Nextbot Creation Tutorial[/URL] and the nextbot base. I also modified it so it works with my bot but I have no clue how while loops work and would like some help on it.
Yeah what I'm thinking is that it has something to do with no delay or something, but I don't know how while loops work and how to end them properly.[/QUOTE]
while (condition now) do (response) end
I believe you can also do repeat (code) until (condition)
[QUOTE=ForrestMarkX;46964467]I need help with a certain thing, basically I want it just as the player is about to die instead of dying enable godmode then disable godmode after a certain function is called that kills the player.
Currently I do not know how to do this as doing the code in DoPlayerDeath doesn't seem to work[/QUOTE]
I can't really picture how or why you need something like that, but using [URL="http://wiki.garrysmod.com/page/GM/EntityTakeDamage"]GM:EntityTakeDamage[/URL] seems to work fine:
[CODE]
-- Serverside file
hook.Add( "EntityTakeDamage", "PreventPlayerDeath", function( ent, dmgInfo )
if ( IsValid( ent ) and ent:IsPlayer() ) then -- make sure it's actually a player first
if ( ent:Health() - dmgInfo:GetDamage() <= 0 ) then -- if the damage they'd receive would kill them
dmgInfo:SetDamage( 0 ) -- prevents any further damage
hook.Run( "PrePlayerDeath", ent )
end
end
end )
hook.Add( "PrePlayerDeath", "PreDeathCheck", function( ply )
-- run whatever you're trying to do with the player
ply:Kill()
end )
[/CODE]
I hope this helps.
[quote]but I have no clue how while loops work and would like some help on it.[/quote]
[quote]while (condition now) do (response) end
I believe you can also do repeat (code) until (condition)[/quote]
They may look the same on the surface ( do something until a condition is met ), they are slightly different - a while loop that fails the condition will not run since it tests the condition first, but a repeat loop will always run since the condition is tested after. Repeat also runs until the condition is true, and while runs until the condition is false.
If you want to skip a single pass of the loop for some reason, such as x being divisible by 13, you would use the keyword continue:
[code]
while some condition do
x = x + 1
if x % 13 == 0 then
continue
end
...
end[/code]
This works on any type of normal loop - for, while, repeat.
If you want to eject from the loop because you don't need to process anymore, such as x being divisible by 26, you'd use break instead, which pops you out one level:
[code]
while some condition do
x = x + 1
if x % 26 == 0 then
break
end
end[/code]
This means that a nest while will continue to run each level above that:
[code]
while x < 10 do
while y < 10 do
while z < 10 do
z = z + 1
if z % 2 == 0 then
break
end
print( x, y, z )
end
y = y + 1
end
x = x + 1
end[/code]
It would print 0-10 on x and y, but only even numbers for z.
In summary, unless you want the block to run at least once no matter what, while will cover all your needs.
How would I make the player's EyeAngles slowly return to a specific angle while allowing them to move the mouse around?
Does any of you guys know which exact fonts the "Default" and "ChatFont" ones are? Y'know, those:
[img]http://i.imgur.com/Er0UClV.png[/img]
I need to use HTML panels for some stuff, but I'd rather not have them display a different font than all the other elements. Consistency, yo.
[QUOTE=10853;46964810]Does any of you guys know which exact fonts the "Default" and "ChatFont" ones are?[/QUOTE]
I believe the font used for at least "Default" is Tahoma. I'm looking at it in HUDPaint right now and it looks exactly the same. Probably the same for ChatFont -- it looks fairly close with shadow = true and antialias = false.
I believe ChatFont is Verdana - a font that's very similar to Tahoma. Default is Tahoma I believe (Verdana on OS X and Linux IIRC even though OS X has Tahoma).
[QUOTE=Bo98;46964853]I believe ChatFont is Verdana - a font that's very similar to Tahoma. Default is Tahoma I believe (Verdana on OS X and Linux IIRC even though OS X has Tahoma).[/QUOTE]
Right, sorry.
Did some searching just before you posted that. For future reference, they can can be found in [B]garrysmod/garrysmod/resource/ChatScheme.res[/B] (this is on a Windows machine, just for clarification):
[CODE]
//////////////////////// FONTS /////////////////////////////
//
// describes all the fonts
Fonts
{
"Default"
{
"1"
{
"name" "Verdana"
"tall" "12"
"weight" "0"
"range" "0x0000 0x017F"
"yres" "480 599"
}
...
"ChatFont"
{
"1"
{
"name" "Verdana"
"tall" "12"
"weight" "700"
"yres" "480 599"
"dropshadow" "1"
}[/CODE]
[QUOTE=Mista Tea;46964829]I believe the font used for at least "Default" is Tahoma. I'm looking at it in HUDPaint right now and it looks exactly the same. Probably the same for ChatFont -- it looks fairly close with shadow = true and antialias = false.[/QUOTE]
It is! Much appreciated, man.
[QUOTE=Mista Tea;46964861]Right, sorry.
I just found [B]garrysmod/garrysmod/resource/ChatScheme.res[/B] and saw this:
[/QUOTE]
Same goes to you. I'm actually a little ashamed now that I didn't figure out that all I had to do was to look up that one file, heh.
[B]Edit:[/B]
Wait what
[img]http://i.imgur.com/66f3VfU.png[/img]
[QUOTE=Mista Tea;46964632]I can't really picture how or why you need something like that, but using [URL="http://wiki.garrysmod.com/page/GM/EntityTakeDamage"]GM:EntityTakeDamage[/URL] seems to work fine:
[CODE]
-- Serverside file
hook.Add( "EntityTakeDamage", "PreventPlayerDeath", function( ent, dmgInfo )
if ( IsValid( ent ) and ent:IsPlayer() ) then -- make sure it's actually a player first
if ( ent:Health() - dmgInfo:GetDamage() <= 0 ) then -- if the damage they'd receive would kill them
dmgInfo:SetDamage( 0 ) -- prevents any further damage
hook.Run( "PrePlayerDeath", ent )
end
end
end )
hook.Add( "PrePlayerDeath", "PreDeathCheck", function( ply )
-- run whatever you're trying to do with the player
ply:Kill()
end )
[/CODE]
I hope this helps.[/QUOTE]
Interesting, I'll defiantly try this but the code will be used for a suicide bomb, when used you can't damage and if you're about to die you're forced to use it
[QUOTE=ROFLBURGER;46964532]acecool no offense but when you post solutions I legitimately do not understand a single thing you're saying
for the record I have absolutely no clue what a coroutines are and this is my first time using while loops
I found out what the problem was, it wasn't setting the self.CurrentEnemy to nil fast enough because it was basically on a 1 second tick when it needed to be on the same tickrate as the while loops[/QUOTE]
I'm sorry if I'm not clear enough in some of my responses.
Basically, using ents.FindInCone is VERY slow ( expensive in terms of processing power to execute especially if done every frame for x entities. It is slow enough for the client to run 1 ents.FindInCone but if the server has to do it for x entities then it'll slow your server down quite a bit ).
Co-routines, from my understanding, is a way to make code execute over the course of several frames instead of forcing it to execute all at once ( useful for expensive algorithms to have more time so as to not slow down the server ).
Glad you found the answer though!
[QUOTE=10853;46964864]It is! Much appreciated, man.
Same goes to you. I'm actually a little ashamed now that I didn't figure out that all I had to do was to look up that one file, heh.
[B]Edit:[/B]
Wait what
[img]http://i.imgur.com/66f3VfU.png[/img][/QUOTE]
Default probably is Verdana for Windows then. Must've been another font that was Tahoma.
[QUOTE=Acecool;46964909]I'm sorry if I'm not clear enough in some of my responses.
Basically, using ents.FindInCone is VERY slow ( expensive in terms of processing power to execute especially if done every frame for x entities. It is slow enough for the client to run 1 ents.FindInCone but if the server has to do it for x entities then it'll slow your server down quite a bit ).[/quote]
I'm aware how laggy it is. I tried it without a time modifier and it lagged pretty bad so it only runs every second until it find someone in it's cone
[quote]
Co-routines, from my understanding, is a way to make code execute over the course of several frames instead of forcing it to execute all at once ( useful for expensive algorithms to have more time so as to not slow down the server ).
Glad you found the answer though![/QUOTE]
In the end I ended up giving up. I plan on just using player.CreateNextBot() and controling it through the StartCommand hook. I already tested the targeting system with regular bots and there wasn't any lag so I'll continue using that.
Is Weapon:Clip1 not shared with other players? The ammo counter on my hud is wrong when spectating.
[code]local ent, spectating = LocalPlayer(), false
if ent:GetObserverMode() == OBS_MODE_IN_EYE and IsValid( ent:GetObserverTarget() ) then
ent, spectating = ent:GetObserverTarget(), true
end
local wep = ent:GetActiveWeapon()
if IsValid( wep ) and wep:GetPrimaryAmmoType() != -1 then
print( ent, wep, wep:Clip1() )
end
[/code]
If you're spectating someone it'll stay at the max clip regardless of how much they've shot.
[T]http://i.imgur.com/4o9aQUu.jpg[/T]
Am I doing something wrong or do you have to network it yourself?
[QUOTE=wauterboi;46964735]How would I make the player's EyeAngles slowly return to a specific angle while allowing them to move the mouse around?[/QUOTE]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/math/ApproachAngle]math.ApproachAngle[/url] on each tick?
Having another problem, I recently posted help for a certain type of thing and I got some code that should work but sadly it doesn't, the second your health hits 0 you die and nothing happens. This hook is added on the serverside
What it does is when a certain amount of damage would mean the players death then see if he has a certain weapon afterwards force him to select and use the weapon
[code]hook.Add( "EntityTakeDamage", "PreventPlayerDeath", function( ent, dmgInfo )
if IsValid(ent) and ent:IsPlayer() then
if ent:Health() - dmgInfo:GetDamage() <= 0 then
if not ent:Team() == TEAM_UNDEAD then
if ent:HasWeapon("weapon_zs_c4") then
dmgInfo:SetDamage(0)
dmginfo:ScaleDamage(0)
hook.Run( "PrePlayerDeath", ent )
end
end
end
end
end )
hook.Add( "PrePlayerDeath", "PreDeathCheck", function( ply )
ply:SelectWeapon("weapon_zs_c4")
local mywep = ply:GetActiveWeapon()
if IsValid(mywep) then
mywep:PrimaryAttack()
end
end )[/code]
How does one code a Q menu? What do I do on the click function on the spawnicons?
[QUOTE=RedNinja;46965439]How does one code a Q menu? What do I do on the click function on the spawnicons?[/QUOTE]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/ents/Create]ents.Create[/url]
For the class, you'd use prop_physics for normal props.
[QUOTE=Blasteh;46965272][img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/math/ApproachAngle]math.ApproachAngle[/url] on each tick?[/QUOTE]
I figured it out with CreateMove!
[url]http://facepunch.com/showthread.php?t=1447007[/url]
Anyone know how to remove convars?
I've been working to remove all of the errors and annoying content from the console on server startup and have recompiled a few models, installed engine-spew for some things that can't be changed, and I almost have it to the point where the only things that show is my gm text and file-system addon / workshop stuff.
But, I want to remove these convars from memory / cache:
Parent and child ConVars with different default values! physgun_limited child: 0
parent: 1 (parent wins)
Parent and child ConVars with different default values! sbox_noclip child: 1 par
ent: 0 (parent wins)
Parent and child ConVars with different default values! sbox_godmode child: 1 pa
rent: 0 (parent wins)
Changing gamemode to Acecool Dev: Crime City (acrp)
Parent and child ConVars with different default values! physgun_limited child: 0
parent: 1 (parent wins)
Parent and child ConVars with different default values! sbox_noclip child: 1 par
ent: 0 (parent wins)
Parent and child ConVars with different default values! sbox_godmode child: 1 pa
rent: 0 (parent wins)
My txt:
[code]"acecooldev_base"
{
"base" "base"
"title" "Acecool Dev: Base"
"menusystem" "1"
}
[/code]
Any ideas?
Sorry, you need to Log In to post a reply to this thread.