I am brand new to LUA and I am trying to show a hidden entity but I think I am doing something wrong. I can call the sound effect but not the entity?
Any help greatly appreciated
g_plrinzone = {}
function plrinzone_init(e)
end
function plrinzone_main(e)
if g_Entity[e]['plrinzone']==1 then
PlaySound(e,0)
Show(e,lightning)
Destroy(e)
PerformLogicConnections(e)
end
end
Related
What I am trying to do is the following : The player loads up my game, is greeted by 2 Text buttons asking, explore or play campaign, when they click for example 'Campaign' it teleport's them to the campaign start and then shuts the game menu, i am very new to Roblox Lua and can't get this script to work, please help!
script.Parent.MouseButton1Click:connect(function()
game.Players.LocalPlayer.character.LowerTorso.CFrame = CFrame.new(workspace.CampainSpawn.Position)
end)
function onClick()
Parent.Parent.Visible = false
end
The problem with your code is that you are not calling the onClick() function therefore it will never execute the code which makes your game menu invisible. Please tell me if the code below works for you:
script.Parent.MouseButton1Click:connect(function()
game.Players.LocalPlayer.character.LowerTorso.CFrame = CFrame.new(workspace.CampainSpawn.Position)
script.Parent.Parent.Visible = false
end)
If the code above does not work, please add a picture of the structure of the user interface in your original post as that will help me out a lot more.
recently I have been creating an imitation HarborRP gamemode for Garry's Mod, and I'm trying to recreate the Smuggler NPC (You'll know what I mean if you've ever played HarborRP) So basically I want the NPC to open ONE Derma-Frame window when the player presses their use key on it. I have the NPC created and all of that, but when the player simply presses their use key on the NPC, a million windows pop up, I have the NPC/Entity's use type set to SIMPLE_USE, but it seems like that doesn't matter because so many windows pop up. the VGUI/Derma Frame's settings is set to MakePopup() but that doesn't matter either. See if you can find whats wrong with it, I have very little knowledge of LUA.
init.lua file:
include("shared.lua")
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
util.AddNetworkString("smug")
hook.Add("PlayerUse", "menuu", function(ply, ent)
net.Start("smug")
net.Send(ply)
end)
function ENT:Initialize()
self:SetModel('models/humans/group01/female_01.mdl')
self:SetHullType(HULL_HUMAN)
self:SetHullSizeNormal()
self:SetNPCState(NPC_STATE_SCRIPT)
self:SetSolid(SOLID_BBOX)
self:SetUseType(SIMPLE_USE)
self:DropToFloor()
end
cl_init.lua file:
include("shared.lua")
function ENT:Draw()
self.Entity:DrawModel()
end
net.Receive("smug", function()
if( !frame ) then
local frame = vgui.Create("DFrame")
frame:SetSize(900,600)
frame:SetPos(ScrW()/2-450,ScrH()/2-300)
frame:SetVisible(true)
frame:MakePopup()
frame:SetDeleteOnClose(true)
elseif (frame) then print("HI")
end
end)
shared.lua file:
ENT.Base = "base_ai"
ENT.Type = "ai"
ENT.PrintName = "[DEV] Smuggler NPC"
ENT.Category = "InVaLiD's HBRP Entities"
ENT.Author = "InVaLiD"
ENT.Spawnable = true
ENT.AdminSpawnable = true
ENT.AutomaticFrameAdvance = true
Something To Note
All of these files are in the addons/smug_npc/lua/entities/ folder.
Yes, I know I have weird names for things, that's just me.
I have a basic to no knowledge of lua, so explain things please :)
I really do appreciate your help, and your will to help people, please know that I thank you all for being here just to sort other people's problems even though you could be spending your time doing something productive, Thank you!
You need to put your code that does net.Send into the entities ENT:Use function rather than on the PlayerUse hook.
function ENT:Use(ply)
net.Start("smug")
net.Send(ply)
end
The below line which you already have in your code in the initialize function makes the entity call the ENT:Use function once when a player presses E on it, which it seems that you want to do so that is good:
self:SetUseType(SIMPLE_USE)
Also, I recommend checking out the gmod forums if you need developer help in future.
GMod forums: https://gmod.facepunch.com/f
I am attempting to build my first game using love2D, I have hit a problem.
The game is a bubble popping game, I want to assign a bubble to each letter on the keyboard so that when a letter is pressed, the bubble will pop.
I have an external file called "bubble.lua" which I have tried to make an object "bubble" with.
to do that I have created a table "bubble" in the bubble.lua which contains functions and variables. Now, this file works when called from main.lua using just one bubble, however I am going to need 26 bubbles so I thought it would be best to store each bubble in another table. For the purpose of trying this I just stored one bubble using 1 as the key.This is where I have problems.
require "bubble"
local bubbles = {}
function love.load()
bubbles[1] = bubble.load(100, 100)
end
function love.draw()
for bubble in bubbles do
bubble.draw()
end
end
function love.keypressed(key)
bubbles[key].bubble.pop()
end
Firstly, I know that the for loop in love.draw() does not work, and the line "bubble[key].bubble.pop" seems to return nil as well
The for loop I can probably find the solution myself online, my main problem is the "bubble[key].bubble.pop()" line, I cannot work out what's wrong or how to fix it.
Can anybody help me?
You may want to look at this as well:
bubble.lua
bubble = {}
function bubble.load(posX, posY)
bubble.x = posX
bubble.y = posY
bubble.popped = false
end
function bubble.draw()
if not bubble.popped then
love.graphics.rectangle("line", bubble.x, bubble.y, 37, 37)
else
love.graphics.rectangle("line", bubble.x, bubble.y, 37, 100)
end
end
function bubble.pop()
bubble.popped = true
end
Edit:
Following the advice of the answer below I now have the following error when I press "a":
main.lua:14: attempt to index a nil value
the updated code is below
main.lua
require "bubble"
local bubbles = {}
function love.load()
bubbles["a"] = bubble.load(100, 100)
end
function love.draw()
for key, bubble in pairs(bubbles) do
bubble.draw()
end
end
function love.keypressed(key)
bubbles[key].pop()
end
any thoughts?
There are several issues with this code. First, you index by number when you initialize bubbles (bubbles[1]), but access them using the key as the index (bubbles[key]), which is NOT a number. You need to settle on one mechanism to index the bubbles. Let's say you picked using key as the index (instead of the number).
This loop:
for bubble in bubbles do
bubble.draw()
end
should be written as:
for key, bubble in pairs(bubbles) do
bubble.draw()
end
and instead of bubbles[key].bubble.pop() you can simply do bubbles[key].pop() as bubbles[key] already returns the bubble you can pop.
To initialize, instead of bubbles[1] you need to do bubbles['a'] (or whatever other value is used by key in love.keypressed(key)).
So, I’m having an issue while trying to split strings into tables (players into teams). When there are two players only, it works like a charm, but when there are 3+ players, this pops up: “Init Error : transformice.lua:7: bad argument: table expected, got nil”. Everything seems to be ok, I really don’t know what’s wrong. Can you guys please help me? Thanks! Here is my code:
ps = {"Player1","Player2","Player3","Player4"}
local teams={{},{},{}}
--[[for name,player in pairs(tfm.get.room.playerList) do
table.insert(ps,name)
end]]
table.sort(ps,function() return math.random()>0.5 end)
for i,player in ipairs(ps) do
table.insert(teams[i%#teams],player)
end
Lua arrays start at index 1, not 0. In the case of when you have 3 players this line:
table.insert(teams[i%#teams],player)
Would evaluate to:
table.insert(teams[3%3],player)
Which then would end up being:
table.insert(teams[0],player)
And teams[0] would be nil. You should be able to write it as:
table.insert(teams[i%#teams+1],player)
instead.
I have this image:
local core = display.newImage("images/core.png", (display.contentWidth/2), display.contentHeight/5)
And when something happened i do this:
spinCore()
Calling this function:
local function spinCore()
transition.to(core,{time=500,rotation=360})
end
This is working, but only the first time i do this, by the next ones it isn´t working. I hope you can help me. Thank you!
Just do like:
local function spinCore()
transition.to(core,{time=500,rotation=core.rotation+360})
end
Keep coding.................. :)