/* __________________________________________________ ______________________________ _______ _ _____ _ |__ __| | | / ____| | | | | ___ _ __ | |_ | (___ _ _ ___| |_ ___ _ __ ___ | |/ _ \ '_ \| __| \___ \| | | / __| __/ _ \ '_ ` _ \ | | __/ | | | |_ ____) | |_| \__ \ || __/ | | | | | |_|\___|_| |_|\__| |_____/ \__, |___/\__\___|_| |_| |_| __/ | |___/ __________________________________________________ ______________________________ */ #define FILTERSCRIPT #include <a_samp> #include <zcmd> #include <streamer> #include <YSI\y_ini> #define SYSTEMNAME "Tent System" #define SCRIPTER "miedo" #define VERSION "0.1" #define MAX_TENTS 100 #define TENTS_PER_PLAYER 2 enum tInfo { tOwner[MAX_PLAYER_NAME], tPlaced, Float:tPosX, Float:tPosY, Float:tPosZ, Float:tRX, Float:tRY, Float:tRZ, tObject, Text3D:tText } new TentInfo[MAX_TENTS][tInfo], EditingTentID[MAX_PLAYERS] = {-1, ...}; stock GetAccountName(playerid) { new name[MAX_PLAYER_NAME]; GetPlayerName(playerid,name,sizeof(name)); for(new i = 0; i < MAX_PLAYER_NAME; i++) { if(name[i] == '_') name[i] = ' '; } return name; } stock GetTentCount(playerid) { new count = 0; for(new i; i < MAX_TENTS; i++) { if(!TentInfo[i][tPlaced]) continue; if(!strcmp(TentInfo[i][tOwner], GetAccountName(playerid))) count++; } return count; } stock GetNearestTent(playerid) { new id = -1, Float: dist = 4.0, Float: tempdist; for(new i; i < MAX_TENTS; i++) { if(!TentInfo[i][tPlaced]) continue; tempdist = GetPlayerDistanceFromPoint(playerid, TentInfo[i][tPosX], TentInfo[i][tPosY], TentInfo[i][tPosZ]); if(tempdist <= dist) { dist = tempdist; id = i; break; } } return id; } stock SaveTent(id) { new file[64]; format(file, sizeof(file), "tents/%d.ini", id); new INI:fHandle = INI_Open(file); if(fHandle != INI_NO_FILE) { INI_SetTag(fHandle, "tent_info"); INI_WriteString(fHandle, "Owner", TentInfo[id][tOwner]); INI_WriteFloat(fHandle, "TentX", TentInfo[id][tPosX]); INI_WriteFloat(fHandle, "TentY", TentInfo[id][tPosY]); INI_WriteFloat(fHandle, "TentZ", TentInfo[id][tPosZ]); INI_WriteFloat(fHandle, "TentRotX", TentInfo[id][tRX]); INI_WriteFloat(fHandle, "TentRotY", TentInfo[id][tRY]); INI_WriteFloat(fHandle, "TentRotZ", TentInfo[id][tRZ]); INI_Close(fHandle); } return 1; } forward LoadTent(id, name[], value[]); public LoadTent(id, name[], value[]) { INI_String("Owner", TentInfo[id][tOwner], MAX_PLAYER_NAME); INI_Float("TentX", TentInfo[id][tPosX]); INI_Float("TentY", TentInfo[id][tPosY]); INI_Float("TentZ", TentInfo[id][tPosZ]); INI_Float("TentRotX", TentInfo[id][tRX]); INI_Float("TentRotY", TentInfo[id][tRY]); INI_Float("TentRotZ", TentInfo[id][tRZ]); return 1; } public OnFilterScriptInit() { new file[64], label[96]; for(new i; i < MAX_TENTS; i++) { format(file, sizeof(file), "tents/%d.ini", i); if(fexist(file)) { INI_ParseFile(file, "LoadTent", .bExtra = true, .extra = i); format(label, sizeof(label), "{4B8A5C}Tent\nOwner: {FFFFFF}%s", TentInfo[i][tOwner]); TentInfo[i][tText] = CreateDynamic3DTextLabel(label, 0xFF9900FF, TentInfo[i][tPosX], TentInfo[i][tPosY], TentInfo[i][tPosZ]+2.0, 15.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0); TentInfo[i][tObject] = CreateDynamicObject(3243, TentInfo[i][tPosX], TentInfo[i][tPosY], TentInfo[i][tPosZ], TentInfo[i][tRX], TentInfo[i][tRY], TentInfo[i][tRZ]); TentInfo[i][tPlaced] = 1; } } print("\n----------------------------------"); printf(" %s loaded successfully.", SYSTEMNAME); printf(" Scripter: %s", SCRIPTER); printf(" System Version: %s", VERSION); print("----------------------------------\n"); return 1; } public OnFilterScriptExit() { for(new i; i < MAX_TENTS; i++) { if(TentInfo[i][tPlaced]) SaveTent(i); } return 1; } public OnPlayerConnect(playerid) { EditingTentID[playerid] = -1; return 1; } public OnPlayerEditDynamicObject(playerid, objectid, response, Float, Float:y, Float:z, Float:rx, Float:ry, Float:rz) { if(response == EDIT_RESPONSE_FINAL) { new id = EditingTentID[playerid]; if(id != -1) { TentInfo[id][tPosX] = x; TentInfo[id][tPosY] = y; TentInfo[id][tPosZ] = z; TentInfo[id][tRX] = rx; TentInfo[id][tRY] = ry; TentInfo[id][tRZ] = rz; Streamer_SetFloatData(STREAMER_TYPE_3D_TEXT_LABEL, TentInfo[id][tText], E_STREAMER_X, x); Streamer_SetFloatData(STREAMER_TYPE_3D_TEXT_LABEL, TentInfo[id][tText], E_STREAMER_Y, y); Streamer_SetFloatData(STREAMER_TYPE_3D_TEXT_LABEL, TentInfo[id][tText], E_STREAMER_Z, z+2.0); SetDynamicObjectPos(objectid, x, y, z); SetDynamicObjectRot(objectid, rx, ry, rz); EditingTentID[playerid] = -1; SaveTent(id); } }else if(response == EDIT_RESPONSE_CANCEL) { new id = EditingTentID[playerid]; if(id != -1) { SetDynamicObjectPos(objectid, TentInfo[id][tPosX], TentInfo[id][tPosY], TentInfo[id][tPosZ]); SetDynamicObjectRot(objectid, TentInfo[id][tRX], TentInfo[id][tRY], TentInfo[id][tRZ]); EditingTentID[playerid] = -1; } } } public OnPlayerEditObject(playerid, playerobject, objectid, response, Float:fX, Float:fY, Float:fZ, Float:fRotX, Float:fRotY, Float:fRotZ) {} CMDlacetent(playerid, params[]) { new id = -1; for(new i; i < MAX_TENTS; i++) { if(!TentInfo[i][tPlaced]) { id = i; break; } } if(id == -1) return SendClientMessage(playerid, -1, "{4B8A5C}Tent System: {FFFFFF}Reached tent limit."); if(GetTentCount(playerid)+1 > TENTS_PER_PLAYER) return SendClientMessage(playerid, -1, "{4B8A5C}Tent System: {FFFFFF}You can't place any more tents."); new Float:X, Float:Y, Float:Z, Float: A, string[96]; GetPlayerPos(playerid, X, Y, Z); GetPlayerFacingAngle(playerid, A); X += (6.0 * floatsin(-A, degrees)); Y += (6.0 * floatcos(-A, degrees)); TentInfo[id][tOwner] = GetAccountName(playerid); TentInfo[id][tPlaced] = 1; TentInfo[id][tPosX] = X; TentInfo[id][tPosY] = Y; TentInfo[id][tPosZ] = Z - 0.90; TentInfo[id][tRZ] = A + 180.0; format(string, sizeof(string), "{4B8A5C}Tent\nOwner: {FFFFFF}%s", TentInfo[id][tOwner]); TentInfo[id][tText] = CreateDynamic3DTextLabel(string, 0xFF9900FF, TentInfo[id][tPosX], TentInfo[id][tPosY], TentInfo[id][tPosZ]+2.0, 15.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0); TentInfo[id][tObject] = CreateDynamicObject(3243, TentInfo[id][tPosX], TentInfo[id][tPosY], TentInfo[id][tPosZ], TentInfo[id][tRX], TentInfo[id][tRY], TentInfo[id][tRZ]); SendClientMessage(playerid, -1, "{4B8A5C}Tent System: {FFFFFF}Tent placed successfully. You can edit it use '/edittent' command."); SaveTent(id); return 1; } CMD:destroytent(playerid, params[]) { new id = GetNearestTent(playerid); if(id == -1) return SendClientMessage(playerid, -1, "{4B8A5C}Tent System: {FFFFFF}You're not near a tent."); if(strcmp(TentInfo[id][tOwner], GetAccountName(playerid))) return SendClientMessage(playerid, -1, "{4B8A5C}Tent System: {FFFFFF}This tent isn't yours."); TentInfo[id][tOwner] = 0; TentInfo[id][tPlaced] = 0; TentInfo[id][tPosX] = 0; TentInfo[id][tPosY] = 0; TentInfo[id][tPosZ] = 0; TentInfo[id][tRX] = 0; TentInfo[id][tRY] = 0; TentInfo[id][tRZ] = 0; DestroyDynamic3DTextLabel(TentInfo[id][tText]); DestroyDynamicObject(TentInfo[id][tObject]); new file[64]; format(file, sizeof(file), "tents/%d.ini", id); if(fexist(file)) fremove(file); SendClientMessage(playerid, -1, "{4B8A5C}Tent System: {FFFFFF}Tent destroyed successfully."); return 1; } CMD:edittent(playerid, params[]) { if(EditingTentID[playerid] != -1) return SendClientMessage(playerid, -1, "{4B8A5C}Tent System: {FFFFFF}You're already editing a tent."); new id = GetNearestTent(playerid); if(id == -1) return SendClientMessage(playerid, -1, "{4B8A5C}Tent System: {FFFFFF}You're not near a tent."); if(strcmp(TentInfo[id][tOwner], GetAccountName(playerid))) return SendClientMessage(playerid, -1, "{4B8A5C}Tent System: {FFFFFF}This tent isn't yours."); EditingTentID[playerid] = id; EditDynamicObject(playerid, TentInfo[id][tObject]); SendClientMessage(playerid, -1, "You can edit your tent now."); return 1; } |
return true;
public OnPlayerEditObject