So i'm about to finish a plugin but there is a small "issue"...
i have this line
and it is not working.. I'm on the xyz that i have to beCode:if player.transform.position.x == self.Config.Test.X and player.transform.position.y == self.Config.Test.Y and player.transform.position.z == self.Config.Test.Z then print("Something")
Is there other way to do this position checking ?
Solved If XYZ then
Discussion in 'Rust Development' started by PaiN, Jun 19, 2015.
-
Wulf Community Admin
Are your config entries ints or strings?
-
This is the plugin's config.
Code:self.Config.Warp1 = self.Config.Warp1 or {} self.Config.Warp1.X = self.Config.Warp1.X or "503" self.Config.Warp1.Y = self.Config.Warp1.Y or "503" self.Config.Warp1.Z = self.Config.Warp1.Z or "503"
-
Wulf Community Admin
Code:self.Config.Warp1 = self.Config.Warp1 or {} self.Config.Warp1.X = self.Config.Warp1.X or 503 self.Config.Warp1.Y = self.Config.Warp1.Y or 503 self.Config.Warp1.Z = self.Config.Warp1.Z or 503
-
Hmm do i have to check every (x) secs ? To see if there is someone at these cords ?
Bcs i tried it with myself but nothing happens
I will try to use the tonumber function
[DOUBLEPOST=1434724985][/DOUBLEPOST]Tried the tonumber function but it is still not working i have no idea on what i'm doing wrong
Some of the code that might help you
I tried without the tonumber function too btw
Code:function PLUGIN:LoadDefaultConfig() self.Config.Warp1 = self.Config.Warp1 or {} self.Config.Warp1.X = tonumber(self.Config.Warp1.X) or 503 self.Config.Warp1.Y = tonumber(self.Config.Warp1.Y) or 503 self.Config.Warp1.Z = tonumber(self.Config.Warp1.Z) or 503 self:SaveConfig() end--and this is what i'm trying to do if player.transform.position.x == self.Config.Warp1.X and player.transform.position.y == self.Config.Warp1.Y and player.transform.position.z == self.Config.Warp1.Z then print("debug")
Code:self.Config.Warp1.X = self.Config.Warp1.X or -1465 self.Config.Warp1.Y = self.Config.Warp1.Y or 10 self.Config.Warp1.Z = self.Config.Warp1.Z or 334
Last edited by a moderator: Jun 19, 2015 -
If you are trying to use positions and match them. this is a somewhat wrong way of doing it since the positions are a float and the result can be something like
My example is using C#
Code:if(player.transform.position.x == self.Config.Wrap1.x) //in actual value if (124.124 == 124.00)
Code:var configPos = new Vector3(config.x, config.y , config.z);if(Vector3.Distance(player.transform.position, configPos) < 1) { //Do Something }
-
I have to tell also that i dont know what these Vectors3 are.. some good coders are using them and i'm like wtf..
[DOUBLEPOST=1434805051,1434792741][/DOUBLEPOST]Code:local configPos = Vector3(self.Config.Warp1.X, self.Config.Warp1.Y, self.Config.Warp1.Z) if(Vector3.Distance(player.transform.position, configPos) < 1) then print("something")
Code:[Oxide] 4:01 PM [Error] Failed to call hook 'Test' on plugin 'Test' File: test.lua Line: 24 attempt to call global 'Vector3' (a nil value): at NLua.Lua.ThrowExceptionFromError (Int32 oldTop) [0x00000] in <filename unkn own>:0 at NLua.Lua.CallFunction (System.Object function, System.Object[] args, System .Type[] returnTypes) [0x00000] in <filename unknown>:0 at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (ob ject,object[],System.Exception&) at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invoke Attr, System.Reflection.Binder binder, System.Object[] parameters, System.Global ization.CultureInfo culture) [0x00000] in <filename unknown>:0
Last edited by a moderator: Jun 20, 2015 -
Vector3 is just XYZ
-
You want to create a new Vector3 struct.Last edited by a moderator: Jun 20, 2015 -
I'm so lost i dont know where is the problem ..
also maybe my translation is bad ..
Can some1 tell me what "var" from C# means in LUA ?
My code :
Code:local configPos = new Vector3(self.Config.Warp1.X, self.Config.Warp1.Y , self.Config.Warp1.Z ) if(Vector3.Distance(player.transform.position, configPos) <1) then rust.BroadcastChat("test") else rust.BroadcastChat("test")
Code:local configPos = new UnityEngine.Vector3(self.Config.Warp1.X, self.Config.Warp1.Y , self.Config.Warp1.Z ) if(Vector3.Distance(player.transform.position, configPos) <1) then rust.BroadcastChat("test") else rust.BroadcastChat("test")
http://screenshot.sh/m7ra7bLxQzD2JLast edited by a moderator: Jun 20, 2015 -
I'm not familiar with using LUA at all, sorry that I am not more help but Vector3 is basically used for the position of an object in the world space.
I believe you are just having some syntax issues right now. -
Var in c# is just a compiler determined strong typed variable, the compiler automatically attributes the proper type on compile. If you assign an int to it it will be an int (and it will be locked as an int and typechecked as one). There is no equivalent in lua afaik, just use the proper type instead.
-