[Unsolved] Get Random Coordinates from File
#1

Hi,

I need to know how I would get a list of coordinates from a file, and then when a player dies and respawns, it spawns them in one of those coordinates from that file.

I think the best way to do this would be to get the coordinates from the file when the file is loaded and store it in an array/variable so it loads up quickly when a player dies and would respawn from a random coordinate from that array. (Please ignore me if i am using incorrect terminology i.e. array/variable). I am using Dracoblue's Dini btw.

This is what I mean in it's most simplest form:

-I type /loadfile (filenumber)
- In that file i have a list of coordinates
-Now when the player dies, he respawns in a location specifieid from the file.

I am guessing I have to use dini_Float(filename[], key[]), but then how would i store it?

I hope you get what I mean, if not, I'll re-explain.

Thank You , ur help is much appreciated!

Reply
#2

Sorry to Double Post, but i still can't figure out how i would do this.

Basically, how would i get a list of coordinates from a file, then make a player spawn out of that list? But I want the list of coordinates to be stored in an array for constant use.

Thanks
Reply
#3

You could make a file in scriptfiles, let's say coordinates.txt. Then get the number of lines in the file (search), then randomize it. Then fread(line) and extract it. Then convert it to float (strfloat... i think?) and at last SetPlayerPos.

Leopard
Reply
#4

Thanks for your reply [K4L]Leopard, but i'm gonna stick with Dini rather than using fread.

I'll explain the use for what i need. Basically it's a gamemode with rounds. So i can load up a round by using say /loadround [roundid]
Then the 'roundid' file will load from my scriptfiles/roundfiles folder. Each File is basicallly a differnet map/area. Roundid 1 may have coordinates in and around Grove St whilst Roundid 2 file has coordinates in and around Central Las Venturas - you get the picture.

Aim of the gamemode is for your team to get as many kills within the time. Team with highest kill wins. So every time a player dies and respawns it will set their position to a random place according to the roundid being played at the time rather than one set position - otherwise people can just stand around the spawn area and keep killing them each time someone spawns.

Each round has it's own map/area.

I've got all the code done, now all i need is to store the coordinates from the 'Roundid' file in an array for the player to spawn which is what i am requesting, not for all the above to be done. Then when another round starts it replaces the coordinates in that array with the coordinates of the new roundid being played.

I hope i made things simpler, and hope i've not confused things further.

Reply
#5

Well. In my server I have an array with different coordinates on.

Define this.

gRandomPlayerSpawns[NUMBER OF COORDS][3]

COORD = x,y,z

pawn Code:
new Float:gRandomPlayerSpawns[5][3] = {
{COORD ONE},
{COORD TWO},
{COORD THREE},
{COORD FOUR},
{COORD FIVE}
};
So you can change the name of the array, with round names.

RoundOnePlayerSpawns[number][3]

pawn Code:
public SetPlayerSpawn(playerid)
{
    if(IsPlayerConnected(playerid))
    {
        if(PlayerRound == 1)
        {
            rand = random(sizeof(RoundOnePlayerSpawns));
            SetPlayerPos(playerid, RoundOnePlayerSpawns[rand][0], RoundOnePlayerSpawns[rand][1], RoundOnePlayerSpawns[rand][2]); //Leave these numbers the
                                                                //same, only change the name eg. "RoundOnePlayerSpawns"
        }
    }
    return 1;
}
You can add extra cases such as if(PlayerRound == 2) and etc.

Good luck.
Reply
#6

Thanks GunnerZ,

That was exactly what i was trying to avoid lol.

Otherwise I will will had so many of this in the pawn file RoundOnePlayerSpawns, RoundTwoPlayerSpawns, RoundThreePlayerSpawns, RoundFourPlayerSpawns. I already know how to do that.

I would rather have it load from a file, rather than setting it in the gamemode file. It is likely that I will have more than 30-100 Round Files, so putting these coordinates in the pawn file will take up a huge amount of space.

Thanks anyways GunnerZ, much appreciated. Still looking for a solution :P
Reply
#7

You could put it in a filterscript?
Reply
#8

Thats basically the same thing, plus i would need it to run on my gamemode for various reasons rsather than alongside it.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)