• Some Hooks wont work
    12 replies, posted
Hi all, I am currently working on a gamemode so i have to use some hooks. My problem now is, that some hooks are working as they should, for example thisone: [code] function GM:PlayerInitialSpawn( ply ) //When player connects, the teammenu will pop up ply:StripWeapons() ply:ConCommand( "sg_team" ) end [/code] and some others dont work, at the moment these two: [code] function GM:PlayerCanPickupWeapon(ply, item) //Player only picks up what is his --Dont work, but no guess why :( if ply:Team() == 1 then if item:GetClass() == "weapon_p90" then return true elseif item:GetClass() == "weapon_beretta" then return true else return false end elseif ply:Team() == 2 then if item:GetClass() == "healkit" then return true elseif item:GetClass() == "weapon_beretta" then return true else return false end elseif ply:Team() == 3 then if item:GetClass() == "stunner_big" then return true elseif item:GetClass() == "wraith_hand" then return true else return false end elseif ply:Team() == 5 then if item:GetClass() == "replicator_sword" then return true elseif item:GetClass() == "replicator_sword_tauri" then return true elseif item:GetClass() == "replicator_sword_wraith" then return true else return false end elseif ply:Team() == 6 then if item:GetClass() == "replicator_claws" then return true else return false end else return false end end function NoFalldamage_human( ply, hitgroup, dmginfo ) //Replicators dont take fall damage PrintMessage( HUD_PRINTTALK, ply:Nick() .. " got falldmg!" ) if ( dmginfo:IsFallDamage() and ply:Team()==5 ) then dmginfo:SetDamage( 0 ) end end hook.Add("ScalePlayerDamage","NoFalldamage_human",NoFalldamage_human) [/code] The console dont shows any relevants errors. But if you want to check it on your own here is the consolelog: [quote] maxplayers set to 8 Can't load pure server whitelist in pure_server_whitelist.txt. Caching file CRCs for pure server... Finished caching file CRCs for pure server in 0 seconds. Lua initialized (Lua 5.1) Couldn't include file 'death_system.lua' (File not found) Registering gamemode 'SGMODE' derived from 'base' ScriptEnforce is disabled Compressing lua files into data pack.. Skipped. Datapack exists. Executing listen server config file exec: couldn't exec listenserver.cfg [L] SGMODE Map: gm_construct Players: 1 / 8 Build: 4394 Server Number: 10 Got pure server whitelist: sv_pure = 1. CMaterial::PrecacheVars: error loading vmt file for decals/egonburn CMaterial::PrecacheVars: error loading vmt file for decals/egonburn InitFastCopy: only 51% fast props. Bug? CMaterial::PrecacheVars: error loading vmt file for decals/egonburn Decompressing data pack into virtual file system.. Data pack loaded: 217 files. (0.049s) Lua initialized (Lua 5.1) Registering gamemode 'SGMODE' derived from 'base' Sending 8 'User Info' ConVars to server (cl_spewuserinfoconvars to see) Connection to Steam servers successful. VAC secure mode is activated. [R2P] Obstsalat aka Kokosnuss joined the spectaters! CMaterial::PrecacheVars: error loading vmt file for decals/egonburn Redownloading all lightmaps You joined the replicators as a replicator! [R2P] Obstsalat aka Kokosnuss joined the replicators as a replicator! [/quote] The hooks dont working acts like wouldnt they exist. I am a little bit frustrated because of that so i hope somebody here can help me.
I trust the comment doesnt spill over to the next line in the code? And you're also missing a lot of ends. Example: [code]if ply:Team() == 1 then -- one end needed if item:GetClass() == "weapon_p90" then --two ends needed return true elseif item:GetClass() == "weapon_beretta" then -- 3 needed return true else return false end -- Yet only one end. [/code]
Correct @ Comments. He has the correct number of Ends. if x elseif elseif elseif end Only need one end statement due to the elseif's. Same with the interior if/elseif statements.
If you have any addons that use PlayerCanPickupWeapon as a hook, they may be returning values and preventing your gamemode function from running.
Which means that this should work: [code]var = 1 if (var != 1) then if var = 1 then Msg("You dun goofed") end[/code] But it spits "[lua\test.lua:8] 'end' expected (to close 'if' at line 2) near '<eof>'" I'll admit, elseifs don't need their own ends.
if != elseif
[QUOTE=Amokov;26555254]Which means that this should work: [code]var = 1 if (var != 1) then if var = 1 then Msg("You dun goofed") end[/code] But it spits "[lua\test.lua:8] 'end' expected (to close 'if' at line 2) near '<eof>'" I'll admit, elseifs don't need their own ends.[/QUOTE] You should really take a look at the basics again.
That code is so wrong, it'd never do anything, even if it did have the right number of ends.
[b][url=http://wiki.garrysmod.com/?title=LUA:Gamemode_from_scratch]This[/url][/b] tutorial uses it once; should be edited.
[QUOTE=thejjokerr;26560125]Why would you do that? Concommands are there so you can communicate with the server. If you are in a script, already on the server, then what's the point of running another console command? Just use functions.[/QUOTE] I use that conCommand to create a clientside menu. i dont know how i can otherwise send instructions to clientside. But thats now not the point. These are the whole functions and i throwed out all other addons so there cant be any other addon who is conflicting with mine. I already reinstalled gmod, so there isnt any "trash" of older addons who can make problems.
[QUOTE=Obstsalat;26560320]I use that conCommand to create a clientside menu. i dont know how i can otherwise send instructions to clientside. But thats now not the point. These are the whole functions and i throwed out all other addons so there cant be any other addon who is conflicting with mine. I already reinstalled gmod, so there isnt any "trash" of older addons who can make problems.[/QUOTE] [url]http://wiki.garrysmod.com/?title=Networking_Variables[/url] As a test, put [lua]print ("hi")[/lua] at the start of each function, and see if it prints when you do something that activates the hook, if it doesn't then there's something wrong with the hook.
[QUOTE=Zephilinox;26567620][url]http://wiki.garrysmod.com/?title=Networking_Variables[/url] As a test, put [lua]print ("hi")[/lua] at the start of each function, and see if it prints when you do something that activates the hook, if it doesn't then there's something wrong with the hook.[/QUOTE] Just done, it isnt printed : /
Sorry, you need to Log In to post a reply to this thread.