21.12.2012, 19:21
Can someone show me example how to make dynamic spawn for players ? And an admin can set it from IG with a commnad?
#include <a_samp>
#include <zcmd> // Command Processer used.
#define MAX_SPAWNS 1// Let's you know that you may only set 1 spawn. DO NOT CHANGE THIS.
enum DynamicSpawn
{
Float:D_SpawnX,// X Float for the Dynamic Spawn
Float:D_SpawnY,// Y Float for the Dynamic Spawn
Float:D_SpawnZ,// Z Float for the Dynamic Spawn
Float:D_Angle// Facing Angle for the Dynamic Spawn
}
new D_Info[DynamicSpawn];
public OnGameModeInit()
{
SetGameModeText("Dynamic Spawn");// Can be removed. Sets the GameMode for SAMP Client.
AddPlayerClass(292, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
LoadDynamicSpawn();// Loads the Dynamic Spawn X, Y, Z, and Facing Angle from d_spawn.cfg
return 1;
}
public OnGameModeExit()
{
return 1;
}
public OnPlayerRequestClass(playerid, classid)
{
SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
return 1;
}
public OnPlayerSpawn(playerid)
{
SetPlayerPos(playerid, D_Info[D_SpawnX], D_Info[D_SpawnY], D_Info[D_SpawnZ]);// Sets the player position for the X,Y, Z loaded from d_spawn.cfg.
SetPlayerFacingAngle(playerid, D_Info[D_Angle]);// Sets the Facing angle loaded from d_spawn.cfg
return 1;
}
/*
// Command disabled, tells you your location and the location of the dynamic spawn.
// Used primarly for de-bugging.
CMD:loc(playerid, params[])
{
new string[256];
new Float:X, Float:Y, Float:Z, Float:A;
GetPlayerPos(playerid, X, Y, Z);
GetPlayerFacingAngle(playerid, A);
format(string, sizeof(string), " D_Location: X: %f, Y: %f, Z: %f, A: %f ", D_Info[D_SpawnX], D_Info[D_SpawnY], D_Info[D_SpawnZ], D_Info[D_Angle]);
SendClientMessage(playerid, 0xFFFFFF, string);
format(string, sizeof(string), " M_Location: X: %f, Y: %f, Z: %f, A: %f ", X, Y, Z, A);
SendClientMessage(playerid, 0xFFFFFF, string);
return 1;
}*/
CMD:spawn(playerid, params[])// Sets the Dynamic Spawn.
{
new string[256];
new Float:X, Float:Y, Float:Z, Float:A;
GetPlayerPos(playerid, X, Y, Z);
GetPlayerFacingAngle(playerid, A);
D_Info[D_SpawnX] = X;//
D_Info[D_SpawnY] = Y;
D_Info[D_SpawnZ] = Z;
D_Info[D_Angle] = A;
SaveDynamicSpawn();
SendClientMessage(playerid, 0xFFFFFF, " ** The Spawn has been changed to your location !");
format(string, sizeof(string), " Spawn: X: %f, Y: %f, Z: %f ", D_Info[D_SpawnX], D_Info[D_SpawnY], D_Info[D_SpawnZ], D_Info[D_Angle]);
SendClientMessage(playerid, 0xFFFFFF, string);
return 1;
}
/*
// Command Disabled, to prevent interfence with your own /kill.
// Can be removed.
CMD:kill(playerid, params[])
{
SetPlayerHealth(playerid, 0);
return 1;
}*/
public OnPlayerCommandText(playerid, cmdtext[])
{
return 0;
}
forward splits(const strsrc[], strdest[][], delimiter);
public splits(const strsrc[], strdest[][], delimiter)
{
new i, li;
new aNum;
new len;
while(i <= strlen(strsrc)){
if(strsrc[i]==delimiter || i==strlen(strsrc)){
len = strmid(strdest[aNum], strsrc, li, i, 128);
strdest[aNum][len] = 0;
li = i+1;
aNum++;
}
i++;
}
return 1;
}
SaveDynamicSpawn()
{
new FString[256], File: flocation = fopen("d_spawn.cfg", io_write);// Location in which all Spawn information is saved.
for(new iIndex; iIndex < MAX_SPAWNS; iIndex++)
{
format(FString, sizeof(FString), "%f|%f|%f|%f", D_Info[D_SpawnX], D_Info[D_SpawnY], D_Info[D_SpawnZ], D_Info[D_Angle]);
fwrite(flocation, FString);
}
return fclose(flocation);// Closes the file, after the information above has been Saved.
}
LoadDynamicSpawn()
{
new SCoords[4][64];
new FString2[256];
new File: flocation = fopen("d_spawn.cfg", io_read);// Location in which all Spawn information is loaded.
if (flocation)
{
fread(flocation, FString2);
splits(FString2, SCoords, '|');
D_Info[D_SpawnX] = floatstr(SCoords[0]);
D_Info[D_SpawnY] = floatstr(SCoords[1]);
D_Info[D_SpawnZ] = floatstr(SCoords[2]);
D_Info[D_Angle] = floatstr(SCoords[3]);
fclose(flocation);// Closes the file after everything is loaded.
}
return 1;
}