[QUOTE=code_gs;52301428]Define attacker in the arguments and put the NWVar calls outside of the IsValid check[/QUOTE]
i added few new items to this list and got this error
[lua]
[ERROR] gamemodes/metro_online/gamemode/init.lua:260: '}' expected (to close '{' at line 256) near '"item_ammo_357"'
1. unknown - gamemodes/metro_online/gamemode/init.lua:0
[/lua]
[lua]local tClasses = {
"weapon_pistol",
"item_ammo_pistol",
"item_ammo_smg1"
"item_ammo_357"
"item_box_buckshot"
"item_ammo_ar2"
"item_battery"
"item_ammo_crossbow"
"weapon_smg1"
}
local iChoices = #tClasses
local flSpawnHeight = 100
function GM:OnNPCKilled(pVictim, attacker)
local pDrop = ents.Create(tClasses[math.random(1, iChoices)])
if (pDrop:IsValid()) then
local vSpawnPos = pVictim:GetPos()
vSpawnPos[3] = vSpawnPos[3] + flSpawnHeight
pDrop:SetPos(vSpawnPos)
pDrop:Spawn()
end
attacker:SetNWInt("playerMoney", attacker:GetNWInt("playerMoney") + 50)
attacker:SetNWInt("playerExp",attacker:GetNWInt("playerExp") + 100)
attacker:SetNWInt("playerLvl",attacker:GetNWInt("playerLvl") + 1)
end[/lua]
You need commas after each entry. Also, make sure the attacker is a player before running the NWVar functions.
[QUOTE=RasmusG5;52299641]npc wont drop anything anymore after i added this code
[lua]function GM:OnNPCKilled(npc, attacker, inflictor)
attacker:SetNWInt("playerMoney", attacker:GetNWInt("playerMoney") + 50)
attacker:SetNWInt("playerExp",attacker:GetNWInt("playerExp") + 100)
attacker:SetNWInt("playerLvl",attacker:GetNWInt("playerLvl") + 1)
end[/lua]
npc drop system
[lua]function GM:OnNPCKilled(victim, killer, weapon)
local Rand = math.random(1, 3)
local SpawnHeight = 100
local NpcPos = victim:GetPos()
local Drop
if Rand == 1 then
Drop = ents.Create("weapon_pistol")
Drop:SetPos(NpcPos+Vector(0, 0, SpawnHeight))
Drop:Spawn()
Drop:Activate()
elseif Rand == 2 then
Drop = ents.Create("item_ammo_pistol")
Drop:SetPos(NpcPos+Vector(0, 0, SpawnHeight))
Drop:Spawn()
Drop:Activate()
elseif Rand == 3 then
Drop = ents.Create("item_ammo_smg1_large")
Drop:SetPos(NpcPos+Vector(0, 0, SpawnHeight))
Drop:Spawn()
Drop:Activate()
end
end[/lua]
how to fix?[/QUOTE]
I know you've probably fixed this already a different way, but I just wanted to say - my preferred method of dealing with this stuff is to use hook.Add instead of GM functions.
[QUOTE=NeatNit;52302901]I know you've probably fixed this already a different way, but I just wanted to say - my preferred method of dealing with this stuff is to use hook.Add instead of GM functions.[/QUOTE]
yeah i fixed it but i noticed that fast zombies only do 6 damage in my gamemode wich is pretty weak is there way to make them do more damage? if code makes all npc do more damage it isnt big dealt becoust they are the only ones
[QUOTE=RasmusG5;52303286]yeah i fixed it but i noticed that fast zombies only do 6 damage in my gamemode wich is pretty weak is there way to make them do more damage? if code makes all npc do more damage it isnt big dealt becoust they are the only ones[/QUOTE]
[url]http://wiki.garrysmod.com/page/GM/ScaleNPCDamage[/url]
[url]http://wiki.garrysmod.com/page/GM/ScalePlayerDamage[/url]
[url]http://wiki.garrysmod.com/page/GM/EntityTakeDamage[/url]
[QUOTE=SleepyMode;52303403][url]http://wiki.garrysmod.com/page/GM/ScaleNPCDamage[/url]
[url]http://wiki.garrysmod.com/page/GM/ScalePlayerDamage[/url]
[url]http://wiki.garrysmod.com/page/GM/EntityTakeDamage[/url][/QUOTE]
so i did this but it wont work i didnt get any errors
[lua]function GM:ScalePlayerDamage( ply, dmginfo )
if ( attacker:NPC()) then
dmginfo:ScaleDamage( 5 )
end
end[/lua]
[QUOTE=RasmusG5;52303567]so i did this but it wont work i didnt get any errors
[lua]function GM:ScalePlayerDamage( ply, dmginfo )
if ( attacker:NPC()) then
dmginfo:ScaleDamage( 5 )
end
end[/lua][/QUOTE]
There is not "attacker", of course it will not work.
[QUOTE=SleepyMode;52303658]There is not "attacker", of course it will not work.[/QUOTE]
you mean like this?
[lua]function GM:ScalePlayerDamage( ply, dmginfo, attacker )
if ( attacker:NPC()) then
dmginfo:ScaleDamage( 5 )
end
end[/lua]
[QUOTE=RasmusG5;52303683]you mean like this?
[lua]function GM:ScalePlayerDamage( ply, dmginfo, attacker )
if ( attacker:NPC()) then
dmginfo:ScaleDamage( 5 )
end
end[/lua][/QUOTE]
Have you looked at the arguments for the hook you're using? [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/ScalePlayerDamage]GM:ScalePlayerDamage[/url]
Third argument is a CTakeDamageInfo, you need to use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/CTakeDamageInfo/GetAttacker]CTakeDamageInfo:GetAttacker[/url]. Also, `NPC` isn't a method, you probably want [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/IsNPC]Entity:IsNPC[/url].
How could I register a weapon with [IMG]http://wiki.garrysmod.com/favicon.ico[/IMG] [URL="http://wiki.garrysmod.com/page/weapons/Register"]weapons.Register[/URL] and have it inherit from another weapon base that was also registered with weapons.Register?
[QUOTE=YourStalker;52317726]How could I register a weapon with [IMG]http://wiki.garrysmod.com/favicon.ico[/IMG] [URL="http://wiki.garrysmod.com/page/weapons/Register"]weapons.Register[/URL] and have it inherit from another weapon base that was also registered with weapons.Register?[/QUOTE]
Use weapons.Get, modify the table, register it.
Hi all,
pretty much a newcomer when it comes to Lua here - I've dabbled in Java before and understand most of the basic terms. I've been trying to write a custom script to disable the SMG grenade for Prop Hunt but it doesn't want to work. After trial and error with various methods of removing the ammo - my last resort is to ask here.
[CODE]
function Loadout( ply )
if ply:Team() == TEAM_HUNTERS then
ply:SetAmmo(0, "SMG1_Grenade")
end
end
hook.Add("PlayerLoadout", "RemoveNade", Loadout)[/CODE]
The code does not spit out any errors when saving it to the server via FileZilla (and is in lua/autorun/server) or when I run the script via lua_openscript (via console). However it doesn't remove the SMG Grenade.
Any help/pointers are appreciated.
Thanks
[QUOTE=meharryp;52318665]Use weapons.Get, modify the table, register it.[/QUOTE]
Thanks, was wondering if there's an automatic way like there is with registering weapons normally, guess not though.
I have a really simple question that I can't seem to figure out. When the player presses Q it sends a net message:
[code]hook.Add("Think", "HolsterWeapon", function()
if input.IsKeyDown(KEY_Q) then
net.Start("holsterweapon")
net.SendToServer()
end
end)
[/code]
I only want the player to be able to be able to send the net message every 2-3 seconds. How would I do that?
[QUOTE=bilbasio;52320154]I have a really simple question that I can't seem to figure out. When the player presses Q it sends a net message:
[code]hook.Add("Think", "HolsterWeapon", function()
if input.IsKeyDown(KEY_Q) then
net.Start("holsterweapon")
net.SendToServer()
end
end)
[/code]
I only want the player to be able to be able to send the net message every 2-3 seconds. How would I do that?[/QUOTE]
If you want it to use the spawnmenu key, you should probably use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/OnSpawnMenuOpen]GM:OnSpawnMenuOpen[/url]
As for the time limit, set a value to CurTime() + 3 when the menu is opened, and check if CurTime() is greater than that value before doing anything
Example:
[code]
local nextholster = 0
local function holster()
if CurTime() > nextholster then
--do stuff
nextholster = CurTime() + 3
end
end
[/code]
[QUOTE=AwfulRanger;52320201]If you want it to use the spawnmenu key, you should probably use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/OnSpawnMenuOpen]GM:OnSpawnMenuOpen[/url]
As for the time limit, set a value to CurTime() + 3 when the menu is opened, and check if CurTime() is greater than that value before doing anything
Example:
[code]
local nextholster = 0
local function holster()
if CurTime() > nextholster then
--do stuff
nextholster = CurTime() + 3
end
end
[/code][/QUOTE]
Thank you that's what I needed.
[QUOTE=bilbasio;52320154]
I only want the player to be able to be able to send the net message every 2-3 seconds. How would I do that?[/QUOTE]
If you're looking for a question to this specific answer (Not regarding the specific instance), you would have to use [URL="http://wiki.garrysmod.com/page/Delays_and_Cooldowns"]CurTime cooldown[/URL].
Also, [URL="https://facepunch.com/showthread.php?t=1560712"]MPan1 has created a nice module for this exactly[/URL]
Not too much of a problem, just something that I'm curious about. How do some servers have a perfect tickrate - such as 33.0 constantly?
I've tried running a server locally and on a dedicated server with 0 addons on a default gamemode like sandbox with only myself as a player, and it always ticks up and down quite widely.
Other servers like SuperiorServers, among many others (when not under too much load) can just sit at a perfect 11, 16 or 33 almost perfectly, with MAYBE a small .1 variation, even though the actual 'var' value is much higher.
[QUOTE=Castiel789;52322663]Not too much of a problem, just something that I'm curious about. How do some servers have a perfect tickrate - such as 33.0 constantly?
I've tried running a server locally and on a dedicated server with 0 addons on a default gamemode like sandbox with only myself as a player, and it always ticks up and down quite widely.
Other servers like SuperiorServers, among many others (when not under too much load) can just sit at a perfect 11, 16 or 33 almost perfectly, with MAYBE a small .1 variation, even though the actual 'var' value is much higher.[/QUOTE]
How are you measuring the tickrate?
[QUOTE=zoox;52324232]How are you measuring the tickrate?[/QUOTE]
Does this not show in the net graph? That's what the bottom right number is "x"/s?
Where "x" is equaling the calculations per second.
It's the number after "sv: "
is there a way to print the console log on the hud so i dont have to keep switching to the console and back?
[QUOTE=Shenesis;52324484][code]developer 1[/code] in console[/QUOTE]
fukin sweet thank you
[QUOTE=zoox;52324232]How are you measuring the tickrate?[/QUOTE]
Yeah, I measured it using netgraph on multiple different servers
[QUOTE=Castiel789;52322663]Not too much of a problem, just something that I'm curious about. How do some servers have a perfect tickrate - such as 33.0 constantly?
I've tried running a server locally and on a dedicated server with 0 addons on a default gamemode like sandbox with only myself as a player, and it always ticks up and down quite widely.
Other servers like SuperiorServers, among many others (when not under too much load) can just sit at a perfect 11, 16 or 33 almost perfectly, with MAYBE a small .1 variation, even though the actual 'var' value is much higher.[/QUOTE]
Yeah, your local server would have to compete with other processes. Superior servers would likely have their darkrp server on a core all by itself, meaning it doesn't need to compete with any other processes.
[QUOTE=Promptitude;52326156]Yeah, your local server would have to compete with other processes. Superior servers would likely have their darkrp server on a core all by itself, meaning it doesn't need to compete with any other processes.[/QUOTE]
Like I said though I've tried it on a dedicated server, 4GHz processor etc, completely default, and it still appears to have more variation(less var, but sv fluctuates more) than their populated server with however many active scripts are running.
[QUOTE=Castiel789;52326196]Like I said though I've tried it on a dedicated server, 4GHz processor etc, completely default, and it still appears to have more variation(less var, but sv fluctuates more) than their populated server with however many active scripts are running.[/QUOTE]
Was the server running on its own, empty core? On Linux try setting the CPU affinity of the server to some core and every other process to others.
how i could check if player is near on player death?
[QUOTE=RasmusG5;52326993]how i could check if player is near on player death?[/QUOTE]
:snip: do what the post below says
[QUOTE=MPan1;52327020][img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/ents/FindInBox]ents.FindInBox[/url]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/IsPlayer]Entity:IsPlayer[/url][/QUOTE]
Wouldn't it be better to loop through all the players and use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Vector/Distance]Vector:Distance[/url]?
Sorry, you need to Log In to post a reply to this thread.