PDA

View Full Version : I need ANY system to save Player Position and Skin.


Aerotactics
12/02/2014, 07:29 AM
I'm building an RP server and I hit a snare. One of the FS for the server saves kills, stats, etc. but lacks saving Skin and Player Position (because its an admin system). It uses YSI, so I would prefer to use that, BUT I am open to use any system to store Position and Skin, but I am very uneducated in this area of scripting, so I ask if the kind community in SAMP could help me and guide me through what I need to know. On top of that, I would also like to create a command that resets these stats in case the player chooses to reset their account details. Could I also incorporate deleting their file used in the Admin system into that command? Here's some additional information:

My GM script (far from finished, IDK if it makes sense to include it here, but people usually ask for it, 600+ lines of bare bones):
/*
CREDITS
=======
-Base GM Script by Aerotactics
*/
#include <a_samp>
#include <foreach>
#include <streamer>
#include <LocalChat>

main()
{
print("\n----------------------------------");
print(" LS-RP Loaded");
print("----------------------------------\n");
}

#define COLOR_WHITE 0xFFFFFFFF
#define COLOR_FADE1 0xE6E6E6E6
#define COLOR_PM1 0xA65FC7FF
#define COLOR_PM2 0xD35FC7FF
#define COLOR_FADE2 0xC8C8C8C8
#define COLOR_FADE3 0xAAAAAAAA
#define COLOR_FADE4 0x8C8C8C8C
#define COLOR_FADE5 0x6E6E6E6E
#define COLOR_OOC 0xE0FFFFFF
#define COLOR_GREY 0xAFAFAFFF
#define COLOR_LIGHTGREEN 0xADFF2FFF
#define COLOR_LIGHTRED 0xFF6347FF
#define COLOR_DARKRED 0xAA3333FF
#define COLOR_RED 0xFF0606FF
#define COLOR_LIGHTBLUE 0x33CCFFFF
#define COLOR_GREEN 0x33AA33FF
#define COLOR_YELLOW 0xFFFF00FF
#define COLOR_PURPLE 0xC2A2DAFF
#define COLOR_ORANGE 0xFF9900FF
#define COLOR_REPORT 0xFFFF91FF
#define COLOR_RADIO 0x8D8DFFFF
#define COLOR_DEPTRADIO 0xFFD700FF
#define COLOR_BLUE 0x2641FEFF
#define COLOR_MEDIC 0xFF8282FF
#define COLOR_NEWBIE 0x7DAEFFFF
#define COLOR_LIME 0x00FF00FF
#define COLOR_NEWS 0x049C7100
#define COLOR_CYAN 0x01FCFFFF
#define COLOR_VIP 0xC93CCEFF
#define COLOR_GOLD 0xFFD700FF

#define Dialog_Sex1 1
#define Dialog_RaceM 2
#define Dialog_RaceF 3
#define Dialog_MaleW 4
#define Dialog_MaleB 5
#define Dialog_MaleO 6
#define Dialog_MaleH 7
#define Dialog_MaleN 8
#define Dialog_FMaleW 9
#define Dialog_FMaleB 10
#define Dialog_FMaleO 11
#define Dialog_FMaleH 12
#define Dialog_FMaleN 13
#define Dialog_MSelect 14
#define Dialog_FSelect 15

#define savefolder "/save/%s.ini"

stock NameValidator(playerid)
{
new pname[MAX_PLAYER_NAME],underline=0;
GetPlayerName(playerid, pname, sizeof(pname));
if(strfind(pname,"[",true) != (-1)) return 0;
else if(strfind(pname,"]",true) != (-1)) return 0;
else if(strfind(pname,"$",true) != (-1)) return 0;
else if(strfind(pname,"(",true) != (-1)) return 0;
else if(strfind(pname,")",true) != (-1)) return 0;
else if(strfind(pname,"=",true) != (-1)) return 0;
else if(strfind(pname,"@",true) != (-1)) return 0;
else if(strfind(pname,"1",true) != (-1)) return 0;
else if(strfind(pname,"2",true) != (-1)) return 0;
else if(strfind(pname,"3",true) != (-1)) return 0;
else if(strfind(pname,"4",true) != (-1)) return 0;
else if(strfind(pname,"5",true) != (-1)) return 0;
else if(strfind(pname,"6",true) != (-1)) return 0;
else if(strfind(pname,"7",true) != (-1)) return 0;
else if(strfind(pname,"8",true) != (-1)) return 0;
else if(strfind(pname,"9",true) != (-1)) return 0;
new maxname = strlen(pname);
for(new i=0; i<maxname; i++)
{
if(pname[i] == '_') underline ++;
}
if(underline != 1) return 0;
pname[0] = toupper(pname[0]);
for(new x=1; x<maxname; x++)
{
if(pname[x] == '_') pname[x+1] = toupper(pname[x+1]);
else if(pname[x] != '_' && pname[x-1] != '_') pname[x] = tolower(pname[x]);
}
SetPlayerName(playerid, "New_Name");
SetPlayerName(playerid, pname);
return 1;
}

stock GetPlayerRPName( playerid, name[ ], len )
{
GetPlayerName( playerid, name, len );
for(new i = 0; i < len; i++ )
{
if ( name[ i ] == '_' )
name[ i ] = ' ';
}
}

halt(seconds)
{
new _newTime[4], _oldTime[4];
gettime(_oldTime[0], _oldTime[1], _oldTime[2]);
_oldTime[3] = _oldTime[2] + (_oldTime[1] * 60) + (_oldTime[0] * 600);

while(_newTime[3] != (_oldTime[3] + seconds))
{
gettime(_newTime[0], _newTime[1], _newTime[2]);
_newTime[3] = _newTime[2] + (_newTime[1] * 60) + (_newTime[0] * 600);
}
}

new Tcar;
new Tboat;
new Tjet;

new gdo;
new gdi;
new gdo2;

new Text:randommsg;

new RandomMessages[][] =
{
"~g~Los Santos Roleplay: ~w~This server won't save skins, but saves ~g~money~w~, ~b~vehicles~w~, and ~y~property~w~.",
"~g~Los Santos Roleplay: ~w~The aim of this server is to be ~y~simple ~w~yet ~y~effective~w~.",
"~g~Los Santos Roleplay: ~w~This server was created by ~y~Aerotactics~w~. Why not ~b~G~r~o~y~o~b~g~g~l~r~e ~w~'~y~Aerotactics~w~'?",
"~g~Los Santos Roleplay: ~r~PSA:~w~ This ~r~Public Service Announcement~w~ was brought to you by ~g~LS-RP~w~.",
"~g~Los Santos Roleplay: ~w~I ~r~NEVER~w~ ask for donations. Did you know this server runs on a laptop?",
"~g~Los Santos Roleplay: ~w~Is a player out of line? Please ~r~/report ~w~them!",
"~g~Los Santos Roleplay: ~w~Enjoying your stay? You are ~y~always welcome~w~ to come back!",
"~g~Los Santos Roleplay: ~w~This server started on the idea of ~b~roleplay ~w~for ~p~~h~VCS:PC.",
"~g~Los Santos Roleplay: ~w~Suggestions? Send ~y~Aerotactics~w~ a personal message on ~b~~h~the SAMP forums~w~.",
"~g~Los Santos Roleplay: ~w~Bugs? Please ~r~/report~w~ or send ~y~Aerotactics ~w~a PM on ~b~~h~the SAMP forums~w~."
};

forward RandomMessage();

public RandomMessage()
{
TextDrawSetString(randommsg, RandomMessages[random(sizeof(RandomMessages))]);
return 1;
}

public OnGameModeInit()
{
SetGameModeText("LS-RP ALPHA");

SetTimer("RandomMessage",30000,1);

randommsg = TextDrawCreate(7.000000, 427.000000, "_");
TextDrawBackgroundColor(randommsg, 255);
TextDrawFont(randommsg, 1);
TextDrawLetterSize(randommsg, 0.379999, 1.499999);
TextDrawColor(randommsg, -1);
TextDrawSetOutline(randommsg, 1);
TextDrawSetProportional(randommsg, 1);

ManualVehicleEngineAndLights();

gdo=CreatePickup(1559, 14, 1454.5000000,-675.5000000,1274.5999800, -1);
gdi=CreatePickup(1559, 1, 1460.5999800,-629.5999800,95.2000000, -1);
gdo2=CreatePickup(1559, 1, 1454.5000000,-675.5000000,1274.5999800, -1);
return 1;
}

public OnGameModeExit()
{
return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_MSGBOX, "Gender Selection", "Choose a gender:", "Male", "Female");
SetPlayerPos(playerid, 1555.5999800,-2312.6001000,-23.4000000);
SetPlayerFacingAngle(playerid, 160);
SetPlayerCameraPos(playerid, 1554.5999800,-2315.6001000,-22.0000000);
SetPlayerCameraLookAt(playerid, 1555.5999800,-2312.6001000,-23.0000000);
return 1;
}

public OnPlayerConnect(playerid)
{
//PlayAudioStreamForPlayer(playerid, "");
if(!NameValidator(playerid))
{
SendClientMessage(playerid,COLOR_RED,"Your name is a non-roleplay name, You have been kicked!");
SendClientMessage(playerid,COLOR_RED,"HINT: Your name must be in Firstname_Lastname format, (E.G: Chris_Hansen)");
halt(2);
Kick(playerid);
}
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
return 1;
}

public OnPlayerSpawn(playerid)
{
TextDrawShowForPlayer(playerid, randommsg);
SetPlayerWorldBounds(playerid,3555.9,-24.4,-397.8,-3189.9);
SetPlayerPos(playerid,1573.4,-2330.8,13.2);
SetPlayerFacingAngle(playerid, 90);
SetCameraBehindPlayer(playerid);
//StopAudioStreamForPlayer(playerid);
new name[MAX_PLAYER_NAME+1], string[24+MAX_PLAYER_NAME+1];
GetPlayerRPName(playerid, name, sizeof(name));
format(string, sizeof(string), "%s has arrived in Los Santos.", name);
SendClientMessageToAll(COLOR_GREEN, string);
return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
return 1;
}

public OnVehicleSpawn(vehicleid)
{
return 1;
}

public OnVehicleDeath(vehicleid, killerid)
{
return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/tcar", cmdtext, true, 10) == 0)
{
new Float:x,Float:y,Float:z;
new Float:a;
GetPlayerPos(playerid, x, y, z);
GetPlayerFacingAngle(playerid, a);
Tcar=CreateVehicle(560,x, y+5, z, a,111,103, -1);
AddVehicleComponent(Tcar, 1138);
AddVehicleComponent(Tcar, 1026);
AddVehicleComponent(Tcar, 1033);
AddVehicleComponent(Tcar, 1010);
AddVehicleComponent(Tcar, 1082);
AddVehicleComponent(Tcar, 1141);
AddVehicleComponent(Tcar, 1169);
ChangeVehiclePaintjob(Tcar, 2);
return 1;
}
if (strcmp("/tboat", cmdtext, true, 10) == 0)
{
new Float:x,Float:y,Float:z;
new Float:a;
GetPlayerPos(playerid, x, y, z);
GetPlayerFacingAngle(playerid, a);
Tboat=CreateVehicle(430,x, y+5, z, a,111,103, -1);
return 1;
}
if (strcmp("/tjet", cmdtext, true, 10) == 0)
{
new Float:x,Float:y,Float:z;
new Float:a;
GetPlayerPos(playerid, x, y, z);
GetPlayerFacingAngle(playerid, a);
Tjet=CreateVehicle(520,x, y+5, z, a,111,103, -1);
return 1;
}
if(strcmp(cmdtext, "/me", true, 3) == 0)
{
if(!cmdtext[3])return SendClientMessage(playerid, COLOR_RED, "USAGE: /me [text]");
new str[128];
GetPlayerRPName(playerid, str, sizeof(str));
format(str, sizeof(str), "*%s %s", str, cmdtext[4]);
SendLocalMessage(playerid, COLOR_PURPLE, 7, str);
return 1;
}
return 0;
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
if (vehicleid==Tcar)
{
DestroyVehicle(Tcar);
}
if (vehicleid==Tboat)
{
DestroyVehicle(Tboat);
}
if (vehicleid==Tjet)
{
DestroyVehicle(Tjet);
}
return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
return 1;
}

public OnPlayerEnterCheckpoint(playerid)
{
return 1;
}

public OnPlayerLeaveCheckpoint(playerid)
{
return 1;
}

public OnPlayerEnterRaceCheckpoint(playerid)
{
return 1;
}

public OnPlayerLeaveRaceCheckpoint(playerid)
{
return 1;
}

public OnRconCommand(cmd[])
{
return 1;
}

public OnPlayerRequestSpawn(playerid)
{
return 1;
}

public OnObjectMoved(objectid)
{
return 1;
}

public OnPlayerObjectMoved(playerid, objectid)
{
return 1;
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
if (pickupid==gdo)
{
new gcar0;
gcar0=GetPlayerVehicleID(playerid);
SetVehiclePos(gcar0,1460.4000200,-634.0999800,95.2000000);
return 1;
}
else if (pickupid==gdi)
{
gdo=CreatePickup(1559, 14, 1454.5000000,-675.5000000,1274.5999800, -1);
SetPlayerPos(playerid,1454.8000500,-672.0999800,1274.5000000);
return 1;
}
else if (pickupid==gdo2)
{
SetPlayerPos(playerid,1460.4000200,-634.0999800,95.2000000);
SetCameraBehindPlayer(playerid);
return 1;
}
return 1;
}

public OnVehicleMod(playerid, vehicleid, componentid)
{
return 1;
}

public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
{
return 1;
}

public OnVehicleRespray(playerid, vehicleid, color1, color2)
{
return 1;
}

public OnPlayerSelectedMenuRow(playerid, row)
{
return 1;
}

public OnPlayerExitedMenu(playerid)
{
return 1;
}

public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(newkeys == KEY_NO)
{
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
new engine, lights, alarm, doors, bonnet, boot, objective;
GetVehicleParamsEx(GetPlayerVehicleID(playerid), engine, lights, alarm, doors, bonnet, boot, objective);
if(engine == 1)
{
SetVehicleParamsEx(GetPlayerVehicleID(playerid), 0, lights, alarm, doors, bonnet, boot, objective);
}
else
{
SetVehicleParamsEx(GetPlayerVehicleID(playerid), 1, lights, alarm, doors, bonnet, boot, objective);
}
}
}
if(newkeys == KEY_SUBMISSION)
{
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
new engine, lights, alarm, doors, bonnet, boot, objective;
GetVehicleParamsEx(GetPlayerVehicleID(playerid), engine, lights, alarm, doors, bonnet, boot, objective);
if(lights == 0)
{
SetVehicleParamsEx(GetPlayerVehicleID(playerid), engine, 1, alarm, doors, bonnet, boot, objective);
}
else
{
SetVehicleParamsEx(GetPlayerVehicleID(playerid), engine, 0, alarm, doors, bonnet, boot, objective);
}
}
}
if(newkeys == KEY_ANALOG_UP)
{
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
new engine, lights, alarm, doors, bonnet, boot, objective;
GetVehicleParamsEx(GetPlayerVehicleID(playerid), engine, lights, alarm, doors, bonnet, boot, objective);
if(bonnet == 0)
{
SetVehicleParamsEx(GetPlayerVehicleID(playerid), engine, lights, alarm, doors, 1, boot, objective);
}
else
{
SetVehicleParamsEx(GetPlayerVehicleID(playerid), engine, lights, alarm, doors, 0, boot, objective);
}
}
}
if(newkeys == KEY_ANALOG_DOWN)
{
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
new engine, lights, alarm, doors, bonnet, boot, objective;
GetVehicleParamsEx(GetPlayerVehicleID(playerid), engine, lights, alarm, doors, bonnet, boot, objective);
if(boot == 0)
{
SetVehicleParamsEx(GetPlayerVehicleID(playerid), engine, lights, alarm, doors, bonnet, 1, objective);
}
else
{
SetVehicleParamsEx(GetPlayerVehicleID(playerid), engine, lights, alarm, doors, bonnet, 0, objective);
}
}
}
return 1;
}

public OnRconLoginAttempt(ip[], password[], success)
{
return 1;
}

public OnPlayerUpdate(playerid)
{
return 1;
}

public OnPlayerStreamIn(playerid, forplayerid)
{
return 1;
}

public OnPlayerStreamOut(playerid, forplayerid)
{
return 1;
}

public OnVehicleStreamIn(vehicleid, forplayerid)
{
return 1;
}

public OnVehicleStreamOut(vehicleid, forplayerid)
{
return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid==1 && response)
{
ShowPlayerDialog(playerid, 2, DIALOG_STYLE_LIST, "Choose a Race","White Males\nBlack Males\nOriental Males\nHispanic Males\nNative Males", "Select", "Back");
}
else if(dialogid==1 && !response)
{
ShowPlayerDialog(playerid, 3, DIALOG_STYLE_LIST, "Choose a Race","White Females\nBlack Females\nOriental Females\nHispanic Females\nNative Females", "Select", "Back");
}
if(dialogid==2 && response)
{
switch(listitem)
{
case 0:ShowPlayerDialog(playerid, 4, DIALOG_STYLE_LIST, "White Males","White Male 1\nWhite Male 2\nWhite Male 3","Select","Back");
case 1:ShowPlayerDialog(playerid, 5, DIALOG_STYLE_LIST, "Black Males","Black Male 1\nBlack Male 2\nBlack Male 3","Select","Back");
case 2:ShowPlayerDialog(playerid, 6, DIALOG_STYLE_LIST, "Oriental Males","Oriental Male 1\nOriental Male 2\nOriental Male 3","Select","Back");
case 3:ShowPlayerDialog(playerid, 7, DIALOG_STYLE_LIST, "Hispanic Males","Oriental Male 1\nOriental Male 2\nOriental Male 3","Select","Back");
case 4:ShowPlayerDialog(playerid, 8, DIALOG_STYLE_LIST, "Native Males","Oriental Male 1\nOriental Male 2\nOriental Male 3","Select","Back");
}
}
if(dialogid==3 && response)
{
switch(listitem)
{
case 0:ShowPlayerDialog(playerid, 9, DIALOG_STYLE_LIST, "White Females","White Male 1\nWhite Male 2\nWhite Male 3","Select","Back");
case 1:ShowPlayerDialog(playerid, 10, DIALOG_STYLE_LIST, "Black Females","Black Male 1\nBlack Male 2\nBlack Male 3","Select","Back");
case 2:ShowPlayerDialog(playerid, 11, DIALOG_STYLE_LIST, "Oriental Females","Oriental Male 1\nOriental Male 2\nOriental Male 3","Select","Back");
case 3:ShowPlayerDialog(playerid, 12, DIALOG_STYLE_LIST, "Hispanic Females","Oriental Male 1\nOriental Male 2\nOriental Male 3","Select","Back");
case 4:ShowPlayerDialog(playerid, 13, DIALOG_STYLE_LIST, "Native Females","Oriental Male 1\nOriental Male 2\nOriental Male 3","Select","Back");
}
}
if(dialogid==4 && response)
{
switch(listitem)
{
case 0:
{
SetPlayerSkin(playerid,29);
ShowPlayerDialog(playerid, 14, DIALOG_STYLE_MSGBOX, "Skin Selection", "Choose this skin for this session?", "Yes", "No");
return 1;
}
case 1:
{

return 1;
}
case 2:
{

return 1;
}
case 3:
{

return 1;
}
case 4:
{

return 1;
}
}
}
if(dialogid==14 && response)
{
SpawnPlayer(playerid);
SetPlayerSkin(playerid,29);
}
else if (dialogid==14 && !response)
{
SetPlayerSkin(playerid,0);
ShowPlayerDialog(playerid, 4, DIALOG_STYLE_LIST, "White Males","White Male 1\nWhite Male 2\nWhite Male 3","Select","Back");
}
return 0;
}

public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
return 1;
}

public OnPlayerText(playerid,text[])
{
new name[MAX_PLAYER_NAME], string[128];
GetPlayerRPName(playerid, name, sizeof(name));
format(string, sizeof(string), "%s: %s", name, text);
SendLocalMessage(playerid, COLOR_WHITE, 7,string);
return 0;
}



The Admin system I'm using (I edited my version slightly, to add additional chat channels):
http://forum.sa-mp.com/showthread.php?t=427582&highlight=j.l.admin

I have to catch some sleep, so until morning, I will be eagerly awaiting a helping hand. Thank You!

Threshold
12/02/2014, 10:28 AM
I guess you could use this as a separate filterscript if you wanted to. For this, you need to follow the following steps:

- Create a folder in your scriptfiles directory called 'Positions'. You should now have a '..\scriptfiles\Positions\' directory.
- You need the YSI Library (preferably), or at least the 'y_ini' include.

#include <a_samp>
#include <YSI\y_ini>

enum PosData
{
Float:X,
Float:Y,
Float:Z,
Float:Angle,
Skin
};
new Position[MAX_PLAYERS][PosData];
new bool:HasFirstSpawned[MAX_PLAYERS];

public OnPlayerDisconnect(playerid, reason)
{
new Float:x, Float:y, Float:z, Float:a;
GetPlayerPos(playerid, x, y, z);
GetPlayerFacingAngle(playerid, a);
new file[40], playername[MAX_PLAYER_NAME];
GetPlayerName(playerid, playername, sizeof(playername));
format(file, sizeof(file), "Positions/%s.ini", playername);
new INI:PFile = INI_Open(file);
INI_WriteFloat(PFile, "Pos_X", x);
INI_WriteFloat(PFile, "Pos_Y", y);
INI_WriteFloat(PFile, "Pos_Z", z);
INI_WriteFloat(PFile, "Pos_Angle", a);
INI_WriteInt(PFile, "Skin", GetPlayerSkin(playerid));
INI_Close(PFile);
return 1;
}

public OnPlayerConnect(playerid)
{
HasFirstSpawned[playerid] = false;
return 1;
}

public OnPlayerSpawn(playerid)
{
//Add important code here. (Ones that you want to run EVERY time a player spawns)
if(!HasFirstSpawned[playerid])
{
new file[40], playername[MAX_PLAYER_NAME];
GetPlayerName(playerid, playername, sizeof(playername));
format(file, sizeof(file), "Positions/%s.ini", playername);
INI_ParseFile(file, "LoadPositions_%s", .bExtra = true, .extra = playerid);
SetPlayerPos(playerid, Position[playerid][X], Position[playerid][Y], Position[playerid][Z]);
SetPlayerFacingAngle(playerid, Position[playerid][Angle]);
SetPlayerSkin(playerid, Position[playerid][Skin]);
HasFirstSpawned[playerid] = true;
return 1;
}
//Add other stuff here, like setting a player to respawn at certain locations.
return 1;
}

forward LoadPositions_data(playerid, name[], value[]);
public LoadPositions_data(playerid, name[], value[])
{
INI_Float("Pos_X", Position[playerid][X]);
INI_Float("Pos_Y", Position[playerid][Y]);
INI_Float("Pos_Z", Position[playerid][Z]);
INI_Float("Pos_Angle", Position[playerid][Angle]);
INI_Int("Skin", Position[playerid][Skin]);
return 1;
}

Aerotactics
12/02/2014, 07:53 PM
'Thank you for your help' and you've earned your rep. The only problem now is that, with my setup it's not working. Again thanks for your help, but I'm going to skip this problem for now and continue on with other things I need to do.