set spawn -
Spartaaaaa - 09.08.2014
Hello,
I want a script when i typed /Spawn it's must save position on scriptfiles and when i get dead i must spawn on that position where i typed /spawn if i discounted game and then conectd again it's must spawn on that position where i set my own /spawn
Re: set spawn -
Stinged - 09.08.2014
Not tested, but should work. Tell me if it did or it gave you some errors.
pawn Код:
CMD:spawn(playerid, params[])
{
new pname[24], string[70];
new Float:x, Float:y, Float:z, Float:a;
GetPlayerPos(playerid, x, y, z);
GetPlayerFacingAngle(playerid, a);
GetPlayerName(playerid, pname, sizeof (pname));
format(string, sizeof (string), "spawns/%s.txt", pname);
new File:pos = fopen(string, io_write);
format(string, sizeof (string), "x %f\r\ny %f\r\nz %f\r\na %f", x, y, z, a);
fwrite(pos, string);
fclose(pos);
return 1;
}
public OnPlayerSpawn(playerid)
{
new pname[24], string[70];
new Float:x, Float:y, Float:z, Float:a;
new str[15];
GetPlayerName(playerid, pname, sizeof (pname));
format(string, sizeof (string), "spawns/%s.txt", pname);
new File:pos = fopen(string, io_read);
while (fread(pos, string))
{
if (!strcmp(string, "x ", true))
{
strmid(str, string, 2, 14);
x = floatstr(str);
}
else if (!strcmp(string, "y ", true))
{
strmid(str, string, 2, 14);
y = floatstr(str);
}
else if (!strcmp(string, "z ", true))
{
strmid(str, string, 2, 14);
z = floatstr(str);
}
else if (!strcmp(string, "a ", true))
{
strmid(str, string, 2, 14);
a = floatstr(str);
}
}
SetPlayerPos(playerid, x, y, z);
SetPlayerFacingAngle(playerid, a);
return 1;
}
Re: set spawn -
Spartaaaaa - 10.08.2014
when i start my server and it's got crashed
Re: set spawn -
Spartaaaaa - 10.08.2014
anyoneR^#^
Re: set spawn -
Spartaaaaa - 10.08.2014
Bump
Re: set spawn -
Spartaaaaa - 10.08.2014
bump
Answer -
Ygzeb - 10.08.2014
You can use this as a reference to make your own spawn set code. Your spawn system would be easier to do with a registration system; then you can use something like:
We define DCMD:
pawn Код:
#define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
In OnPlayerCommandText:
We create our command (Out of publics):
pawn Код:
dcmd_spawn(playerid,params[]) // We create the command and we save the position of the player.
{
#pragma unused params
new Float: X, Float: Y, Float:Z, Interior;
GetPlayerPos(playerid, X, Y, Z); Interior = GetPlayerInterior(playerid);
dUserSetINT(Player(playerid)).("X", floatround(X));
dUserSetINT(Player(playerid)).("Y", floatround(Y));
dUserSetINT(Player(playerid)).("Z", floatround(Z));
dUserSetINT(Player(playerid)).("Interior", Interior);
dUserSetINT(Player(playerid)).("World", (GetPlayerVirtualWorld(playerid)));
return SendClientMessage(playerid, 0xFFA600AA, "Spawn point saved!");
}
We put our code in OnPlayerSpawn to spawn the player in the position:
pawn Код:
public OnPlayerSpawn(playerid) // Spawning code.
{
#pragma unused params
if(dUserINT(Player(playerid)).("X")!=0)
{
Pos(playerid);
SetPlayerVirtualWorld(playerid, (dUserINT(Player(playerid)).("World")) );
return SendClientMessage(playerid, 0xFFA600AA, "Spawned succesfully!");
}
else return SendClientMessage(playerid, 0xFF0000AA, "You must save a spawn position first.");
}
Create a public for "Pos":
pawn Код:
forward Pos(playerid);
// We set the position of the player.
public Pos(playerid)
{
if(dUserINT(Player(playerid)).("X")!=0)
{
SetPlayerPos(playerid, float(dUserINT(Player(playerid)).("X")), float(dUserINT(Player(playerid)).("Y")), float(dUserINT(Player(playerid)).("Z")));
SetPlayerInterior(playerid, (dUserINT(Player(playerid)).("Interior")));
}
}
Note: This is just a reference for you because we do not know if you are going to use a registration system or what kind of registration system you are using. I made this using my own registration system. It is possible to make a spawn set without a registration system but it is more complicated.
Good luck