Vice City: Multiplayer

Server Development => Scripting and Server Management => Topic started by: Mötley on Jan 29, 2018, 01:22 AM

Title: Returning the lesser distance from four different vectors
Post by: Mötley on Jan 29, 2018, 01:22 AM
Sorry, It's been a really long work week, and my mind is not really that great from lack of sleep, and over working. This is a rather simple solution. I just cant seem to think clearly :/ regards.

Well the topic say's it all. 
I was looking at the Squirrel Docs at what made sense, http://www.squirrel-lang.org/squirreldoc/reference/language/builtin_functions.html?highlight=compare .

Please remember I'm only testing at the moment, I haven't taken the time to write to code more efficiently, this is just fundamental testing stuff. Any help on how I should go about this would be great! ;)
Hospital_Spawn <- array( GetMaxPlayers(), false ); // Has the player died
HospitalSpawnLocations <- [ Vector( -886.074,-470.278,13.1109 ), Vector( -783.051,1141.83,12.4111), Vector( 467.763,697.68,11.7033 ), Vector( -135.137,-981.579,10.4634 ) ]; // Hospital locations

Death_Loacation <- array( GetMaxPlayers() ); // Storage of the players last position upon death 'player.Pos'

// Kuddos Rwwpl
function GetDistance(v1,v2) return sqrt((v2.x-v1.x)*(v2.x-v1.x) + (v2.y-v1.y)*(v2.y-v1.y) + (v2.z-v1.z)*(v2.z-v1.z));
There's so much to compare, I don't want to go about this wrongly and end up with a huge script, when that's not even necessary.
I can get around to this eventually if no one is able to help me any time soon.
Title: Re: Returning the lesser distance from four different vectors
Post by: DizzasTeR on Jan 29, 2018, 01:41 AM
Vector1.Distance (Vector2)

Use that one, its faster and better. It was also posted several times on the forum
Title: Re: Returning the lesser distance from four different vectors
Post by: Mötley on Jan 29, 2018, 02:10 AM
I did a search for that version. I did not see it, Can I get a link please :)?

Welp, I figured I would make this easier on myself, I made this Island return. It took a lot of testing. It's not 100% perfected but it should do the trick once perfected.

function GetIsland(pos) {
 
  // First Island
  if (pos.x > -170) return 1;
  // Third Island
  if (pos.x < -724) return 3;
 
  // Center islands bull shittery
  return 2;
}

function NearestHospital(pos) {
if (pos.y >= 30) return 1; // northern hospitals
if (pos.y <= 30) return 2; // southern hospitals

}



I'm just going to fix this myself and randomly put solved as I don't see anyone really helping on this tbh...
Title: Re: Returning the lesser distance from four different vectors
Post by: DizzasTeR on Feb 01, 2018, 10:26 AM
What's so hard when I already told you the method
g_Hospitals <- [
    Vector(x,y,z),
    ...
];

function GetNearestHospital(player) {
    local pPos = player.Pos;
    local lastSmallDistance = pPos.Pos.Distance(g_Hospitals[0]), Hindex;
    foreach(index, vHospital in g_Hospitals) {
        if(pPos.Distance(vHospital) < lastSmallDistance) {
            Hindex = index;
        }
    }
    return Hindex;
}

Might have mistakes but I don't know how you didn't manage to understand it
Title: Re: Returning the lesser distance from four different vectors
Post by: Mötley on Feb 01, 2018, 01:05 PM
Quote from: Doom_Kill3R on Feb 01, 2018, 10:26 AMWhat's so hard when I already told you the method

xD all I said was

Quote from: TurboGrafx on Jan 29, 2018, 02:10 AMI did a search for that version. I did not see it, Can I get a link please :)?

So I was still at ???.



But thanks I guess :)