• What do you need help with V4
    639 replies, posted
"Player X touched a prop." Is there any way to make that happen? Print message when player touches a prop (barrel for exsample).
[QUOTE=cixu2;36089885]"Player X touched a prop." Is there any way to make that happen? Print message when player touches a prop (barrel for exsample).[/QUOTE] [url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexcdb2.html?title=ENT.Touch[/url] or.. [url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexbf26.html?title=ENT.PhysicsCollide[/url] [QUOTE=DarthTealc;36087960]Is there a way to see the name/id of the spray a player has sprayed? I know you can hook the spray event ([URL="http://bananatree.im/wiki/wiki.garrysmod.com/indexafb8.html?title=Gamemode.PlayerSpray"]wiki link[/URL]) but you'd only be able to get the player object from that, not the spray id. By "spray id", I'm talking about the hex string used as the filename (eg "f15c8155.vtf") The reason I'm asking is that I want to code a tool to allow server administrators to see who sprayed what spray. A vgui panel would have all the currently sprayed sprays displayed (by displaying the material in "materials/temp" folder), and the player name and Steam ID of the player who sprayed it. But I can't figure out how to get the spray ID when a player sprays. Any tips?[/QUOTE] Try running a trace when the player sprays, gathering the vector where the spray is like this: SprayVectors[PLAYER:SteamID] = PLAYER:GetEyeAngles( ).HitPos [QUOTE=ashrobhoy;36087887]I need help with "Entity:Set" how would i make it set HEV suit power i have tryed Entity:Setarmor / suit but cannot figure it out[/QUOTE] Maybe try doing: Entity:SetArmor( <Amount> ) Please replace "<Amount>" with the actual amount.
I'm trying to find a way to display text over an entity dropped by an npc. Right now I have everything working (in earlier stages, I have plans on expanding it) except for the names displaying of the items. Keep in mind, I'm new'ish to Lua (coming from a lot of experience in Java and C#) [code] AddCSLuaFile("cl_init.lua") PrintMessage(HUD_PRINTTALK, "Preparing loot drops") local maps = {"gm_construct", "gm_flatgrass"} function NPCKilled( victim, killer, weapon ) local randomNumber = math.random(1,3) local npcPos = victim:GetPos() local spawnHeight = 128 -- Kill Counter PrintMessage(HUD_PRINTTALK, killer:GetNWInt("killcounter") + 1) if killer:GetNWInt("killcounter") == 50 then timer.Simple(3, function() game.ConsoleCommand("changelevel " ..table.Random(maps).. "\n") end) end killer:SetNWInt("killcounter", killer:GetNWInt("killcounter") + 1) -- Drop Loot if randomNumber == 1 then local drop = ents.Create("weapon_pistol") drop:SetPos(npcPos + Vector(0,0,spawnHeight)) local lootPos = drop:GetPos() + Vector(0,0,32) local lootScreenPos = lootPos:ToScreen() surface.SetTextColor(200, 25, 25, 100) surface.SetFont("Trebuchet18") surface.SetTextPos(tonumber(lootScreenPos.x), tonumber(lootScreenPos.y)) surface.DrawText("Test text of loot") drop:Spawn() drop:Activate() end end hook.Add("OnNPCKilled", "KillCounter", NPCKilled) [/code] Now I know the code wont update the text to match that of the items if it was to move, but I just wanted a proof of concept. Edit: What's the BB Code for Lua syntax highlighting?
This glitch is driving me crazy, I can't freaking find a logical reason to why it happens. I have a ply:Give() function that works 70% of the time. For some reason, sometimes it just doesn't gives the user the weapon, no console error or nothing, i just doesn't fucking gives the user the gun, anyone else is having this problem too? Anyone knows which under circunstances that function may not work? Note: the code is right, it sometimes works perfectly, others it doesn't... Other question, functions like [b][url=wiki.garrysmod.com/?title=Gamemode.ScalePlayerDamage]Gamemode.ScalePlayerDamage [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] and [b][url=wiki.garrysmod.com/?title=Gamemode.PlayerDeath]Gamemode.PlayerDeath [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] have arguments that give you the inflictor of the damage, aka The weapon used to deal the damage, but, for god sake of the incovenience, these arguments always retrieve "player" when the damage was dealt by a weapon that uses shootbullets(HL 2 weps, CSS weps...), anyone know how to get the real weapon?
[QUOTE=DoubleElite;36094201]I'm trying to find a way to display text over an entity dropped by an npc. Right now I have everything working (in earlier stages, I have plans on expanding it) except for the names displaying of the items. Keep in mind, I'm new'ish to Lua (coming from a lot of experience in Java and C#) [code] AddCSLuaFile("cl_init.lua") PrintMessage(HUD_PRINTTALK, "Preparing loot drops") local maps = {"gm_construct", "gm_flatgrass"} function NPCKilled( victim, killer, weapon ) local randomNumber = math.random(1,3) local npcPos = victim:GetPos() local spawnHeight = 128 -- Kill Counter PrintMessage(HUD_PRINTTALK, killer:GetNWInt("killcounter") + 1) if killer:GetNWInt("killcounter") == 50 then timer.Simple(3, function() game.ConsoleCommand("changelevel " ..table.Random(maps).. "\n") end) end killer:SetNWInt("killcounter", killer:GetNWInt("killcounter") + 1) -- Drop Loot if randomNumber == 1 then local drop = ents.Create("weapon_pistol") drop:SetPos(npcPos + Vector(0,0,spawnHeight)) local lootPos = drop:GetPos() + Vector(0,0,32) local lootScreenPos = lootPos:ToScreen() surface.SetTextColor(200, 25, 25, 100) surface.SetFont("Trebuchet18") surface.SetTextPos(tonumber(lootScreenPos.x), tonumber(lootScreenPos.y)) surface.DrawText("Test text of loot") drop:Spawn() drop:Activate() end end hook.Add("OnNPCKilled", "KillCounter", NPCKilled) [/code] Now I know the code wont update the text to match that of the items if it was to move, but I just wanted a proof of concept. Edit: What's the BB Code for Lua syntax highlighting?[/QUOTE] [lua]if randomNumber == 1 then local drop = ents.Create("weapon_pistol") drop:SetPos(npcPos + Vector(0,0,spawnHeight)) local lootPos = drop:GetPos() + Vector(0,0,32) local lootScreenPos = lootPos:ToScreen() surface.SetTextColor(200, 25, 25, 100) surface.SetFont("Trebuchet18") surface.SetTextPos(tonumber(lootScreenPos.x), tonumber(lootScreenPos.y)) surface.DrawText("Test text of loot") end[/lua] It's probably not working because this needs to be clientside.
[QUOTE=Stillnex;36094719]This glitch is driving me crazy, I can't freaking find a logical reason to why it happens. I have a ply:Give() function that works 70% of the time. For some reason, sometimes it just doesn't gives the user the weapon, no console error or nothing, i just doesn't fucking gives the user the gun, anyone else is having this problem too? Anyone knows which under circunstances that function may not work? Note: the code is right, it sometimes works perfectly, others it doesn't... Other question, functions like [b][url=wiki.garrysmod.com/?title=Gamemode.ScalePlayerDamage]Gamemode.ScalePlayerDamage [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] and [b][url=wiki.garrysmod.com/?title=Gamemode.PlayerDeath]Gamemode.PlayerDeath [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] have arguments that give you the inflictor of the damage, aka The weapon used to deal the damage, but, for god sake of the incovenience, these arguments always retrieve "player" when the damage was dealt by a weapon that uses shootbullets(HL 2 weps, CSS weps...), anyone know how to get the real weapon?[/QUOTE] Not sure why it would retrieve the player instead of the entity, it should be getting both. But I guess you could try [lua] player:GetActiveWeapon() [/lua] but It 'should' be getting the entity, in which case you could just use [lua] entity:GetName() [/lua] If you could post the code in question, that would be great.
[QUOTE=Stillnex;36094719]This glitch is driving me crazy, I can't freaking find a logical reason to why it happens. I have a ply:Give() function that works 70% of the time. For some reason, sometimes it just doesn't gives the user the weapon, no console error or nothing, i just doesn't fucking gives the user the gun, anyone else is having this problem too? Anyone knows which under circunstances that function may not work? Note: the code is right, it sometimes works perfectly, others it doesn't... Other question, functions like [b][url=wiki.garrysmod.com/?title=Gamemode.ScalePlayerDamage]Gamemode.ScalePlayerDamage [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] and [b][url=wiki.garrysmod.com/?title=Gamemode.PlayerDeath]Gamemode.PlayerDeath [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] have arguments that give you the inflictor of the damage, aka The weapon used to deal the damage, but, for god sake of the incovenience, these arguments always retrieve "player" when the damage was dealt by a weapon that uses shootbullets(HL 2 weps, CSS weps...), anyone know how to get the real weapon?[/QUOTE] Giving weapons: [lua] function GiveWeapons(ply) ply:Give("weapon_crowbar") end concommand.Add("give_cbar", GiveWeapons) [/lua] Best way I found: [lua] local WeaponName = weapon:GetClass() or "unknown" [/lua] Full code if you want: [lua] function GM:PlayerDeath(victim, weapon, killer) //DarkRP does this well if weapon:IsVehicle() and weapon:GetDriver():IsPlayer() then killer = weapon:GetDriver() end local KillerName = (killer:IsPlayer() and killer:Nick()) or killer:GetClass() if KillerName == "prop_physics" then KillerName = killer.Owner and killer.Owner:Nick() or "unknown" end local WeaponName = weapon:GetClass() or "unknown" if WeaponName == "prop_physics" then WeaponName = weapon:GetClass() .. " (" .. weapon:GetModel() or "unknown" .. ")" end for k,v in pairs(player.GetAll()) do if v:IsAdmin() and victim == killer then v:PrintMessage(HUD_PRINTCONSOLE, victim:Nick().." suicided.\n") elseif v:IsAdmin() then v:PrintMessage(HUD_PRINTCONSOLE, victim:Nick().." was killed by "..KillerName.." with ".. WeaponName..".\n") end end victim:Extinguish() if victim:InVehicle() then victim:ExitVehicle() end end [/lua]
Trying to find the best way of creating an object and then for the object to randomly appear and move from PointA to PointB I have this that I thought of [lua]Object:setPos((pointB - pointA):normalized() * SPEED)[/lua] I don't even know if normalized() is something used in lua but I'm needing the object to move smoothly from pointA to pointB What's the best way to do this?
[QUOTE=DoubleElite;36097956] -snip- [/QUOTE] I used the player:GetCurrentWeapon(), thanks. About the Give(), I had a StripWeapons() before, it must have been glitching with the Give() so I decided to remove the player weapons by going through the player weps and removing the ones needed. [QUOTE=brandonj4;36100513] -snip- [/QUOTE] the syntax was right, but probably there was a conflcit with a StripWeapons() I had.
Just wondering if anyone here could maybe explain to me how to use the sound.add(table) function in Gmod13 to find sound script files so custom scripted sounds can work.
Anyone know how you can get the current GMod version in Lua? Edit: Got it, the VERSION global, problem is it says 131, I thought the latest version was 133?
Getting an error "line blah erroed 'dt' is a nil value" while I am using self.dt.blah = blah in ENT:Initialize() Someone know why this happens? I did SetupDatatables in shared
Are you sure SetupDatatables is called before that code runs?
Are you sure SetupDatatables is called before that code runs?
[QUOTE=ralle105;36108541]Are you sure SetupDatatables is called before that code runs?[/QUOTE] Yeah, I don't know, but how I am supposed to set the player a datatable if I have to: [lua] function GM:PlayerSpawn( ply ) self.BaseClass:PlayerSpawn( ply ) if ( !ply:IsValid() && !ply:IsOnGround() && !ply:IsInWorld() ) then return end local SpawnPos = ply:GetPos() + Vector(0, 0, 20) local fairy = ents.Create("fairy_player") fairy:SetPos( SpawnPos ) fairy:SetAngles(Angle(0, math.random(0,360), 0)) fairy:SetRenderMode(1) fairy:Spawn() fairy:Activate() ply:StripWeapons() ply:SetMoveType( MOVETYPE_OBSERVER ) ply:Spectate( OBS_MODE_CHASE ) ply:SpectateEntity( fairy ) ply:CrosshairDisable() fairy:SetName("Fairy_".. string.gsub(ply:SteamID(), ":", "_")) fairy.maxSpeed = 160 fairy.user = ply fairy.name = fairy.user fairy:SetDTEntity(0, ply) end[/lua] I am outside the Sents code. And when I go into ENT:Initialize() I can't get the player
Initialize is called when you invoke fairy:Spawn( ). You need to set the player before you try to access it.
[QUOTE=Kogitsune;36110152]Initialize is called when you invoke fairy:Spawn( ). You need to set the player before you try to access it.[/QUOTE] nvm.. I used NWString. But another question, where do I have to look for an graphic specialist? I need a better background for my HUD: [IMG]http://puu.sh/x6lM[/IMG] The fairy on the bottom left is rendered by me and coloured like your fairy. It is your healthbar. (Fairy colour goes down when your health decreased and it turns gray.) I thought about black borders at top and bottom but it turned out to look very creepy. So I am searching for one guy who could make me those two coloured lines in my screenshot: A 400x400 *.png background for the blue line and the red line. The background shouldn't be so strict formed as it's there, it should be filled with fantasy and abstract forms like in the bg of [url='http://www.moonmentum.com/blog/wp-content/uploads/2010/09/fairy_wallpaper_by_tryncess.jpg']this[/url] pic. Should I search somewhere else?
Hey, I'm having a problem with my code for darkrp, for some reason when I type the command in game, it wont work. Yet I see nothing wrong with the code? The code is supposed to be a command which you type to disguise yourself, aka reskin yourself temporarily. You type /disguise again to remove it and go to your normal state [CODE] local function DisguisePlayer( p, c, a ) if not ( p:Team( ) == TEAM_TERRORIST ) then Notify( p, 1, 4, "You must be a Terrorist to Disguise!" ) return "" end if p.IsDisguise then GAMEMOD:PlayerSetModel( p ) p.IsDisguise = false p:ChatPrint( "You have removed the Disguiser!" ) else p:SetModel( "models/player/Group01/male_03.mdl" ) p.IsDisguise = True p:ChatPrint( "You Have Disguised!" ) end return "" end AddChatCommand( "/disguise", DisguisePlayer )[/CODE] Can someone help me please?
"it won't work" helpful [editline]28th May 2012[/editline] aka tell us what doesn't work
[QUOTE=Banana Lord.;36112969]"it won't work" helpful [editline]28th May 2012[/editline] aka tell us what doesn't work[/QUOTE] Lol I figured I was being to vague. However, that's all there is. I type /disguise in game and nothing happens. It just litterly types "/disguise" in chat, without executing it. No lua errors, nothing in console.
for starters GAMEMOD:PlayerSetModel( p ) should be GAMEMODE, not GAMEMOD
[QUOTE=Banana Lord.;36113454]for starters GAMEMOD:PlayerSetModel( p ) should be GAMEMODE, not GAMEMOD[/QUOTE] That was just a typo from me typing it onto the forums.
I have a hopefully quick question, what is the function of "render.CopyTexture(from, to)"? I've tried playing around with it, to copy a renderer to a texture, but failed: [code]local from = GetRenderTarget("GModToolgunScreen", 256, 256) local to = Material("ash47/mytexture"):GetMaterialTexture("$basetexture") render.CopyTexture(from, to)[/code] Obviously I'm doing something wrong, feel free to tell me what I'm missing... Edit: I'm simply running this code as is, using lua_openscript_cl, perhaps it needs to be in a hook somewhere?
Simple and straight to the point question- can you run a mysqloo query when there is no active player on the server? Some people tell me you can, some people tell me you can't.. the tests I did say you can't but I might be doing something wrong. [editline]29th May 2012[/editline] Note thats for [b]mysqloo[/b] not tmysql.
[QUOTE=zzaacckk;36121724]Simple and straight to the point question- can you run a mysqloo query when there is no active player on the server? Some people tell me you can, some people tell me you can't.. the tests I did say you can't but I might be doing something wrong. [editline]29th May 2012[/editline] Note thats for [b]mysqloo[/b] not tmysql.[/QUOTE] Yes, just run it on the Database:OnConnected function.
[QUOTE=Alex_grist;36121767]Yes, just run it on the Database:OnConnected function.[/QUOTE] I've tried, would you like to see the code?
[QUOTE=zzaacckk;36121724]Simple and straight to the point question- can you run a mysqloo query when there is no active player on the server? Some people tell me you can, some people tell me you can't.. the tests I did say you can't but I might be doing something wrong. [editline]29th May 2012[/editline] Note thats for [b]mysqloo[/b] not tmysql.[/QUOTE] You can't until the first player has joined, if a player joins and then leaves you can still run queries with no players, but you can't run any queries between the server starting up and the first player joining. [editline]29th May 2012[/editline] But it will save the queries you try and run and run them all when the first player joins.
[QUOTE=Drakehawke;36121808]You can't until the first player has joined, if a player joins and then leaves you can still run queries with no players, but you can't run any queries between the server starting up and the first player joining. [editline]29th May 2012[/editline] But it will save the queries you try and run and run them all when the first player joins.[/QUOTE] Actually, I just found out I am wrong. If you synchronize the queries in the main thread it will work (but it dosent matter because no players are in the server).
I'm having issues with getting the players current team in a clientside script. I'm using LocalPlayer():Team() for a derma panel in cl_init. I get this: [code][gamemodes\kush\gamemode\cl_init.lua:78] attempt to call method 'Team' (a nil value)[/code] Is there another way I should be doing this? I'm basically doing "if LocalPlayer():Team() == 1 then". I saw it being used here: [url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index4cc3.html?title=Fretta_Derma_Panel[/url]
[QUOTE=kp3;36122998]I'm having issues with getting the players current team in a clientside script. I'm using LocalPlayer():Team() for a derma panel in cl_init. I get this: [code][gamemodes\kush\gamemode\cl_init.lua:78] attempt to call method 'Team' (a nil value)[/code] Is there another way I should be doing this? I'm basically doing "if LocalPlayer():Team() == 1 then". I saw it being used here: [url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index4cc3.html?title=Fretta_Derma_Panel[/url][/QUOTE] Team shouldn't be nil, that would mean the thing you're calling it on isn't a player, which would be LocalPlayer(). You'll have to post more code if you want any more help.
Sorry, you need to Log In to post a reply to this thread.