[QUOTE=fairy;39363081]You could put it init.lua in terrortown/gamemode/[/QUOTE]
You could, but then you'll have to re-add it every time you update.
An autorun folder would be more appropriate
So it should work by just making that it's own file and throwing it in say, lua/autorun/server/"killreveal.lua"?
[QUOTE=my_hat_stinks;39363306]You could, but then you'll have to re-add it every time you update.
An autorun folder would be more appropriate[/QUOTE]
I don't know that GetRoleString() will work outside of the main gamemode. But you can try it.
Is there any way of converting a string to lua?
So "print('Hi')"
Could be ran for example.
[QUOTE=Science;39363770]Is there any way of converting a string to lua?
So "print('Hi')"
Could be ran for example.[/QUOTE]
[code]RunString("print('Hi');");[/code]
Something like that?
[QUOTE=Chocolate1234;39362794]This is kind of a silly thing. I was trying to spawn a dropship with a troop container. I know it doesnt actually drop anything off or do anything but a dropship looks kind of silly without the container when youre putting it in the background of a screenshot. Anyways I used this bit of console lua code to do it after finding it on the forum somewhere.
lua_run dropship = ents.Create("npc_combinedropship")
dropship:SetKeyValue("CrateType", 1)
dropship:Spawn()
The thing is on the map it seems to spawn in a predefined location and turns out on the map i was using it was inside a shed and i couldn't get it out (it was kind of funny, really, because it didn't fit very well and was clipping through the walls) -- and,on any map, if i try to move it away and then turn the AI on it just goes back to where it was before instead of staying put (I know, air nodes). I tried another map and i couldn't find it at all although I heard it.
Now Im pretty sure theres a way to make it spawn at where your cursor points, I think its !picker or something but I don't know how or where to put it in, as I don't lua or any code very well. So if someone could help me, thanks.[/QUOTE]
Well I actually managed to get it into the spawnlist by taking a look at the actual NPC spawnlist for the dropship and then doing some modifications and then making a new lua file with just the container dropship. I am surprised I didn't make it break, especially when you take into fact that [I]I managed to break "hello world."[/I]
Ah the code worked for the reveler, thanks guys for helping me out. I put it in the autorun/server folder and works good!
How can I see if a file exists on the server from the client?
[QUOTE=J.R.;39364311]How can I see if a file exists on the server from the client?[/QUOTE]
Make a net hook on the server that runs file.Exists( net.ReadString() ) and then send the boolean back to the client.
How does the .png drawing actually work?
[lua]
local material = Material("mypng.png","unlitgeneric")
function drawPng()
surface.SetTexture(material)
surface.SetDrawColor(Color(255,255,255))
surface.DrawTexturedRect(0,0,50,50)
end
hook.Add("HUDPaint","MyPng",drawPng)
[/lua]
That doesn't work and nor does this:
[lua]
local material = surface.GetTextureID(Material("mypng.png","unlitgeneric"))
function drawPng()
surface.SetTexture(material)
surface.SetDrawColor(Color(255,255,255))
surface.DrawTexturedRect(0,0,50,50)
end
hook.Add("HUDPaint","MyPng",drawPng)
[/lua]
or this
[lua]
local material = surface.GetTextureID("mypng.png")
function drawPng()
surface.SetTexture(material)
surface.SetDrawColor(Color(255,255,255))
surface.DrawTexturedRect(0,0,50,50)
end
hook.Add("HUDPaint","MyPng",drawPng)
[/lua]
[QUOTE=thejjokerr;39366021]The first thing you tried but then with surface.SetMaterial rather than SetTexture.[/QUOTE]
Thanks, that worked!
Could someone explain to me how data works? To be more specific im using DarkRP where in showteamtabs.lua i have SetHTML( file.Read("stuff.txt") but when i launch it, it says SetHTML returns null(cause appearantly adding stuff.txt to servers data folder wont suffice). Any tips/hints/tutorials would be nice.
[editline]26th January 2013[/editline]
Instead of rating me dumb nudge me in the right direction, i just found out about resource.AddFile.
Hey guys, I'm working on an NPC and its my first time coding in GMod13 so I am not very use to it and I have no idea what I am doing wrong here but, here is the problem:
My NPC roams around the level just find. But right now, when I shoot him I want him to chase me. Although when I shoot him he either reacts to the shot by stopping his schedule, then continuing on his roam adventure or just ignores the shot all together. I have no idea what I am doing wrong.
[B]init.lua[/B]
[lua]AddCSLuaFile( "cl_init.lua" );
AddCSLuaFile( "shared.lua" );
include( 'shared.lua' );
ENT.StartHP = 100;
ENT.Model = "models/zombie/zclassic_03.mdl";
ENT.Sound = {};
ENT.Sound[ "GET_TARGET" ] = "";
function ENT:Initialize( )
self:SetModel( self.Model );
self:SetHullType( HULL_HUMAN );
self:SetHullSizeNormal( );
self:SetSolid( SOLID_BBOX );
self:SetMoveType( MOVETYPE_STEP );
//self:SetCollisionGroup( COLLISION_GROUP_ALL );
self:CapabilitiesAdd( bit.bor( CAP_MOVE_GROUND, CAP_INNATE_MELEE_ATTACK1 ) );
self:SetMaxYawSpeed( 5000 );
self:SetHealth( self.StartHP );
self:DropToFloor();
//Init Variables
self.fNextFootstepTime = 0;
end
function ENT:ValidTarget( pl )
if ( IsValid( pl ) && pl:IsPlayer() && pl:Alive()/* && pl:GetObserverMode() == OBS_MODE_NONE*/ ) then
return true;
end
return false;
end
function ENT:IsZombie()
return true;
end
function ENT:OnTakeDamage( dmginfo )
local attacker = dmginfo:GetAttacker();
self:SetHealth( self:Health() - dmginfo:GetDamage() );
if ( self:Health() <= 0 ) then
self:DoDeath( attacker );
return;
end
if ( self:ValidTarget( attacker ) ) then
self:SetEnemy( attacker, true );
self:SetSchedule( SCHED_CHASE_ENEMY );
end
end
function ENT:DoDeath( attacker )
self:Remove();
end
function ENT:Think( )
self:UpdateEnemy();
end
function ENT:UpdateEnemy()
if ( !self:ValidTarget( self:GetEnemy() ) ) then
return;
end
self:UpdateEnemyMemory( self:GetEnemy(), self:GetEnemy():GetPos() );
end
function ENT:FindEnemy()
if ( self:GetEnemy() ) then return; end
local pl = #player.GetAll()[ math.random( 1, #player.GetAll() ) ];
if ( self:ValidTarget( pl ) ) then
self:SetEnemy( pl, true );
self:UpdateEnemyMemory( pl, pl:GetPos() );
self:SetSchedule(SCHED_CHASE_ENEMY);
return;
end
self:FindEnemy(); //Loop this function until we find a enemy
end
function ENT:SelectSchedule( )
/* if ( BrainStock.Missions.IsServer() ) then
self:FindEnemy();
return;
end*/
//if ( self:ValidTarget( self:GetEnemy() ) ) then return; end
self:SetSchedule(SCHED_IDLE_WANDER);
end[/lua]
Now usually before asking a question I search it on google.
I searched this question on google and it fucking pains me to ask. I mean REALLY pains me to ask...
But how the fuck do I fix custom spawns on DarkRP.
I honestly just want to play this with my friends and I cant because the spawns are fucked when ever the server resets :/
If someone who has experience with darkrp could help that would be great.
*prepares for the onslaught of dumb ratings*
Also here is my static_data.lua
[CODE]-- Team Spawn Positions for various maps
if team_spawn_positions then
table.insert(team_spawn_positions, {"rp_jail_alcatraz", TEAM_CITIZEN, -1472.755737 -25.992861 96.031250})
table.insert(team_spawn_positions, {"rp_jail_alcatraz", TEAM_HITMAN, -1472.755737 -25.992861 96.031250})
table.insert(team_spawn_positions, {"rp_jail_alcatraz", TEAM_POLICE, -1830.557617 279.182007 96.031250})
table.insert(team_spawn_positions, {"rp_jail_alcatraz", TEAM_MAYOR, -1830.557617 279.182007 96.031250})
table.insert(team_spawn_positions, {"rp_jail_alcatraz", TEAM_CHIEF, -1830.557617 279.182007 96.031250})
table.insert(team_spawn_positions, {"rp_jail_alcatraz", TEAM_GANG, -1472.755737 -25.992861 96.031250})
table.insert(team_spawn_positions, {"rp_jail_alcatraz", TEAM_MOB, -1472.755737 -25.992861 96.031250})
table.insert(team_spawn_positions, {"rp_jail_alcatraz", TEAM_MEDIC, -1830.557617 279.182007 96.031250})
table.insert(team_spawn_positions, {"rp_jail_alcatraz", TEAM_GUN, -1472.755737 -25.992861 96.031250})
end[/CODE]
Please dont hate me ;~;
Hey guys,
Ok, so I have an entity that's pretty much bare-boned... I can spawn the entity just fine though an ent.Create() and it works fine, but when I try and spawn it through the Q menu, my server crashes.
Anyone know the deal?
[lua]
AddCSLuaFile()
DEFINE_BASECLASS( "base_gmodentity" )
ENT.PrintName = "Fire Ent"
ENT.Author = "Severed Skullz"
ENT.Purpose = "Fire entity for PNRP"
ENT.Spawnable = true
ENT.AdminSpawnable = true
if (SERVER) then
function ENT:Initialize()
self.Entity:SetModel("models/props_junk/sawblade001a.mdl")
self.Entity:PhysicsInit( SOLID_VPHYSICS ) -- Make us work with physics,
self.Entity:SetMoveType( MOVETYPE_VPHYSICS ) -- after all, gmod is a physics
self.Entity:SetSolid( SOLID_VPHYSICS ) -- Toolbox
self.Entity.BurnArea = 200
self.LastTime = 0
--timer.Create(tostring(self.Entity) .. "Timer", 1,0, self:DoFire)
end
function ENT:Use( activator, caller )
end
function ENT:Think()
--if not self.isLit then return end
if CurTime() >= self.LastTime then
self.LastTime = CurTime() + 3
self:DoFire()
end
end
function ENT:DoFire()
for k, v in pairs(player.GetAll()) do
if self:Distance(v) < self.BurnArea then
v.data.Stats["Therm"] = math.min(v.data.Stats["Therm"] + 3, 100)
SendTherm( v )
end
end
end
else
function ENT:Draw()
self.Entity:DrawModel()
end
end
[/lua]
Stick this in shared.lua
[url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index75e6.html[/url]
I would like some assistance converting these two scripts to GM13:
[CODE] local RegenerateAmount = 10
local RegenerateTime = 10
local RegenerateMax = 600
local function RegenerateHealth()
for k,v in pairs(player.GetAll()) do
if v:Alive() and v:IsAdmin() then
v:SetHealth(math.min(v:Health()+RegenerateAmount,math.max(100,RegenerateMax)))
end
end
timer.Simple(RegenerateTime,RegenerateHealth)
end
RegenerateHealth()
[/CODE]
and
[CODE]local function UnlimitedAmmo()
for k,v in pairs(player.GetAll()) do
curwep = v:GetActiveWeapon()
if (v:Alive()) then
if v:GetAmmoCount(curwep:GetPrimaryAmmoType() < 100)then
v:SetAmmo(100,curwep:GetPrimaryAmmoType())
end
if v:GetAmmoCount(curwep:GetSecondaryAmmoType() < 100)then
v:SetAmmo(100,curwep:GetSecondaryAmmoType())
end
end
end
timer.Simple(0.05,UnlimitedAmmo)
end
UnlimitedAmmo()[/CODE]
How would I make a setmoney command like: bw_setmoney
I already have a money system.
Is there any documentation on how Player:UniqueID( ) is calculated?
[QUOTE=Mega1mpact;39369748]Is there any documentation on how Player:UniqueID( ) is calculated?[/QUOTE]
[lua]util.CRC("gm_" .. ply:SteamID() .. "_gm")[/lua]
[QUOTE=tigeronmybed;39369405]I would like some assistance converting these two scripts to GM13:
-snip-[/QUOTE]
Both of these are perfectly compatible with Gmod 13, but the second script has a minor typo that messes it up.
This:
[CODE]
if v:GetAmmoCount(curwep:GetPrimaryAmmoType() < 100)then
...
if v:GetAmmoCount(curwep:GetSecondaryAmmoType() < 100)then
[/CODE]
needs to be:
[CODE]
if v:GetAmmoCount(curwep:GetPrimaryAmmoType()) < 100 then
...
if v:GetAmmoCount(curwep:GetSecondaryAmmoType()) < 100 then
[/CODE]
[QUOTE=Matt-;39369898][lua]util.CRC("gm_" .. ply:SteamID() .. "_gm")[/lua][/QUOTE]
Is there any way to reverse this process?
I followed the tutorial on the wiki for creating a gamemode. However, when I try to launch it I get this error while loading: "Error loading gamemode: !IsValidGamemode[untitled]"
cl_init.lua
[lua]
include( 'shared.lua' )
[/lua]
init.lua
[lua]
AddCSLuaFile( "shared.lua" )
AddCSLuaFile( "cl_init.lua" )
include( 'shared.lua' )
function GM:PlayerLoadout( pl )
pl:Give( "weapon_pistol" )
pl:Give( "weapon_smg1" )
pl:Give( "weapon_crowbar" )
pl:GiveAmmo( 999, "pistol" )
pl:GiveAmmo( 999, "smg1" )
end
[/lua]
shared.lua
[lua]
GM.Name = "Untitled"
GM.Author = "Untitled"
GM.Email = "Untitled"
GM.Website = ""
[/lua]
[QUOTE=TehButter;39369930]Both of these are perfectly compatible with Gmod 13, but the second script has a minor typo that messes it up.
This:
[CODE]
if v:GetAmmoCount(curwep:GetPrimaryAmmoType() < 100)then
...
if v:GetAmmoCount(curwep:GetSecondaryAmmoType() < 100)then
[/CODE]
needs to be:
[CODE]
if v:GetAmmoCount(curwep:GetPrimaryAmmoType()) < 100 then
...
if v:GetAmmoCount(curwep:GetSecondaryAmmoType()) < 100 then
[/CODE][/QUOTE]
It gets the current ammo, it doesn't check if it's less that 100 of not.
For the pistol and smg, it flashes between 8200 and 256.
[QUOTE=N!mr0d;39370276]I followed the tutorial on the wiki for creating a gamemode. However, when I try to launch it I get this error while loading: "Error loading gamemode: !IsValidGamemode[untitled]"
cl_init.lua
[lua]
include( 'shared.lua' )
[/lua]
init.lua
[lua]
AddCSLuaFile( "shared.lua" )
AddCSLuaFile( "cl_init.lua" )
include( 'shared.lua' )
function GM:PlayerLoadout( pl )
pl:Give( "weapon_pistol" )
pl:Give( "weapon_smg1" )
pl:Give( "weapon_crowbar" )
pl:GiveAmmo( 999, "pistol" )
pl:GiveAmmo( 999, "smg1" )
end
[/lua]
shared.lua
[lua]
GM.Name = "Untitled"
GM.Author = "Untitled"
GM.Email = "Untitled"
GM.Website = ""
[/lua][/QUOTE]
In shared.lua:
[code]
DeriveGamemode("sandbox")
[/code]
Is anyone having issues applying alpha to SENT's example of how im applying the alpha:
[lua] local colortbl = team.GetColor(ply:Team())
ent:SetColor(Color(colortbl.r,colortbl.g,colortbl.b,125))
ent:SetRenderMode(RENDERMODE_TRANSALPHA)[/lua]
However if I set the alpha to 0 its invisable, but anything greater then 1 is like having set the alpha to 255
Since nobody answered me.. AGAIN : T
[TTT]Anti RDM System
Is there anyway make the server automaticlly detec when a innocent crowbars another innocent to death? Specially if he is afk.. I assume that 99% of the times an inno is killed with a crowbar it is rdm.
[QUOTE=hellguy;39372414]Since nobody answered me.. AGAIN : T
[TTT]Anti RDM System
Is there anyway make the server automaticlly detec when a innocent crowbars another innocent to death? Specially if he is afk.. I assume that 99% of the times an inno is killed with a crowbar it is rdm.[/QUOTE]
There is no such thing as Anti RDM in TTT.
[QUOTE=brandonj4;39372463]There is no such thing as Anti RDM in TTT.[/QUOTE]
My god, try to understand, this is a "Help and support" area in the lua section, so you can assume that I'm not looking for a feature, but gently asking someone to code that for me
I couldn't figure this out
When the player presses 1 (Not Numberpad) something in the HUD is suppose
to change (The color of a box, so the player can see "I activated that; It reacts")
Since it has to do with the HUD I thought I will have to put it in cl_init.lua so I wrote this:
[QUOTE]
if( LocalPlayer( client ):KeyDown( KEY_1 ) ) then
draw.RoundedBox( 8, ScrW()*0.327, ScrH()*0.875, 50, 50, Color( 13, 176, 255, 200 ) )
else
draw.RoundedBox( 8, ScrW()*0.327, ScrH()*0.875, 50, 50, Color( 33, 63, 102, 250 ) )
end
[/QUOTE]
It worked, but it's only activated when I press 'SPACE', not 1. Afterwards I read in the [URL="http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexa077.html"]Lua Library[/URL], that ( KEY_* ) is only used with
input.IsKeyDown in init.lua (In other cases it would "Derp" like in my IF), but if I want to use KeyDown, I will have to use ( IN_* ) instead, but ( IN_* ) doesn't include
keys like A,B,C,D,1,2,3,4, Shift, Alt, etc., instead it uses Attack, Use, Reload, etc. (But I need to activate it with a key from 1-9)
I tried all sorts of things out, but nothing has worked yet :( Only Lua Errors occurred when I tried to find a solution
[B]TL;DR[/B]
By pressing a button on the players keyboard, the look of the HUD is suppose to change (e.g. color of a RoundedBox)
What function would I have to use?
Sorry, you need to Log In to post a reply to this thread.