main () { } //Inc #include <a_samp> #include <Dini2> #include <streamer> #include "../include/gl_common.inc" //define #define GPC(%0) CallRemoteFunction("GPC", "i", %0) #define GPCK(%0) CallRemoteFunction("GPCK", "i", %0) #define GHID(%0) CallRemoteFunction("GHID", "i", %0) #define MAX_FURNITURE 3500 #define SCM SendClientMessage #define Dialog_Edit 4500 #define Dialog_Edit2 4503 #define Dialog_Down 4501 #define Dialog_GetRangeFurniture 4502 // enum fInfo { fID, fObject, fModel, Float:fX, Float:fY, Float:fZ, Float:fRX, Float:fRY, Float:fRZ, fvID, fInt, Text3D:fText, bool:fLiftup, fName[256], fOwner[256] } new FurnitureInfo[MAX_FURNITURE][fInfo]; new PlayerUseingFurniture[MAX_PLAYERS]; new bool:PlayerLiftup[MAX_PLAYERS]; new bool:PlayerEdit[MAX_PLAYERS]; new bool:PlayerPutDown[MAX_PLAYERS]; new RecoveryLiftTimer; new ShowPlayerRangeFurniture[MAX_PLAYERS][MAX_FURNITURE]; //Forward forward SaveFurniture(idx); forward LoadFurniture(); forward CreateFurniture(ID); forward Lift(playerid); forward PutDown(playerid); forward RecoveryLift(); // public SaveFurniture(idx) { new string[256]; format(string,sizeof(string),"Furniture/%d.ini",idx); if(!fexist(string)) { dini_Create(string); } dini_IntSet(string,"Model",FurnitureInfo[idx][fModel]); dini_FloatSet(string,"X",FurnitureInfo[idx][fX]); dini_FloatSet(string,"Y",FurnitureInfo[idx][fY]); dini_FloatSet(string,"Z",FurnitureInfo[idx][fZ]); dini_FloatSet(string,"RX",FurnitureInfo[idx][fRX]); dini_FloatSet(string,"RY",FurnitureInfo[idx][fRY]); dini_FloatSet(string,"RZ",FurnitureInfo[idx][fRZ]); dini_IntSet(string,"vID",FurnitureInfo[idx][fvID]); dini_IntSet(string,"Int",FurnitureInfo[idx][fInt]); dini_Set(string,"Name",FurnitureInfo[idx][fName]); dini_Set(string,"Owner",FurnitureInfo[idx][fOwner]); return 1; } public LoadFurniture() { for(new idx=1;idx<MAX_FURNITURE;idx++) { new string[256]; format(string,sizeof(string),"Furniture/%d.ini",idx); if(fexist(string)) { FurnitureInfo[idx][fID] = idx; FurnitureInfo[idx][fModel] = dini_Int(string,"Model"); FurnitureInfo[idx][fX] = dini_Float(string,"X"); FurnitureInfo[idx][fY] = dini_Float(string,"Y"); FurnitureInfo[idx][fZ] = dini_Float(string,"Z"); FurnitureInfo[idx][fRX] = dini_Float(string,"RX"); FurnitureInfo[idx][fRY] = dini_Float(string,"RY"); FurnitureInfo[idx][fRZ] = dini_Float(string,"RZ"); FurnitureInfo[idx][fvID] = dini_Int(string,"vID"); FurnitureInfo[idx][fInt] = dini_Int(string,"Int"); FurnitureInfo[idx][fName] = dini_Get(string,"Name"); FurnitureInfo[idx][fOwner] = dini_Get(string,"Owner"); CreateFurniture(idx); } } return 1; } public CreateFurniture(ID) { FurnitureInfo[ID][fObject] = CreateDynamicObject(FurnitureInfo[ID][fModel], FurnitureInfo[ID][fX], FurnitureInfo[ID][fY], FurnitureInfo[ID][fZ], FurnitureInfo[ID][fRX], FurnitureInfo[ID][fRY], FurnitureInfo[ID][fRZ], FurnitureInfo[ID][fvID], FurnitureInfo[ID][fInt]); new string[128]; format(string, sizeof(string), "%d", FurnitureInfo[ID][fID]); FurnitureInfo[ID][fText] = CreateDynamic3DTextLabel(string, 0xFFFFFFFF, FurnitureInfo[ID][fX], FurnitureInfo[ID][fY], FurnitureInfo[ID][fZ], 3.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, FurnitureInfo[ID][fvID], FurnitureInfo[ID][fInt]); return 1; } public Lift(playerid) { FurnitureInfo[PlayerUseingFurniture[playerid]][fLiftup] = true; PlayerLiftup[playerid] = true; ClearAnimations(playerid); ApplyAnimation(playerid, "CARRY", "crry_prtial", 4.0, 0, 0, 1, 1, 1); DestroyDynamic3DTextLabel(FurnitureInfo[PlayerUseingFurniture[playerid]][fText]); DestroyDynamicObject(FurnitureInfo[PlayerUseingFurniture[playerid]][fObject]); SetPlayerAttachedObject(playerid, 9, FurnitureInfo[PlayerUseingFurniture[playerid]][fModel], 1, 0, 0.6, 0, 0, 90, 0, 1, 1, 1); return 1; } public PutDown(playerid) { PlayerPutDown[playerid] = false; FurnitureInfo[PlayerUseingFurniture[playerid]][fLiftup] = false; GetPlayerPos(playerid, FurnitureInfo[PlayerUseingFurniture[playerid]][fX], FurnitureInfo[PlayerUseingFurniture[playerid]][fY], FurnitureInfo[PlayerUseingFurniture[playerid]][fZ]); FurnitureInfo[PlayerUseingFurniture[playerid]][fZ] -= 1.0; FurnitureInfo[PlayerUseingFurniture[playerid]][fRX] = 0.0; FurnitureInfo[PlayerUseingFurniture[playerid]][fRY] = 0.0; FurnitureInfo[PlayerUseingFurniture[playerid]][fRZ] = 0.0; FurnitureInfo[PlayerUseingFurniture[playerid]][fvID] = GetPlayerVirtualWorld(playerid); FurnitureInfo[PlayerUseingFurniture[playerid]][fInt] = GetPlayerInterior(playerid); new name[256],pName[MAX_PLAYER_NAME]; GetPlayerName(playerid, pName, MAX_PLAYER_NAME); format(name, sizeof(name), "%s",pName); FurnitureInfo[PlayerUseingFurniture[playerid]][fOwner]=name; CreateFurniture(PlayerUseingFurniture[playerid]); SaveFurniture(FurnitureInfo[PlayerUseingFurniture[playerid]][fID]); return 1; } public RecoveryLift() { for(new i=0; i<MAX_PLAYERS; i++) { if(!IsPlayerInAnyVehicle(i)) { if(GetPlayerAnimationIndex(i)) { if(PlayerLiftup[i] == true) { new animlib[32]; new animname[32]; GetAnimationName(GetPlayerAnimationIndex(i), animlib, 32, animname, 32); if(strcmp(animname, "crry_prtial", true) != 0) { ApplyAnimation(i, "CARRY", "crry_prtial", 4.0, 0, 0, 1, 1, 1); } } } } } return 1; } //Stock stock GetFurnitureID() { new i=1; while(i != MAX_FURNITURE) { if(FurnitureInfo[i][fID] == 0) { return i; } i++; } return -1; } stock GetClosestFurniture(playerid) { new i=1; while(i != MAX_FURNITURE) { if(IsPlayerInRangeOfPoint(playerid, 1.5, FurnitureInfo[i][fX], FurnitureInfo[i][fY], FurnitureInfo[i][fZ]) && FurnitureInfo[i][fLiftup] == false) { return i; } i++; } return -1; } PreloadAnimLib(playerid, animlib[]) { ApplyAnimation(playerid, animlib, "null", 0.0, 0, 0, 0, 0, 0); } //Function public OnFilterScriptInit() { LoadFurniture(); RecoveryLiftTimer = SetTimer("RecoveryLift", 2000, true); for(new i=0; i<=MAX_PLAYERS; i++) { if(IsPlayerConnected(i)) { PlayerUseingFurniture[i] = 0; PlayerLiftup[i] = false; PlayerPutDown[i] = false; } } return 1; } public OnFilterScriptExit() { KillTimer(RecoveryLiftTimer); for(new i=1; i<MAX_FURNITURE; i++) { if(FurnitureInfo[i][fID] != 0) { DestroyDynamic3DTextLabel(FurnitureInfo[i][fText]); DestroyDynamicObject(FurnitureInfo[i][fObject]); FurnitureInfo[i][fID] = 0; FurnitureInfo[i][fLiftup] = true; } } return 1; } public OnPlayerConnect(playerid) { PlayerUseingFurniture[playerid] = 0; PlayerLiftup[playerid] = false; PlayerPutDown[playerid] = false; // PreloadAnimLib(playerid, "CARRY"); PreloadAnimLib(playerid, "Freeweights"); return 1; } public OnPlayerDisconnect(playerid,reason) { if(PlayerLiftup[playerid] == true) { PlayerLiftup[playerid] = false; FurnitureInfo[PlayerUseingFurniture[playerid]][fLiftup] = false; CreateFurniture(PlayerUseingFurniture[playerid]); //SaveFurniture(FurnitureInfo[PlayerUseingFurniture[playerid]][fID]); RemovePlayerAttachedObject(playerid, 9); } if(PlayerEdit[playerid] == true) { PlayerEdit[playerid] = false; FurnitureInfo[PlayerUseingFurniture[playerid]][fLiftup] = false; new string[128]; format(string, sizeof(string), "%d", FurnitureInfo[PlayerUseingFurniture[playerid]][fID]); FurnitureInfo[PlayerUseingFurniture[playerid]][fText] = CreateDynamic3DTextLabel(string, 0xFFFFFFFF, FurnitureInfo[PlayerUseingFurniture[playerid]][fX], FurnitureInfo[PlayerUseingFurniture[playerid]][fY], FurnitureInfo[PlayerUseingFurniture[playerid]][fZ], 3.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, FurnitureInfo[PlayerUseingFurniture[playerid]][fvID], FurnitureInfo[PlayerUseingFurniture[playerid]][fInt]); //SaveFurniture(FurnitureInfo[PlayerUseingFurniture[playerid]][fID]); } return 1; } public OnPlayerSpawn(playerid) { if(PlayerLiftup[playerid] == true) { SetPlayerAttachedObject(playerid, 9, FurnitureInfo[PlayerUseingFurniture[playerid]][fModel], 1, 0, 0.6, 0, 0, 90, 0, 1, 1, 1); SCM(playerid,0xFFFFFFC8,"* You just died, furniture has been restore to your hands up."); } return 1; } public OnPlayerCommandText(playerid, cmdtext[]) { new idx; new cmd[256]; cmd = str(cmdtext, idx); if(strcmp(cmd,"/Create",true) == 0) { if(!IsPlayerAdmin(playerid)) return 0; new tmp[128], Model, Float:x, Float:y, Float:z; new NewID = GetFurnitureID(); tmp = str(cmdtext, idx); if(!strlen(tmp)) { SendClientMessage(playerid, 0xBFC0C2FF, "Use: /Create [Model]"); return 1; } Model = strval(tmp); if(NewID == -1) return SCM(playerid, 0xFF0000C8, "* No extra furniture that you can not continue to create."); GetPlayerPos(playerid,x,y,z); FurnitureInfo[NewID][fID] = NewID; FurnitureInfo[NewID][fModel] = Model; FurnitureInfo[NewID][fX] = x +1; FurnitureInfo[NewID][fY] = y +1; FurnitureInfo[NewID][fZ] = z; FurnitureInfo[NewID][fRX] = 0; FurnitureInfo[NewID][fRY] = 0; FurnitureInfo[NewID][fRZ] = 0; FurnitureInfo[NewID][fvID] = GetPlayerVirtualWorld(playerid); FurnitureInfo[NewID][fInt] = GetPlayerInterior(playerid); FurnitureInfo[NewID][fLiftup] = false; new name[256],owner[256]; format(name, sizeof(name), "未命名的家具"); FurnitureInfo[NewID][fName]=name; format(owner, sizeof(owner), "幻想城系统"); FurnitureInfo[NewID][fOwner]=owner; CreateFurniture(NewID); SaveFurniture(NewID); return 1; } if(strcmp(cmd,"/Remove",true) == 0) { if(!IsPlayerAdmin(playerid)) return 0; new tmp[128], id, string[256]; tmp = str(cmdtext, idx); if(!strlen(tmp)) { SCM(playerid, 0xB4B5B7FF, "Use: /Remove [Furniture ID]"); return 1; } id = strval(tmp); if(FurnitureInfo[id][fLiftup] == true) return SCM(playerid, 0xFFFF00C8, "* Someone is using this furniture! (Can not delete)"); DestroyDynamic3DTextLabel(FurnitureInfo[id][fText]); DestroyDynamicObject(FurnitureInfo[id][fObject]); FurnitureInfo[id][fID] = 0; FurnitureInfo[id][fLiftup] = true; format(string, sizeof(string), "Furniture/%d.ini", id); if(fexist(string)) { dini_Remove(string); format(string, sizeof(string), "* Successfully removed (Furniture ID: %d).", id); SCM(playerid, 0xFF0000C8, string); } else { format(string, sizeof(string), "* Error (Furniture ID: %d).", id); SCM(playerid, 0xFF0000C8, string); } return 1; } /*if(strcmp(cmd,"/near",true) == 0) { Dialog(playerid, 4499, DIALOG_STYLE_MSGBOX, "搜索家具", "搜索你附近300米的家具,并传送过去,获得坐标\n收费 $500\n此功能非常耗资源,无论你找到还是未找到,马上花费 $500", "搜索", "取消"); }*/ return 0; } public OnPlayerKeyStateChange(playerid, newkeys, oldkeys) { if(newkeys == 65536) { if(PlayerLiftup[playerid] == true) return Dialog(playerid, 999, DIALOG_STYLE_MSGBOX, "{ff0000}警告", "{ff0000}你正拿着家具", "Okay", ""); if(PlayerEdit[playerid] == true) return Dialog(playerid, 999, DIALOG_STYLE_MSGBOX, "{ff0000}警告", "{ff0000}你正在编辑家具", "Okay", ""); new string[256]; new string2[256]; if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT) { PlayerUseingFurniture[playerid] = GetClosestFurniture(playerid); if(PlayerUseingFurniture[playerid] != -1) { if(FurnitureInfo[PlayerUseingFurniture[playerid]][fvID]>1000) { if(GHID(playerid)+1000!=FurnitureInfo[PlayerUseingFurniture[playerid]][fvID]) { format(string, sizeof(string), "{FFFF80}家具ID: %d", FurnitureInfo[PlayerUseingFurniture[playerid]][fID]); format(string2, sizeof(string2), "{ff0000}这不是你的家具\n\n{FFFFFF}%s\n{C0C0C0}By:%s", FurnitureInfo[PlayerUseingFurniture[playerid]][fName],FurnitureInfo[PlayerUseingFurniture[playerid]][fOwner]); Dialog(playerid, 999, DIALOG_STYLE_MSGBOX, string, string2, "Okay", ""); return 1; } } if(GetPlayerVirtualWorld(playerid) != FurnitureInfo[PlayerUseingFurniture[playerid]][fvID] || GetPlayerInterior(playerid) != FurnitureInfo[PlayerUseingFurniture[playerid]][fInt]) return 1; format(string, sizeof(string), "{FFFF80}家具ID: %d", FurnitureInfo[PlayerUseingFurniture[playerid]][fID]); format(string2, sizeof(string2), "{FFFFFF}%s\n{C0C0C0}By:%s", FurnitureInfo[PlayerUseingFurniture[playerid]][fName],FurnitureInfo[PlayerUseingFurniture[playerid]][fOwner]); Dialog(playerid, Dialog_Edit, DIALOG_STYLE_MSGBOX, string, string2, "搬起", "选项"); } } } return 1; } public OnPlayerUpdate(playerid) { new k, ud, lr; GetPlayerKeys(playerid, k, ud, lr); if(k == 128) { if(PlayerLiftup[playerid] == true && PlayerPutDown[playerid] == false) { Dialog(playerid, Dialog_Down, DIALOG_STYLE_MSGBOX, "家具", "是否放下?", "放下", "取消"); } } if(PlayerEdit[playerid] == true) { if(!IsPlayerInRangeOfPoint(playerid, 200, FurnitureInfo[PlayerUseingFurniture[playerid]][fX],FurnitureInfo[PlayerUseingFurniture[playerid]][fY],FurnitureInfo[PlayerUseingFurniture[playerid]][fZ])) { PlayerEdit[playerid] = false; DestroyDynamicObject(FurnitureInfo[PlayerUseingFurniture[playerid]][fObject]); CreateFurniture(PlayerUseingFurniture[playerid]); CancelEdit(playerid); FurnitureInfo[PlayerUseingFurniture[playerid]][fX] = FurnitureInfo[PlayerUseingFurniture[playerid]][fX]; FurnitureInfo[PlayerUseingFurniture[playerid]][fY] = FurnitureInfo[PlayerUseingFurniture[playerid]][fY]; FurnitureInfo[PlayerUseingFurniture[playerid]][fZ] = FurnitureInfo[PlayerUseingFurniture[playerid]][fZ]; FurnitureInfo[PlayerUseingFurniture[playerid]][fRX] = FurnitureInfo[PlayerUseingFurniture[playerid]][fRX]; FurnitureInfo[PlayerUseingFurniture[playerid]][fRY] = FurnitureInfo[PlayerUseingFurniture[playerid]][fRY]; FurnitureInfo[PlayerUseingFurniture[playerid]][fRZ] = FurnitureInfo[PlayerUseingFurniture[playerid]][fRZ]; FurnitureInfo[PlayerUseingFurniture[playerid]][fLiftup] = false; Dialog(playerid,999,DIALOG_STYLE_MSGBOX,"{ff0000}警告","{FF0000}距离过远,自动退出,家具返回原来位置","Okay",""); } } return 1; } public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) { if(dialogid == Dialog_Edit) { if(response) { if(!IsPlayerInRangeOfPoint(playerid, 1.5, FurnitureInfo[PlayerUseingFurniture[playerid]][fX],FurnitureInfo[PlayerUseingFurniture[playerid]][fY],FurnitureInfo[PlayerUseingFurniture[playerid]][fZ])) return Dialog(playerid,999,DIALOG_STYLE_MSGBOX,"{ff0000}警告","{FF0000}你不在家具附近","Okay",""); //ApplyAnimation(playerid, "CARRY", "liftup", 4, 0, 0, 0, 0, 0); SCM(playerid, -1, "提示:按鼠标右键可以放下家具"); FurnitureInfo[PlayerUseingFurniture[playerid]][fLiftup] = true; PlayerLiftup[playerid] = true; ClearAnimations(playerid); ApplyAnimation(playerid, "CARRY", "crry_prtial", 4.0, 0, 0, 1, 1, 1); DestroyDynamic3DTextLabel(FurnitureInfo[PlayerUseingFurniture[playerid]][fText]); DestroyDynamicObject(FurnitureInfo[PlayerUseingFurniture[playerid]][fObject]); SetPlayerAttachedObject(playerid, 9, FurnitureInfo[PlayerUseingFurniture[playerid]][fModel], 1, 0, 0.6, 0, 0, 90, 0, 1, 1, 1); } if(!response) { new string[256]; format(string, sizeof(string), "{FFFF80}家具ID: %d", FurnitureInfo[PlayerUseingFurniture[playerid]][fID]); Dialog(playerid, Dialog_Edit2, DIALOG_STYLE_LIST, string, "编辑位置\n家具名称", "选择", "关闭"); } } if(dialogid == Dialog_Edit2) { if(response) { if(!IsPlayerInRangeOfPoint(playerid, 1.5, FurnitureInfo[PlayerUseingFurniture[playerid]][fX],FurnitureInfo[PlayerUseingFurniture[playerid]][fY],FurnitureInfo[PlayerUseingFurniture[playerid]][fZ])) return Dialog(playerid,999,DIALOG_STYLE_MSGBOX,"{ff0000}警告","{FF0000}你不在家具附近","Okay",""); if(listitem == 0) { if(GetPlayerVirtualWorld(playerid)<1000) return Dialog(playerid, 999, DIALOG_STYLE_MSGBOX, "{ff0000}警告", "{ff0000}这个家具不在房子里,无法编辑", "Okay", ""); FurnitureInfo[PlayerUseingFurniture[playerid]][fLiftup] = true; PlayerEdit[playerid] = true; DestroyDynamic3DTextLabel(FurnitureInfo[PlayerUseingFurniture[playerid]][fText]); EditDynamicObject(playerid, FurnitureInfo[PlayerUseingFurniture[playerid]][fObject]); } if(listitem == 1) { Dialog(playerid,4505,DIALOG_STYLE_INPUT,"家具名称","设置你的家具名称,在按Y后会显示在对话框\n{ff0000}如果内容带有辱骂这个家具将会被删除","设置","取消"); } } } if(dialogid == 4505) { if(response) { if(strlen(inputtext)<1) return Dialog(playerid, 999, DIALOG_STYLE_MSGBOX, "{ff0000}警告", "{ff0000}请输入家具名称", "Okay", ""); if(strlen(inputtext)>20) return Dialog(playerid, 999, DIALOG_STYLE_MSGBOX, "{ff0000}警告", "{ff0000}最多20个字符", "Okay", ""); new name[256]; format(name, sizeof(name), "%s",inputtext); FurnitureInfo[PlayerUseingFurniture[playerid]][fName]=name; Dialog(playerid, 999, DIALOG_STYLE_MSGBOX, "家具名称", "设置成功!", "Okay", ""); } } if(dialogid == Dialog_Down) { if(response) { if(GetPlayerVirtualWorld(playerid)>0){if(GetPlayerVirtualWorld(playerid)<1000) return Dialog(playerid, 999, DIALOG_STYLE_MSGBOX, "{ff0000}警告", "{ff0000}禁止在非大世界里放下家具", "Okay", "");} if(PlayerLiftup[playerid] == false) return Dialog(playerid, 999, DIALOG_STYLE_MSGBOX, "{ff0000}警告", "{ff0000}你手上没有拿着家具", "Okay",""); ApplyAnimation(playerid, "CARRY", "putdwn", 4.0, 0, 0, 0, 0, 0); SetTimerEx("PutDown", 1100, false, "i", playerid); RemovePlayerAttachedObject(playerid, 9); PlayerPutDown[playerid] = true; PlayerLiftup[playerid] = false; } } if(dialogid == 4499) { if(GPC(playerid)<500) return Dialog(playerid, 999, DIALOG_STYLE_MSGBOX, "{ff0000}警告", "{ff0000}你现金不够$500", "Okay",""); CallRemoteFunction( "SPC1", "ii", playerid, 500 );//扣钱 new string[256]; new id = 0; for(new i=1; i<MAX_FURNITURE; i++) { if(IsPlayerInRangeOfPoint(playerid, 300, FurnitureInfo[i][fX], FurnitureInfo[i][fY], FurnitureInfo[i][fZ]) && FurnitureInfo[i][fLiftup] == false) { new Smg[128]; format(Smg, sizeof(Smg), "ID: %d\n", FurnitureInfo[i][fID]); strcat(string, Smg); ShowPlayerRangeFurniture[playerid][id] = FurnitureInfo[i][fID]; id ++; } } if(id==0) return Dialog(playerid, 999, DIALOG_STYLE_MSGBOX, "{ff0000}警告", "{ff0000}你附近300米没有任何家具", "Okay",""); Dialog(playerid, Dialog_GetRangeFurniture, DIALOG_STYLE_LIST, "传送最近家具", string, "传送","关闭"); } if(dialogid == Dialog_GetRangeFurniture) { if(!response) return 1; SetPlayerPos(playerid,FurnitureInfo[PlayerUseingFurniture[playerid]][fX], FurnitureInfo[PlayerUseingFurniture[playerid]][fY], FurnitureInfo[PlayerUseingFurniture[playerid]][fZ]); new string[256]; PlayerUseingFurniture[playerid] = ShowPlayerRangeFurniture[playerid][listitem]; format(string, sizeof(string), "家具 %d 的坐标:\nX: %f\nY: %f\nZ: %f", FurnitureInfo[PlayerUseingFurniture[playerid]][fID],FurnitureInfo[PlayerUseingFurniture[playerid]][fX], FurnitureInfo[PlayerUseingFurniture[playerid]][fY], FurnitureInfo[PlayerUseingFurniture[playerid]][fZ]); Dialog(playerid, 999, DIALOG_STYLE_MSGBOX, "家具坐标", string, "Okay", ""); } return 0; } //Inc Public public OnPlayerEditDynamicObject(playerid, objectid, response, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz) { new Float:oldX, Float:oldY, Float:oldZ,Float:oldRotX, Float:oldRotY, Float:oldRotZ; new string[256]; format(string,sizeof(string),"%d", FurnitureInfo[PlayerUseingFurniture[playerid]][fID]); GetDynamicObjectPos(objectid, oldX, oldY, oldZ); GetDynamicObjectRot(objectid, oldRotX, oldRotY, oldRotZ); /*if(GetPVarInt(playerid,"IsSet")==0) { SetPVarFloat(playerid,"lastx",FurnitureInfo[PlayerUseingFurniture[playerid]][fX]); SetPVarFloat(playerid,"lasty",FurnitureInfo[PlayerUseingFurniture[playerid]][fY]); SetPVarFloat(playerid,"lastz",FurnitureInfo[PlayerUseingFurniture[playerid]][fY]); SetPVarFloat(playerid,"lastrx",FurnitureInfo[PlayerUseingFurniture[playerid]][fRX]); SetPVarFloat(playerid,"lastry",FurnitureInfo[PlayerUseingFurniture[playerid]][fRY]); SetPVarFloat(playerid,"lastrz",FurnitureInfo[PlayerUseingFurniture[playerid]][fRZ]); SetPVarInt(playerid,"lasti",FurnitureInfo[PlayerUseingFurniture[playerid]][fInt]); SetPVarInt(playerid,"lastv",FurnitureInfo[PlayerUseingFurniture[playerid]][fvID]); SetPVarString(playerid,"laststring",string); SetPVarInt(playerid,"IsSet",1); } if(!IsPlayerInRangeOfPoint(playerid, 10, FurnitureInfo[PlayerUseingFurniture[playerid]][fX],FurnitureInfo[PlayerUseingFurniture[playerid]][fY],FurnitureInfo[PlayerUseingFurniture[playerid]][fZ])) { SetDynamicObjectPos(objectid, GetPVarFloat(playerid,"lastx"),GetPVarFloat(playerid,"lasty"),GetPVarFloat(playerid,"lastz")); SetDynamicObjectRot(objectid, GetPVarFloat(playerid,"lastrx"),GetPVarFloat(playerid,"lastry"),GetPVarFloat(playerid,"lastrz")); FurnitureInfo[PlayerUseingFurniture[playerid]][fX] = GetPVarFloat(playerid,"lastx"); FurnitureInfo[PlayerUseingFurniture[playerid]][fY] = GetPVarFloat(playerid,"lasty"); FurnitureInfo[PlayerUseingFurniture[playerid]][fZ] = GetPVarFloat(playerid,"lastz"); FurnitureInfo[PlayerUseingFurniture[playerid]][fRX] = GetPVarFloat(playerid,"lastrx"); FurnitureInfo[PlayerUseingFurniture[playerid]][fRY] = GetPVarFloat(playerid,"lastry"); FurnitureInfo[PlayerUseingFurniture[playerid]][fRZ] = GetPVarFloat(playerid,"lastrz"); FurnitureInfo[PlayerUseingFurniture[playerid]][fvID] = GetPVarInt(playerid,"lastv"); FurnitureInfo[PlayerUseingFurniture[playerid]][fInt] = GetPVarInt(playerid,"lasti"); FurnitureInfo[PlayerUseingFurniture[playerid]][fText] = CreateDynamic3DTextLabel(string, 0xFFFFFFFF, FurnitureInfo[PlayerUseingFurniture[playerid]][fX], FurnitureInfo[PlayerUseingFurniture[playerid]][fY], FurnitureInfo[PlayerUseingFurniture[playerid]][fZ], 3.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, FurnitureInfo[PlayerUseingFurniture[playerid]][fvID], FurnitureInfo[PlayerUseingFurniture[playerid]][fInt]); FurnitureInfo[PlayerUseingFurniture[playerid]][fLiftup] = false; PlayerEdit[playerid] = false; Dialog(playerid,999,DIALOG_STYLE_MSGBOX,"{ff0000}警告","{FF0000}距离过远,自动退出,家具返回原来位置","Okay",""); return 1; }*/ if(response == EDIT_RESPONSE_FINAL) { FurnitureInfo[PlayerUseingFurniture[playerid]][fX] = x; FurnitureInfo[PlayerUseingFurniture[playerid]][fY] = y; FurnitureInfo[PlayerUseingFurniture[playerid]][fZ] = z; FurnitureInfo[PlayerUseingFurniture[playerid]][fRX] = rx; FurnitureInfo[PlayerUseingFurniture[playerid]][fRY] = ry; FurnitureInfo[PlayerUseingFurniture[playerid]][fRZ] = rz; FurnitureInfo[PlayerUseingFurniture[playerid]][fvID] = GetPlayerVirtualWorld(playerid); FurnitureInfo[PlayerUseingFurniture[playerid]][fInt] = GetPlayerInterior(playerid); SetDynamicObjectPos(objectid, x, y, z); SetDynamicObjectRot(objectid, rx, ry, rz); FurnitureInfo[PlayerUseingFurniture[playerid]][fText] = CreateDynamic3DTextLabel(string, 0xFFFFFFFF, FurnitureInfo[PlayerUseingFurniture[playerid]][fX], FurnitureInfo[PlayerUseingFurniture[playerid]][fY], FurnitureInfo[PlayerUseingFurniture[playerid]][fZ], 3.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, FurnitureInfo[PlayerUseingFurniture[playerid]][fvID], FurnitureInfo[PlayerUseingFurniture[playerid]][fInt]); SaveFurniture(FurnitureInfo[PlayerUseingFurniture[playerid]][fID]); FurnitureInfo[PlayerUseingFurniture[playerid]][fLiftup] = false; SCM(playerid,-1,"{FFFF80}保存"); PlayerEdit[playerid] = false; } if(response == EDIT_RESPONSE_CANCEL) { SetDynamicObjectPos(objectid, oldX, oldY, oldZ); SetDynamicObjectRot(objectid, oldRotX, oldRotY, oldRotZ); FurnitureInfo[PlayerUseingFurniture[playerid]][fX] = oldX; FurnitureInfo[PlayerUseingFurniture[playerid]][fY] = oldY; FurnitureInfo[PlayerUseingFurniture[playerid]][fZ] = oldZ; FurnitureInfo[PlayerUseingFurniture[playerid]][fRX] = oldRotX; FurnitureInfo[PlayerUseingFurniture[playerid]][fRY] = oldRotY; FurnitureInfo[PlayerUseingFurniture[playerid]][fRZ] = oldRotZ; FurnitureInfo[PlayerUseingFurniture[playerid]][fvID] = GetPlayerVirtualWorld(playerid); FurnitureInfo[PlayerUseingFurniture[playerid]][fInt] = GetPlayerInterior(playerid); FurnitureInfo[PlayerUseingFurniture[playerid]][fText] = CreateDynamic3DTextLabel(string, 0xFFFFFFFF, FurnitureInfo[PlayerUseingFurniture[playerid]][fX], FurnitureInfo[PlayerUseingFurniture[playerid]][fY], FurnitureInfo[PlayerUseingFurniture[playerid]][fZ], 3.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, FurnitureInfo[PlayerUseingFurniture[playerid]][fvID], FurnitureInfo[PlayerUseingFurniture[playerid]][fInt]); FurnitureInfo[PlayerUseingFurniture[playerid]][fLiftup] = false; SCM(playerid,-1,"{FF0000}取消"); PlayerEdit[playerid] = false; } return 1; } Dialog(playerid, dialogid, style, caption[], info[], button1[], button2[]) { ShowPlayerDialog(playerid, dialogid, style, caption, info, button1, button2); return SetPVarInt(playerid,"DialogID",dialogid); } stock str(const string[], &index) { new length = strlen(string); while ((index < length) && (string[index] <= ' ')) { index++; } new offset = index; new result[20]; while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1))) { result[index - offset] = string[index]; index++; } result[index - offset] = EOS; return result; }
fName[256],
fOwner[256]
fName[MAX_PLAYER_NAME],
fOwner[MAX_PLAYER_NAME]
public PutDown(playerid) { PlayerPutDown[playerid] = false; FurnitureInfo[PlayerUseingFurniture[playerid]][fLiftup] = false; GetPlayerPos(playerid, FurnitureInfo[PlayerUseingFurniture[playerid]][fX], FurnitureInfo[PlayerUseingFurniture[playerid]][fY], FurnitureInfo[PlayerUseingFurniture[playerid]][fZ]); FurnitureInfo[PlayerUseingFurniture[playerid]][fZ] -= 1.0; FurnitureInfo[PlayerUseingFurniture[playerid]][fRX] = 0.0; FurnitureInfo[PlayerUseingFurniture[playerid]][fRY] = 0.0; FurnitureInfo[PlayerUseingFurniture[playerid]][fRZ] = 0.0; FurnitureInfo[PlayerUseingFurniture[playerid]][fvID] = GetPlayerVirtualWorld(playerid); FurnitureInfo[PlayerUseingFurniture[playerid]][fInt] = GetPlayerInterior(playerid); new name[256],pName[MAX_PLAYER_NAME]; GetPlayerName(playerid, pName, MAX_PLAYER_NAME); format(name, sizeof(name), "%s",pName); FurnitureInfo[PlayerUseingFurniture[playerid]][fOwner]=name;
new pName[MAX_PLAYER_NAME]; GetPlayerName(playerid, pName, MAX_PLAYER_NAME); FurnitureInfo[PlayerUseingFurniture[playerid]][fOwner] = pName;
You're lucky the axm size isn't bigger than 5Mb.
If you take the array-size into account: 3500 indices x (256 cells for one field, 256 cells for another field) x 4 bytes per cell = 3500 x 512 x 4 = 7.168.000 bytes. That's 6.8Mb for that array alone. Like suggested earlier, only use the size for a playername (24 cells instead of 256). Reducing this to it's proper size alone would give you an array of: 3500 x (24 + 24) x 4 = 3500 x 48 x 4 = 672.000 bytes or 656Kb. It's 1/10th the size. Or better yet: Give every player a unique number as his ID (not the ingame playerid but an account-ID in your saving system). Then you can replace those fields by an integer. Your array would shrink to this size: 3500 indices x (1 cell for the first ID, 1 cell for the second ID) x 4 bytes per cell = 3500 x 2 x 4 = 28.000 bytes = 27Kb. That's 256 times smaller than before and it still contains the same information. Not the name of the player per se, but still his ID, which you can use to get the name from. To make this effective, you should convert to MySQL. It's not that hard to learn and it's faster and more flexible than ini-files. In the beginning, I also didn't wanna learn MySQL because I thought my own saving system was good enough. But once I learned the advantages of MySQL, I'll never go back to using files. And don't worry over a few Mb of RAM nowadays. Any modern pc has at least 4Gb of RAM onboard, servers even have more RAM. My own pc has 12Gb of RAM. Also, most modern games are at least 4Gb on your harddrive. If you compare it to those games, what's 5Mb? But still, even with so much RAM, you shouldn't waste it unneccessarily. Only use what you need (24 cells for a playername, not 256), or go for account-id's instead if you use a database. Looking at the code further down: Код:
public PutDown(playerid) { PlayerPutDown[playerid] = false; FurnitureInfo[PlayerUseingFurniture[playerid]][fLiftup] = false; GetPlayerPos(playerid, FurnitureInfo[PlayerUseingFurniture[playerid]][fX], FurnitureInfo[PlayerUseingFurniture[playerid]][fY], FurnitureInfo[PlayerUseingFurniture[playerid]][fZ]); FurnitureInfo[PlayerUseingFurniture[playerid]][fZ] -= 1.0; FurnitureInfo[PlayerUseingFurniture[playerid]][fRX] = 0.0; FurnitureInfo[PlayerUseingFurniture[playerid]][fRY] = 0.0; FurnitureInfo[PlayerUseingFurniture[playerid]][fRZ] = 0.0; FurnitureInfo[PlayerUseingFurniture[playerid]][fvID] = GetPlayerVirtualWorld(playerid); FurnitureInfo[PlayerUseingFurniture[playerid]][fInt] = GetPlayerInterior(playerid); new name[256],pName[MAX_PLAYER_NAME]; GetPlayerName(playerid, pName, MAX_PLAYER_NAME); format(name, sizeof(name), "%s",pName); FurnitureInfo[PlayerUseingFurniture[playerid]][fOwner]=name; It makes a variable "name" of 256 cells, it gets the playername (which is only 24 bytes for "pName"), stores it into "name" and copies it to the array. Код:
new pName[MAX_PLAYER_NAME]; GetPlayerName(playerid, pName, MAX_PLAYER_NAME); FurnitureInfo[PlayerUseingFurniture[playerid]][fOwner] = pName; There might be more places in that code where you make make such improvements. |
error 047: array sizes do not match, or destination array is too small