I'm trying to spawn custom particles in a gamemode hook (serverside) with ParticleEffectAttach. Hook runs with no errors, but particles aren't spawned. When I spawn them with console command (serverside), they are working fine. I'M DUMB.
game.AddParticles("particles/custom.pcf") -- SHARED
PrecacheParticleSystem("custom_particle") -- SHARED
-- SERVERSIDE BELOW
hook.Add("OnEvent", "Particle", function(ply, arg2, ...)
print(ply, arg2, ...) -- WORKING
ParticleEffectAttach("custom_particle", PATTACH_POINT, ply, 1) -- NOT WORKING
end)
concommand.Add("pattach", function(ply)
ParticleEffectAttach("custom_particle", PATTACH_POINT, ply, 1) -- WORKING
end)
http://lua-users.org/wiki/ForTutorial
it probably doesn't mention it in the tutorial but those loops are incredibly useful
I added a thing to the code that sort of works:
ent:SetPos( self.Owner:EyePos() + ( self.Owner:GetAimVector() * 32 ) + ( i * 4 ) )
The important bit is:
i * 4
That means that:
When i is 1 it will add 4
When i is 2 it will add 8
When i is 3 it will add 12
So by the time it spawns the third object, it will be 12 extra units along.
You can increase or decrease this value to add larger or smaller amounts.
Does anyone know of an easy way to upload an image to Imgur using HTTP.Post?
I understand this is the method some of those screencap addons use, rather than using the server to send the image.
This is my first time messing with Post requests, and I am a bit lost. Thanks!
https://api.imgur.com/endpoints/image/#image-upload
So I guess
http.Post( "https://api.imgur.com/3/image", { image = "base64data" } )
Yes. You can do it in a for loop:
for i = 1, 3 do
local ent = ...
ent:...()
end
Then you can change the number of entities just by changing the 3 to, say, 5.
I GOT THE IMGUR THING TO WORK!!!
local data = render.Capture( {
format = "jpeg",
quality = 100,
x = 0,
y = 0,
w = ScrW(),
h = ScrH()
} )
http.Post( "https://api.imgur.com/3/image", {
image = util.Base64Encode( data )
}, function( response )
print( response )
gui.OpenURL( util.JSONToTable( response ).data.link )
end, function( failed )
print( failed )
end, {
Authorization = "Client-ID <CLIENT_ID>"
} )
It works if you replace <CLIENT_ID> with your Client ID.
You can get a Client ID by registering here.
Select "OAuth 2 authorization without a callback URL" and it'll work.
Cool! You can make the Client ID a convar (with archive so it saves) so users don't have to edit Lua files too.
Users never set the client id, the developer sets the client id and the users never touch it. Clients don't need to be involved with it unless you want it to be unanonymous.
Oh! I understand it now, thank you very much for the help!
I can't promise I'm right here, but I'd assume if you do something like this
local ent1 = ents.Create( "prop_physics" )
local ent2 = nil
local ent3 = nil
if ( !IsValid(ent1) ) then return end
ent1:SetModel(model_file)
local ent2 = ent1
local ent3 = ent1
local newents = ent2, ent3
if ( !IsValid(newents) ) then return end
ent1:SetPos(self.Owner:EyePos() + (self.Owner:GetAimVector() * 32 ))
ent1:SetAngles(self.Owner:EyeAngles())
ent1:Spawn()
ent2:SetPos(self.Owner:EyePos() + (self.Owner:GetAimVector() * 40 ))
ent2:SetAngles(self.Owner:EyeAngles())
ent2:Spawn()
ent3:SetPos(self.Owner:EyePos() + (self.Owner:GetAimVector() * 48 ))
ent3:SetAngles(self.Owner:EyeAngles())
ent3:Spawn()
My thought is, since you set up ent1 first... saying ent2 = ent1 would essentially duplicate it. But I may be wrong and this might cause errors, idk... you could also change ent2 and ent3's models after declaring them if I'm right.
Quick question: Is there an easy way to get the relative angles between two props?
I am trying to make an entity that is composed of several prop models parented to the main ent, like how those cool drones on the workshop are put together, but I can't seem to find any way of positioning the parented models short of just messing around with the values like this:
movingPlate:SetPos(self:GetPos()+(self:GetUp()*28)+(self:GetForward()*-18)+(self:GetRight()*-1));
I've tried building a mockup of the entity out of actual props and then recording the positions of each part and trying to reconstruct it in lua that way, but that didn't really work.
And I seem to be making really slow progress doing it the 'normal' way. Is there some sort of tool people use for this that I am not privy to? There has to be an easier way. Thanks again!
A quick question that I think can be answered pretty fast-
Can you use the same Network String to send a message to the server as sending a message to the client, or would this cause problems? Also, yes, I know that sending messages to the server should not be taken lightly. I have very specific criteria the message must follow for it to even be considered.
You can.
Thanks! Yet again, sorry to bother, I have an error with this:
I'm trying to store data for a line in a table.
local thisline = {
linestartx = gui.MouseX(),
linestarty = gui.MouseY(),
lineendx = lastposx,
lineendy = lastposy
}
It expects the table to close on the third line, like this
local thisline = {
linestartx = gui.MouseX()
}
The error is:
'}' expected (to close '{' at line 33) near 'linestarty'
I'm out of ideas.
Try restarting your server/client?
By the arms of simmered monkey it actually worked.
Thanks, i guess?
YI believe you cannot do that since you don't know for sure that the ammo you use for one weapon isn't being used by another weapon.
ply:GiveAmmo(howMuch, ply:GetActiveWeapon():GetPrimaryAmmoType())
where 'ply' is the player in question and 'howMuch' is how much ammo to give. Make sure the weapon exists to avoid errors
GetActiveWeapon can return null if the player doesn't have any weapon active. You can check with IsValid:
local pWeapon = ply:GetActiveWeapon()
if (pWeapon:IsValid()) then
-- Code
end
Hello the problem i have is i have this code wrapped in if CLIENT in a autorun folder and and when i try to
call the method from a other addon it doesnt work.Error is: cl_init.lua:9: attempt to call method 'IsOnQuest' (a nil value)
local meta = FindMetaTable("Player")
function meta:IsOnQuest(ply)
if meta:GetPData("quest") then return true
else
return false
end
IsOnQuest is not a method for metatables.
If you wish to make a custom function with metatable context, use blahblahblah(metatable, args)
Make sure the file is actually being sent to clients and loaded. My first guess is that's your initial problem.
Also your function will have a runtime error once it actually does get ran. Remove ply from the arguments for meta:IsOnQuest() as you don't need it, and then change this:
meta:GetPData("quest")
to this:
self:GetPData("quest")
self is how you reference the calling object within a metafunction.
How can I change the current weapon of an NPC? It is done quite easily in the Sandbox C menu.
NPC:Give
So I've heard that using lights is laggy. I plan to use them extensively for a thing I'm making.
Is it graphical lag or net lag that people are concerned about?
FPS drops
Use a lower percentage, screen coordinates start on the top left going to bottom right. So for example using a screen width of 1920, the box would appear at 1718. If you changed your percentage to say 0.1, it would appear at 192.
Y represents how low it is (a positive number) under the top of the screen, and X is- well, X.
You can use static values like ScrW() - 20, to place the top left corner 20 pixels from the right edge of the screen, or just 20 to be 20 pixels from the left edge. Nobody is going to have a 20x20 screen resolution, after all.
Sorry, you need to Log In to post a reply to this thread.