How to convert this?
#1

How to convert this to C#?
pawn Код:
return ( ( ((px-X)*(px-X))+((py-Y)*(py-Y))+((pz-Z)*(pz-Z)) ) >= radius*radius );
I tried that in C# but it's not working.
Reply
#2

Will this work?

PHP код:
 private bool IsPlayerInRangeOfPoint(Player plfloat radiusfloat Xfloat Yfloat Z)
        {
            
float pxpypz;
            
px pl.Pos.X;
            
py pl.Pos.Y;
            
pz pl.Pos.Z;
            
float dist = (((px X) * (px X)) + ((py Y) * (py Y)) + ((pz Z) * (pz Z)));
            
float radi radius radius;
            if (
dist >= radi)
            {
                return 
true;
            }
            else
            {
                return 
false;
            }
        } 
Reply
#3

BUMP! Anyone knows about it?
Reply
#4

Code looks right to me.

There is a Vector3 method for getting distance that will make life easier though.

Код:
 private bool IsPlayerInRangeOfPoint(Player pl, float radius, Vector3 other)
        {
            if (pl.Pos.Distance(other) < radius) return true;
            return false;
        }
The contents of Vector3.Distance() are:
Код:
public float Distance(Vector3 other)
        {
            //     __________________________________
            //d = √ (x2-x1)^2 + (y2-y1)^2 + (z2-z1)^2
            //
 
            //Our end result
            float result = 0.0F;
            //Take x2-x1, then square it
            double part1 = Math.Pow((other.X - this.X), 2);
            //Take y2-y1, then sqaure it
            double part2 = Math.Pow((other.Y - this.Y), 2);
            //Take z2-z1, then square it
            double part3 = Math.Pow((other.Z - this.Z), 2);
            //Add both of the parts together
            double underRadical = part1 + part2 + part3;
            //Get the square root of the parts
            result = (float)Math.Sqrt(underRadical);
            //Return our result
            return result;
        }
The coe is not mine; im no good with maths. But a ****** search led me to http://www.dreamincode.net/code/snippet4417.htm .
Reply
#5

Quote:
Originally Posted by Iain.Gilbert
Посмотреть сообщение
Code looks right to me.

There is a Vector3 method for getting distance that will make life easier though.

Код:
 private bool IsPlayerInRangeOfPoint(Player pl, float radius, Vector3 other)
        {
            if (pl.Pos.Distance(other) < radius) return true;
            return false;
        }
The contents of Vector3.Distance() are:
Код:
public float Distance(Vector3 other)
        {
            //     __________________________________
            //d = √ (x2-x1)^2 + (y2-y1)^2 + (z2-z1)^2
            //
 
            //Our end result
            float result = 0.0F;
            //Take x2-x1, then square it
            double part1 = Math.Pow((other.X - this.X), 2);
            //Take y2-y1, then sqaure it
            double part2 = Math.Pow((other.Y - this.Y), 2);
            //Take z2-z1, then square it
            double part3 = Math.Pow((other.Z - this.Z), 2);
            //Add both of the parts together
            double underRadical = part1 + part2 + part3;
            //Get the square root of the parts
            result = (float)Math.Sqrt(underRadical);
            //Return our result
            return result;
        }
The coe is not mine; im no good with maths. But a ****** search led me to http://www.dreamincode.net/code/snippet4417.htm .
Thanks bud!
Reply
#6

P.S. Does anyone knows how to get the return values from native functions?
Reply
#7

look to NativeFunctionExample.cs script:

Код:
        public void SpawnPlayerCar(int playerid)
        {
            int model = 429; //banshee
            Samp.Util.FloatRef x = 0.0F, y = 0.0F, z = 0.0F, angle = 0.0F; // must use FloatRef class to return floats from native function, same goes for StringRef & IntRef
            Samp.Client.NativeFunctionRequestor.RequestFunction("GetPlayerPos", playerid, x, y, z);
            NativeFunctionRequestor.RequestFunction("GetPlayerFacingAngle", playerid, angle);
            int vehicleid = NativeFunctionRequestor.RequestFunction("CreateVehicle", model, x.Value, y.Value, z.Value, angle.Value, 0, 0, 300);// note that we use x.Value now
            NativeFunctionRequestor.RequestFunction("PutPlayerInVehicle", playerid,vehicleid,0);
            NativeFunctionRequestor.RequestFunction("SendClientMessage", playerid, 0,"{00FF00}Vehicle Spawned.");
        }
Reply
#8

Can I export function to that I can use on include files?
Reply
#9

Oh yeah, good idea, i'll add that.
I never realy thought much on it, but it should be relatively simple (famous last words) to add both calling .net functions from pawn & calling pawn functions from .net.
I've had too many beers to comtemplate it properly at the moment, but i'll see about adding it tomorrow-ish.
Reply
#10

Quote:
Originally Posted by Iain.Gilbert
Посмотреть сообщение
Oh yeah, good idea, i'll add that.
I never realy thought much on it, but it should be relatively simple (famous last words) to add both calling .net functions from pawn & calling pawn functions from .net.
I've had too many beers to comtemplate it properly at the moment, but i'll see about adding it tomorrow-ish.
you are the man!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)