I'm really new to Lua and I'm following [url=http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexaee6.html?title=Simple_Gamemode]this[/url] guide to making a gamemode for Marble Blast Ultra to go with GameDev's maps. When I test it in GMod, the console says
[quote=Console]Cannot change maxplayers while the server is running
Dropped Pyth from server (Server shutting down)
Browser Message: Uncaught ReferenceError: SetStatusChanged is not defined - :0Lua initialized (Lua 5.1)
[gamemodes\marble_blast_ultra\gamemode\init.lua:59] function arguments expected near 'end'
[cpp]
There was a problem opening the gamemode file 'Marble_Blast_Ultra/gamemode/init.lua'
Registering gamemode 'Marble_Blast_Ultra' derived from 'base'
ScriptEnforce is disabled
Executing listen server config file
Lua initialized (Lua 5.1)
Registering gamemode 'sandbox' derived from 'base'
Registering gamemode 'Marble_Blast_Ultra' derived from 'sandbox'
Sending 267 'User Info' ConVars to server (cl_spewuserinfoconvars to see)
Scanning for downloaded fonts..
Redownloading all lightmaps
[/quote]
No clue what it means, but here's the init.lua.
[lua]
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
AddCSLuaFile( "specialchars.lua" )
include( 'shared.lua' )
include( 'specialchars.lua' )
--on player spawn
function GM:PlayerSpawn( ply )
self.BaseClass:PlayerSpawn( ply )
ply:SetGravity ( 1 )
ply:SetMaxHealth ( 100, true )
ply:SetWalkSpeed ( 325 )
ply:SetRunSpeed ( 325 )
end
--on player join
function GM:PlayerInitialSpawn( ply )
CheckSpecialCharacters( ply )
if ply:IsAdmin() then
mbu_team2( ply )
else
joining( ply )
RunConsoleCommand( "mbu_start" )
end
end
--weapons given on player join team
function GM:PlayerLoadout( ply )
if ply:Team() == 1 then
// blank because no weapons are used
elseif ply:Team() == 2 then
//blank because no weapons are used
end
end
--on player join team Players [1]
function mbu_team1( ply )
ply:UnSpectate()
ply:SetTeam( 1 )
ply:Spawn()
ply:PrintMessage( HUD_PRINTTALK, "[Marble Blast Ultra]Welcome to the server!")
end
--on player join team Admins [2]
function mbu_team2( ply )
ply:SetTeam( 2 )
ply:Spawn
ply:PrintMessage( HUD_PRINTTALK, "[Marble Blast Ultra]Welcome back, Admin.")
end
concommand.Add( "mbu_team1", mbu_team1 )
--on player join the server pre-team selection
function joining( ply )
ply:Spectate( 5 )
ply:SetTeam( 3 )
end
[/lua]
[lua]AddCSLuaFile( "shared.lua" )
SWEP.Author = "Flubascrubadoo"
SWEP.Purpose = ""
SWEP.Instructions = ""
SWEP.Spawnable = false
SWEP.AdminSpawnable = true
SWEP.ViewModel = "models/weapons/v_atgun.mdl"
SWEP.WorldModel = "models/jaanus/atgun.mdl"
SWEP.Category = "etest"
SWEP.Primary.ClipSize = 8
SWEP.Primary.DefaultClip = -1
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = "none"
SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = "none"
SWEP.Weight = 5
SWEP.AutoSwitchTo = false
SWEP.AutoSwitchFrom = false
SWEP.PrintName = "Heavy Plasma Sniper Rifle"
SWEP.Slot = 1
SWEP.SlotPos = 2
SWEP.DrawAmmo = false
SWEP.DrawCrosshair = true
local ShootSound = Sound( "NPC_Hunter.FlechetteShoot" )
Zoom = 0
Slomo = 0
/*---------------------------------------------------------
Think does nothing (insert strikethrough) something
---------------------------------------------------------*/
/*function SWEP:Reload() //ugh doesnt work, but i dont care
if(Slomo == 0) then
if(SERVER) then
RunConsoleCommand("host_timescale", "0.7")
end
self:EmitSound("Weapon_AR2.Special1")
Slomo = 1
else
if(SERVER) then
RunConsoleCommand("host_timescale", "1")
end
self:EmitSound("Weapon_AR2.Special2")
Slomo = 0
end
end*/
/*---------------------------------------------------------
PrimaryAttack
---------------------------------------------------------*/
function SWEP:PrimaryAttack()
self.Weapon:SetNextPrimaryFire( CurTime() + 0.85 )
self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
self:EmitSound( ShootSound )
self:ShootEffects( self )
// The rest is only done on the server and shit
if (!SERVER) then return end
self:TakePrimaryAmmo( 0 )
local x
for x = 1, 12 do
local r1 = math.random(-20, 20) / 10000
local r2 = math.random(-20, 20) / 10000
local r3 = math.random(-20, 20) / 10000
local Forward = self.Owner:EyeAngles():Forward()
local ent = ents.Create( "hunter_flechette" )
if ( ValidEntity( ent ) ) then
ent:SetPos( self.Owner:GetShootPos() + Forward * 30 )
ent:SetAngles( self.Owner:EyeAngles() )
ent:Spawn()
ent:SetVelocity( Forward * 3000 ) //LET THERE BE BULLET DROP! IN THIS CASE, FLECHETTEs.
end
ent:Fire("addoutput","basevelocity 0 0 -5",0.1)
ent:Fire("addoutput","basevelocity 0 0 -6",0.3)
ent:Fire("addoutput","basevelocity 0 0 -8",0.5)
ent:Fire("addoutput","basevelocity 0 0 -10",0.7)
ent:Fire("addoutput","basevelocity 0 0 -13",1)
ent:Fire("addoutput","basevelocity 0 0 -16",1.3)
ent:Fire("addoutput","basevelocity 0 0 -19",1.5)
ent:Fire("addoutput","basevelocity 0 0 -23",1.7) //useless mumbo jumbo
ent:Fire("addoutput","basevelocity 0 0 -27",2)
ent:Fire("addoutput","basevelocity 0 0 -31.5",2.3)
ent:Fire("addoutput","basevelocity 0 0 -34",2.5)
ent:Fire("addoutput","basevelocity 0 0 -39",2.7)
ent:AddEffects( EF_ITEM_BLINK | EF_BRIGHTLIGHT );
ent:SetOwner( self.Owner )
util.ScreenShake( ent:GetPos(), 2, 2, 0.7, 100 )
ParticleEffectAttach("larvae_glow_extract",PATTACH_ABSORIGIN_FOLLOW,ent,0) //wee
ParticleEffectAttach("vortigaunt_hand_glow",PATTACH_ABSORIGIN_FOLLOW,ent,0)
ParticleEffectAttach("test_beam",PATTACH_ABSORIGIN_FOLLOW,ent,0)
timer.Simple(2.7,function() ParticleEffectAttach("Weapon_Combine_Ion_Cannon_Explosion",PATTACH_ABSORIGIN_FOLLOW,ent,0) end)
timer.Simple(2.7,function() ParticleEffectAttach("electrical_arc_01_system",PATTACH_ABSORIGIN_FOLLOW,ent,0) end)
//timer.Simple(2.7,function() ParticleEffectAttach("cingularity",PATTACH_ABSORIGIN_FOLLOW,ent,0) end)
//timer.Simple(2.7,function() ParticleEffectAttach("aurora_02b",PATTACH_ABSORIGIN_FOLLOW,ent,0) end)
end
end
/*---------------------------------------------------------
SecondaryAttack
---------------------------------------------------------*/
function SWEP:SecondaryAttack()
if(Zoom == 0) then
if(SERVER) then
self.Owner:SetFOV( 25, 0.25 )
end
self:EmitSound("Weapon_AR2.Special1")
Zoom = 1
else
if(SERVER) then
self.Owner:SetFOV( 0, 0.25 )
end
self:EmitSound("Weapon_AR2.Special2")
Zoom = 0
end
end
hook.Add("EntityRemoved", "entRemoved", entityRemoved)
[/lua]
Ugh, tried going back into Lua on a very old and simple project, but whenever the flechettes attach to an NPC, the explosion effects simply seem to go to the origin of the map rather than explode where the NPC is. How would I go about making it so that no effects appear if a flechette hits an NPC (becomes non-existant)?
I tried something like this at around line 110 and commenting out the code pertaining to the timed effects:
[lua]timer.Simple(2.7,function()
if IsValid(ent) then
ParticleEffectAttach("aurora_02b",PATTACH_ABSORIGIN_FOLLOW,ent,0)
ParticleEffectAttach("electrical_arc_01_system",PATTACH_ABSORIGIN_FOLLOW,ent,0)
ParticleEffectAttach("Weapon_Combine_Ion_Cannon_Explosion",PATTACH_ABSORIGIN_FOLLOW,ent,0)
ParticleEffectAttach("cingularity",PATTACH_ABSORIGIN_FOLLOW,ent,0)
end
end)[/lua]
But all that does is completely remove the extra delayed effects attached to the flechette, although there are no effects attached to the origin of the map.
Suggestions?
[editline]4th February 2012[/editline]
Gah, nevermind, I realized the thing I did at the bottom wasn't in the primary fire function... I'm dumb.
[lua]function DB_GlobalSave()
for _, ply in pairs (player.GetAll()) do
if ply:IsValid() then
SQLaction = sql.Query("UPDATE ply_info SET money = "..ply.stats.money..", items = 'smallbattery', WHERE u_id = '"..ply:SteamID().."'")
end
if !SQLaction then
print(sql.LastError(SQLaction))
end
end
end[/lua]
Timer Error: [gamemodes\nethsrp\gamemode\database.lua:54] attempt to concatenate field 'money' (a nil value)
If anyone is curious, this is where I setup those tables:
[lua]function DB_LoadPlayer( person )
if !person:IsValid() then return end
SQLaction = sql.Query("SELECT u_id, money, items FROM ply_info WHERE u_id = '"..person:SteamID().."'")
if SQLaction then
person.stats =
{
money = SQLaction.money,
xp = 1337,
points = 1339
}
person.items =
{
SQLaction.items
}
DB_SendStats( person )
//DB_SendItems( person )
else
DB_NewPlayer( person )
end
end
hook.Add( "PlayerInitialSpawn", "DB_LoadPlayer", DB_LoadPlayer )[/lua]
[QUOTE=Pyth;34538932]I'm really new to Lua and I'm following [url=http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexaee6.html?title=Simple_Gamemode]this[/url] guide to making a gamemode for Marble Blast Ultra to go with GameDev's maps. When I test it in GMod, the console says
No clue what it means, but here's the init.lua.
[lua]
- code -
[/lua][/QUOTE]
Line 58:
[lua]ply:Spawn[/lua]
Should be
[lua]ply:Spawn()[/lua]
[QUOTE=pennerlord;34539773]Line 58:
[lua]ply:Spawn[/lua]
Should be
[lua]ply:Spawn()[/lua][/QUOTE]
Oh shit, thanks.
What difference between function and local function?
You can't call local function globally?
[QUOTE=aurum481;34540350]What difference between function and local function?
You can't call local function globally?[/QUOTE]
a local function can only be run within the block of code its been made in.
[QUOTE=aurum481;34540350]What difference between function and local function?
You can't call local function globally?[/QUOTE]
Acts like any other local, it doesn't exist outside it's scope.
[QUOTE=Drakehawke;34533346]GM:HUDPaint is for gamemodes, which is loaded after autorun hence it's nil when your file is ran.
Use this instead:
[lua]hook.Add( "HUDPaint", "DrawSpeedo?", function()
-- your code here
end )[/lua][/QUOTE]
Thank you very much, it works. Just one question: What units is the result for GetVelocity() in? When I walk its 250, when I run its 500 (gmod walk and run are faster than normal), when I drive a vehicle its 800-1100. Id like to convert them to kph.
Since wiki is not working properly I get no uselful results for this function.
Edit: I have measured this:
vehicle
normal mode: measured max: 1580 specified max: 90 mph 144.84096 kph
boost mode: measured max: 2110 specified max: 120 mph 193.12128 kph
[QUOTE=Jinx786;34540750]Thank you very much, it works. Just one question: What units is the result in? When I walk its 250, when I run its 500, when I drive a vehicle its 800-1100.
Since wiki is not working properly I get no uselful results for this function.[/QUOTE]
Units per a minute at a guess.
[QUOTE=Jinx786;34540750]Thank you very much, it works. Just one question: What units is the result for GetVelocity() in? When I walk its 250, when I run its 500 (gmod walk and run are faster than normal), when I drive a vehicle its 800-1100. Id like to convert them to kph.
Since wiki is not working properly I get no uselful results for this function.[/QUOTE]
[url]https://developer.valvesoftware.com/wiki/Dimensions[/url]
It's in units per second.
Feet per second = speed/16
Miles per hour = (speed * 3600)/5280
Kilometers per hour = (speed * 0.3048 * 3600)/(1000 * 16)
Is there a tutorial somewhere that teaches you how to make your own particle system/particle effects that can be used in conjunction with util.Effect() or ParticleEffectAttach()?
EP2 ones are nice but I'd rather make my own.
Getting a weird problem on my server.
Basically on TTT, every so often, when someone drops any weapon on the floor then tries to pick it up with their magneto stick, the weapon gets stuck inside the floor, spazzes out (With dust clouds) and the server crashes. This never used to happen on our old host, but I have no idea why a different host would affect this.
The dumps confirmed it was a vphysics crash, but I'm not really sure what could be done to fix it aside from not letting people pick them up.
im gonna post in this thread again. hope its fine.
ive been trying all day to make a AmmoCrate. entity for rp that when you click use on it you would obtain 20 Pistol ammo ive been trying for 6hrs today without luck i hope theres some help out there
Need Help with a 3D HUD, Trying to use render targets, but dont know much about the library.
Is there any way to sort a table by key? I have a table with 20 strings as the key and want to sort alphanumerically based on that key.
[QUOTE=Banana Lord.;34549193]Is there any way to sort a table by key? I have a table with 20 strings as the key and want to sort alphanumerically based on that key.[/QUOTE]
[lua]for k, v in SortedPairs( tbl ) do
-- blah
end[/lua]
The function is in lua/includes/extensions/table.lua
[QUOTE=raBBish;34549314][lua]for k, v in SortedPairs( tbl ) do
-- blah
end[/lua]
The function is in lua/includes/extensions/table.lua[/QUOTE]
Perfect, thanks
How do you add 1 to network bool?
e.g
[lua]self.Entity:SetNWBool("fertlimit", +1)[/lua]
It was set at 0 on initialize.
[QUOTE=Mrkrabz;34551790]How do you add 1 to network bool?
e.g
[lua]self.Entity:SetNWBool("fertlimit", +1)[/lua]
It was set at 0 on initialize.[/QUOTE]
you cat 'add' to a bool, bools are 'true' or 'false'
[QUOTE=Deadman123;34552007]you cat 'add' to a bool, bools are 'true' or 'false'[/QUOTE]
Yes, but bools can also be 1,2,3 etc?
no
[editline]ajb[/editline]
A 'Boolean' is true or false, not numbers, use NWInts instead, or something more efficient
[QUOTE=Mrkrabz;34552061]Yes, but bools can also be 1,2,3 etc?[/QUOTE]
true false 1 0
[QUOTE=AngryChairR;34552195]true false 1 0[/QUOTE]
Balls to it, Ill just use the old friend variable.
[QUOTE=Mrkrabz;34551790]How do you add 1 to network bool?
e.g
[lua]self.Entity:SetNWBool("fertlimit", +1)[/lua]
It was set at 0 on initialize.[/QUOTE]
Don't know why you're trying to add one, it can only be 0 or 1 so just set it to 1
[QUOTE=AngryChairR;34552219]Don't know why you're trying to add one, it can only be 0 or 1 so just set it to 1[/QUOTE]
I was using it for when to remove something, or when it = 5. But now coming to think about it a variable will be much easier.
If you don't need the clients knowing the variable you shouldn't be using the SetNW functions, at all.
[QUOTE=ArmageddonScr;34552375]If you don't need the clients knowing the variable you shouldn't be using the SetNW functions, at all.[/QUOTE]
?
Where did he say that?
Trying to get a
[lua]
ply:PrintMessage( HUD_PRINTCENTER, "Out of bounds!")
[/lua]
to appear when a player falls off of a stage, but only for the player. Putting this in init.lua will make everyone see it, but putting
[lua]
function player_initdeath( ply, wep, killer )
ply:PrintMessage( HUD_PRINTCENTER, "Out of bounds!")
end
hook.Add( "PlayerDeath", "player_initalize_dvars", player_initdeath );
[/lua]
into cl_init.lua under the derma does nothing.
[QUOTE=Pyth;34553102]Trying to get a
[lua]
ply:PrintMessage( HUD_PRINTCENTER, "Out of bounds!")
[/lua]
to appear when a player falls off of a stage, but only for the player. Putting this in init.lua will make everyone see it, but putting
[lua]
function player_initdeath( ply, wep, killer )
ply:PrintMessage( HUD_PRINTCENTER, "Out of bounds!")
end
hook.Add( "PlayerDeath", "player_initalize_dvars", player_initdeath );
[/lua]
into cl_init.lua under the derma does nothing.[/QUOTE]
You will need to define ply in init.lua, for example local ply = self.Entity.dt.owning_ent (This is for my entity) Then do
[lua]ply:PrintMessage( HUD_PRINTCENTER, "Out of bounds!")[/lua]
Where are you calling that in init.lua?
Sorry, you need to Log In to post a reply to this thread.