Can anybody tell me if this will work and if not fix it or explain what I should do to make it work.
[CODE]pos1 = (1,2,3)
pos2 = (1,2,3)
plypos == arrestedply:GetPos()
function playerArrested( arrestedply, time, actor)
if arrestedply:IsPlayer() and plypos:WithinAABox( pos1, pos2 ) then
arrestedply:unArrest()
end[/CODE]
The code is syntactically and functionally incorrect. Can you give a detailed explanation of when you want the code to be run and what it should do?
Its supposed to unarrest a player in a certain area.
You should at least try before just expecting people to spoonfeed you.
First off pos1, and pos2 should not be global, especially with those variable names. They need to be localized and given more unique names.
Second plypos also needs to be local, and won't even work outside of the function you have defined.
Third your if statement is missing an end, or your function is missing an end. Regardless you need an end.
Finally playerArrested won't be called upon anything since there is no hook. You'd need to hook into this.
[url]http://wiki.darkrp.com/index.php/Hooks/Server/playerArrested[/url]
Your function also should not be global, and needs a more unique name.
I now have this.
[CODE]local posi1 == (1,2,3)
local posi2 == (1,2,3)
local plyposi == arrestedply:GetPos()
hook.Add("playerArrested", "isplayerarrested" , function(arrestedply, time ,actor)
if arrestedply:IsPlayer() and plyposi:WithinAABox(•pos1,•pos2•) then
arrestedply:unArrest()
end[/CODE]
[QUOTE=Nookyava;52487079]You should at least try before just expecting people to spoonfeed you.
First off pos1, and pos2 should not be global, especially with those variable names. They need to be localized and given more unique names.
Second plypos also needs to be local, and won't even work outside of the function you have defined.
Third your if statement is missing an end, or your function is missing an end. Regardless you need an end.
Finally playerArrested won't be called upon anything since there is no hook. You'd need to hook into this.
[url]http://wiki.darkrp.com/index.php/Hooks/Server/playerArrested[/url]
Your function also should not be global, and needs a more unique name.[/QUOTE]
I would do it by checking all players in Think every few seconds if they are arrested and outside of the jail bounds.
[editline]19th July 2017[/editline]
I would read this before continuing on your project: [url]https://www.lua.org/manual/5.3/manual.html[/url]
Other than implementation, you have syntax issues in your variable declaration.
I would only do it on arrested players and I wouldn't want the think to be slow enough for it to be noticeable nor fast enough to cause the server to lag
[QUOTE=Bear1ySane;52487235]I would only do it on arrested players and I wouldn't want the think to be slow enough for it to be noticeable nor fast enough to cause the server to lag[/QUOTE]
A cooldown of 1 second should be fine then.
What are the syntax issues?
[QUOTE=Bear1ySane;52487247]What are the syntax issues?[/QUOTE]
[code]local posi1 == (1,2,3) -- Variable declarations use single-equals, not double
local posi2 == (1,2,3) -- You need to have "Vector" in front of the parenthesis - it's a function call where you are sending in x, y, and z
local plyposi == arrestedply:GetPos() -- arrestedply isn't defined here. You can't cache this outside of the hook
hook.Add("playerArrested", "isplayerarrested" , function(arrestedply, time ,actor)
if arrestedply:IsPlayer() and plyposi:WithinAABox(•pos1,•pos2•) then -- Weird dots here? Might be a Facepunch editor issue
arrestedply:unArrest()
end
-- Missing an end)[/code]
[QUOTE=code_gs;52487371][code]local posi1 == (1,2,3) -- Variable declarations use single-equals, not double
local posi2 == (1,2,3) -- You need to have "Vector" in front of the parenthesis - it's a function call where you are sending in x, y, and z
local plyposi == arrestedply:GetPos() -- arrestedply isn't defined here. You can't cache this outside of the hook
hook.Add("playerArrested", "isplayerarrested" , function(arrestedply, time ,actor)
if arrestedply:IsPlayer() and plyposi:WithinAABox(•pos1,•pos2•) then -- Weird dots here? Might be a Facepunch editor issue
arrestedply:unArrest()
end
-- Missing an end)[/code][/QUOTE]
Yeah those dots are meant to be spaces
[editline]19th July 2017[/editline]
[CODE]local pos1 = Vector(1,2,3)
local pos2 = Vector(1,2,3)
hook.Add("playerArrested", "isplayerarrested" , function(arrestedply, time ,actor)
plypos = arrestedply:GetPos()
if arrestedply:IsPlayer() and plypos:WithinAABox(•pos1,•pos2•) then
arrestedply:unArrest()
end
end) [/CODE]
[QUOTE=code_gs;52487218]I would do it by checking all players in Think every few seconds if they are arrested and outside of the jail bounds.
[editline]19th July 2017[/editline]
I would read this before continuing on your project: [url]https://www.lua.org/manual/5.3/manual.html[/url]
Other than implementation, you have syntax issues in your variable declaration.[/QUOTE]
Honestly you could avoid doing a think hook by just popping a unique timer on the arrest player using the arrest hook, and use it to check every few seconds to see if they're in bounds. That's how I'd handle it.
I obviously did something wrong.
[CODE]---------------- Config ----------------
local pos1 = Vector( -1416, 142, -131)
local pos2 = Vector( -1371, 53, -56)
---------------- Config ----------------
function IsThePlyArrested( arrestedply, time, actor)
plypos = arrestedply:GetPos()
if arrestedply:IsPlayer() and plypos:WithinAABox( pos1, pos2 ) then
arrestedply:unArrest()
end
end)
hook.Add("playerArrested", "isplayerarrested" , IsThePlyArrested)
timer.Create( "playerinbounds", 1, 0, function("arrestedply") )[/CODE]
You're passing in a string to a function which isn't right and your function IsThePlyArrested is wrong because you don't need a ) at the end of it
Also plypos is global which it doesn't need to be, same with the function
What you would want to do is make it so the timer is created when the player is arrested like this
Also you don't want the timer to run forever, you only need it to run for the duration of their arrested time. Once they are un-arrested you can remove the timer
[code]
---------------- Config ----------------
local pos1 = Vector( -1416, 142, -131)
local pos2 = Vector( -1371, 53, -56)
---------------- Config ----------------
local function IsThePlyArrested( arrestedply, time, actor)
timer.Create( "playerinbounds"..ply:EntIndex(), 1, time, function()
if !IsValid(arrestedply) then return end
local plypos = arrestedply:GetPos()
if arrestedply:IsPlayer() and plypos:WithinAABox( pos1, pos2 ) then
arrestedply:unArrest()
timer.Remove("playerinbounds"..ply:EntIndex())
end
end)
end
hook.Add("playerArrested", "isplayerarrested" , IsThePlyArrested)
[/code]
An easier (and more efficient) option to do all of this is to make an entity that uses [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/ENTITY/StartTouch]ENT:StartTouch[/url]
You make the entity not draw / invisible and so players can pass through it but so it still calls StartTouch
You would just place the entity in a doorway or something / where ever you would consider them escaping and then when they hit it, unarrest them and set them back to where they were like this
[code]
function ENT:StartTouch(ent)
if ent:IsPlayer() and ent:isArrested() then
local playerPos = ent:GetPos()
ent:unArrest()
timer.Simple(.05,function()
ent:SetPos(playerPos)
end)
end
end
[/code]
[QUOTE=dence47;52489410]You're passing in a string to a function which isn't right and your function IsThePlyArrested is wrong because you don't need a ) at the end of it
Also plypos is global which it doesn't need to be, same with the function
What you would want to do is make it so the timer is created when the player is arrested like this
Also you don't want the timer to run forever, you only need it to run for the duration of their arrested time. Once they are un-arrested you can remove the timer
[code]
---------------- Config ----------------
local pos1 = Vector( -1416, 142, -131)
local pos2 = Vector( -1371, 53, -56)
---------------- Config ----------------
local function IsThePlyArrested( arrestedply, time, actor)
timer.Create( "playerinbounds"..ply:EntIndex(), 1, time, function()
if !IsValid(arrestedply) then return end
local plypos = arrestedply:GetPos()
if arrestedply:IsPlayer() and plypos:WithinAABox( pos1, pos2 ) then
arrestedply:unArrest()
timer.Remove("playerinbounds"..ply:EntIndex())
end
end)
end
hook.Add("playerArrested", "isplayerarrested" , IsThePlyArrested)
[/code]
An easier (and more efficient) option to do all of this is to make an entity that uses [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/ENTITY/StartTouch]ENT:StartTouch[/url]
You make the entity not draw / invisible and so players can pass through it but so it still calls StartTouch
You would just place the entity in a doorway or something / where ever you would consider them escaping and then when they hit it, unarrest them and set them back to where they were like this
[code]
function ENT:StartTouch(ent)
if ent:IsPlayer() and ent:isArrested() then
local playerPos = ent:GetPos()
ent:unArrest()
timer.Simple(.05,function()
ent:SetPos(playerPos)
end)
end
end
[/code][/QUOTE]
Would I spawn the entity there manualy?
[QUOTE=Bear1ySane;52489586]Would I spawn the entity there manualy?[/QUOTE]
You may spawn entities through Lua.
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/ents/Create]ents.Create[/url]
This isn't rust. ;)
Stop trying to write vectors as (#,#,#) :)
[QUOTE=Kran;52489967]This isn't rust. ;)
Stop trying to write vectors as (#,#,#) :)[/QUOTE]
I don't play rust im just terrible at Gmod LUA and LUA in general :rollout:
[QUOTE=Bear1ySane;52489984]I don't play rust im just terrible at Gmod LUA and LUA in general :rollout:[/QUOTE]
Nope, I meant the programming language LOL.
[QUOTE=Kran;52489967]This isn't rust. ;)
Stop trying to write vectors as (#,#,#) :)[/QUOTE]
I... What? Do you even make stuff for Garry's Mod?
[editline]20th July 2017[/editline]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Vector]Vector[/url]
Yeah, I read that and decided not to reply. I double check the Vector code and was completely confused. Rust isnt a programing language... :scream::hammered:
[QUOTE=Bear1ySane;52491082]Yeah, I read that and decided not to reply. I double check the Vector code and was completely confused. Rust isnt a programing language... :scream::hammered:[/QUOTE]
Rust is a programming language, just irrelevant.
Vector(#, #, #) is the usual case in which vectors are set in Lua.
[QUOTE=Wavie;52491091]Rust is a programming language, just irrelevant.
Vector(#, #, #) is the usual case in which vectors are set in Lua.[/QUOTE]
:incredible: Had no clue
[QUOTE=VeXan;52490976]I... What? Do you even make stuff for Garry's Mod?
[editline]20th July 2017[/editline]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Vector]Vector[/url][/QUOTE]
You can write vectors like this (#, #, #) in rust. Instead of std::vector or whatever.
[QUOTE=Kran;52491359]You can write vectors like this (#, #, #) in rust. Instead of std::vector or whatever.[/QUOTE]
You telling him "not to write vectors like Rust" though when it's how it's done in Gmod is silly though.
[QUOTE=Nookyava;52491475]You telling him "not to write vectors like Rust" though when it's how it's done in Gmod is silly though.[/QUOTE]
nope, if you read the first post youd understand what was going on.
[QUOTE=Kran;52491495]nope, if you read the first post youd understand what was going on.[/QUOTE]
What? I've been involved in this thread from the start.
Vectors are still going to use (#, #, #), just with Vector before it. So even though his syntax was wrong your post still comes out like you're speaking out of your ass.
[QUOTE=Nookyava;52491538]What? I've been involved in this thread from the start.
Vectors are still going to use (#, #, #), just with Vector before it. So your post still comes out like you're speaking out of your ass.[/QUOTE]
what are you even talking about? im literally just saying you dont write vectors like (#, #, #) in Lua.
[QUOTE=Kran;52491539]what are you even talking about? im literally just saying you dont write vectors like (#, #, #) in Lua.[/QUOTE]
Then how do you write them?
[QUOTE=Kran;52491539]what are you even talking about? im literally just saying you dont write vectors like (#, #, #) in Lua.[/QUOTE]
Your post needs to be worded better then, because that's not how you came across at all.
Sorry, you need to Log In to post a reply to this thread.