27.07.2012, 14:25
Код:
warning 219: local variable "tmp" shadows a variable at a preceding level <<7 Warnings.
Код:
/*===================================================================================================*\ ||===================================================================================================|| || ________ ________ ___ _ ______ ______ ________ || || \ | _____| | ____ | | \ | | | _ \ | _ \ | ____ | / || || ======== \ | |_____ | |____| | | |\ \ | | | | | | | |_| / | |____| | / ======== || || | | _____ | | ____ | | | \ \| | | | | | | _ \ | ____ | | || || ======== / ______| | | | | | | | \ \ | | |_| | | | \ \ | | | | \ ======== || || / |________| |_| |_| |_| \__| |______/ |_| \_| |_| |_| \ || || || || || || Example Property Filterscript || || || ||===================================================================================================|| || Created on the 2nd of April 2008 by =>Sandra<= || || Do NOT remove any credits!! || \*===================================================================================================*/ #include <a_samp> #include <properties> #define MAX_PROPERTIES 250 #define CREATE_PICKUPS new TmpPickup[MAX_PROPERTIES]; new TotalPickups; public OnFilterScriptInit() { print("----------------------------------------"); print(" Example Property Filterscript "); print(" by =>Sandra<= "); print("----------------------------------------"); new File:fhnd; if(!fexist("SavedProperties.txt")) { fhnd=fopen("SavedProperties.txt",io_write); fclose(fhnd); print("File 'SavedProperties.txt' created succesfully!"); } UsePropertyTextDraw(0); SetMaxPropertiesPerPlayer(2); SetPayoutFrequency(120); AddProperty("Cj's House", 2495.25, -1686.60, 13.51, 40000, 12500, 750); AddProperty("Sweets House", 2521.52, -1678.98, 15.44, 33000, 9500, 450); AddProperty("Grovestreet 1", 2469.64, -1648.20, 13.47, 26000, 8000, 525); AddProperty("Grovestreet 2", 2489.25, -1646.48, 14.06, 30000, 8750, 600); AddProperty("Grovestreet 3", 2498.56, -1644.10, 13.77, 19000, 4500, 400); AddProperty("Grovestreet 4", 2522.61, -1658.78, 15.49, 20000, 5000, 400); return 1; } public OnFilterScriptExit() { DestroyAllPropertyPickups(); for(new i; i<TotalPickups; i++) { DestroyPickup(TmpPickup[i]); } return 1; } public OnPlayerDisconnect(playerid, reason) { ResetPlayerPropertyInfo(playerid); return 1; } public OnPlayerCommandText(playerid, cmdtext[]) { new cmd[256], tmp[256]; new idx; cmd = strtok(cmdtext, idx); //=========================================================== if (strcmp("/addproperty", cmdtext, true, 10) == 0) { if(!IsPlayerAdmin(playerid)) return 0; new name[64], price, sell, earning; new Float:X, Float:Y, Float:Z; GetPlayerPos(playerid, X, Y, Z); format(name, 64, "%s", strtok(cmdtext,idx)); tmp = strtok(cmdtext,idx); if(!strlen(tmp)) { SendClientMessage(playerid, 0xFFFFFFAA, "Use: /addproperty [name] [price] [sellvalue] [earning]"); return 1; } price = strval(tmp); tmp = strtok(cmdtext,idx); if(!strlen(tmp)) { SendClientMessage(playerid, 0xFFFFFFAA, "Use: /addproperty [name] [price] [sellvalue] [earning]"); return 1; } sell = strval(tmp); tmp = strtok(cmdtext,idx); if(!strlen(tmp)) { SendClientMessage(playerid, 0xFFFFFFAA, "Use: /addproperty [name] [price] [sellvalue] [earning]"); return 1; } earning = strval(tmp); new entry[128], entry2[128]; new File:hFile; format(entry, 128, "AddProperty(\"%s\", %.2f, %.2f, %.2f, %d, %d, %d);", name, X, Y, Z, price, sell, earning); format(entry2, 128, "\r\n%s",entry); hFile = fopen("SavedProperties.txt", io_append); fwrite(hFile, entry2); fclose(hFile); #if defined CREATE_PICKUPS TmpPickup[TotalPickups] = CreatePickup(1272, 1, X, Y, Z); #endif TotalPickups++; format(entry, sizeof(entry), "Saved Property \"%s\" in SavedProperties.txt!", name); SendClientMessage(playerid,0x00FF00AA, entry); return 1; } //=========================================================== //=========================================================== if (strcmp("/propertyinfo", cmd, true) == 0) { new tmp[256]; tmp = strtok(cmdtext, idx); if(!strlen(tmp)) { SendClientMessage(playerid, 0xFF0000AA, "USE: /propertyinfo [PropertyID]"); return 1; } new prop = strval(tmp); if(!DoesPropertyExists(prop)) return SendClientMessage(playerid, 0xFF0000AA, "This property does not exists!"); new Float:X, Float:Y, Float:Z; new Price, Earning, SellValue, Name[64], Owner[MAX_PLAYER_NAME], Status[16]; GetPropertyInfo(prop, X, Y, Z, Price, SellValue, Earning); format(Name, 64, "%s", GetPropertyName(prop)); format(Owner, MAX_PLAYER_NAME, "%s", GetPropertyOwner(prop)); format(Status, 16, "%s", GetPropertyStatus(prop)); new str[128]; format(str, 128, "Name: %s ** X: %.1f Y:%.1f ** Z:%.1f", Name, X, Y, Z); SendClientMessage(playerid, 0xFFFFFFAA, str); format(str, 128, "Price: $%d ** SellValue: $%d ** Earnings: $%d", Price, SellValue, Earning); SendClientMessage(playerid, 0xFFFFFFAA, str); format(str, 128, "Owner: %s", Owner); SendClientMessage(playerid, 0xFFFFFFAA, str); format(str, 128, "Status: %s", Status); SendClientMessage(playerid, 0xFFFFFFAA, str); return 1; } //=========================================================== if (strcmp("/disableproperty", cmd, true) == 0) { if(!IsPlayerAdmin(playerid)) return 0; new tmp[256]; tmp = strtok(cmdtext, idx); new prop = strval(tmp); if(!DoesPropertyExists(prop)) return SendClientMessage(playerid, 0xFF0000AA, "This property does not exists!"); ToggleProperty(prop, 0); return 1; } if (strcmp("/enableproperty", cmd, true) == 0) { if(!IsPlayerAdmin(playerid)) return 0; new tmp[256]; tmp = strtok(cmdtext, idx); new prop = strval(tmp); if(!DoesPropertyExists(prop)) return SendClientMessage(playerid, 0xFF0000AA, "This property does not exists!"); ToggleProperty(prop, 1); return 1; } //=========================================================== if (strcmp("/myproperties", cmdtext,true) == 0) { GetPlayerProperties(playerid); return 1; } //=========================================================== if (strcmp("/buyproperty", cmdtext, true) == 0) { BuyPropertyForPlayer(playerid); return 1; } //=========================================================== if (strcmp("/sellproperty", cmdtext, true) == 0) { SellPropertyForPlayer(playerid); return 1; } //=========================================================== if (strcmp("/locateproperty", cmd, true) == 0) { new tmp[256]; tmp = strtok(cmdtext, idx); if(!strlen(tmp)) { SendClientMessage(playerid, 0xFF0000AA, "USAGE: /locateproperty [PropertyID]"); return 1; } new prop = strval(tmp); if(!DoesPropertyExists(prop)) return SendClientMessage(playerid, 0xFF0000AA, "This property does not exists!"); LocatePropertyForPlayer(prop, playerid); return 1; } //=========================================================== if (strcmp("/SetPropertyPrice", cmd, true) == 0) { if(!IsPlayerAdmin(playerid)) return 0; new tmp[256]; tmp = strtok(cmdtext, idx); if(!strlen(tmp)) { SendClientMessage(playerid, 0xFF0000AA, "USAGE: /SetPropertyPrice [PropertyID] [Price]"); return 1; } new prop = strval(tmp); tmp = strtok(cmdtext, idx); if(!strlen(tmp)) { SendClientMessage(playerid, 0xFF0000AA, "USAGE: /SetPropertyPrice [PropertyID] [Price]"); return 1; } if(!DoesPropertyExists(prop)) return SendClientMessage(playerid, 0xFF0000AA, "This property does not exists!"); new str[128]; new price = strval(tmp); SetPropertyPrice(prop, price); format(str, 128, "You've set the price of \"%s\" (ID: %d) to $%d", PropInfo[prop][PropName], prop, price); SendClientMessage(playerid, 0x00FF00AA, str); return 1; } //=========================================================== if (strcmp("/SetPropertyValue", cmd, true) == 0) { if(!IsPlayerAdmin(playerid)) return 0; new tmp[256]; tmp = strtok(cmdtext, idx); if(!strlen(tmp)) { SendClientMessage(playerid, 0xFF0000AA, "USAGE: /SetPropertyValue [PropertyID] [Value]"); return 1; } new prop = strval(tmp); tmp = strtok(cmdtext, idx); if(!strlen(tmp)) { SendClientMessage(playerid, 0xFF0000AA, "USAGE: /SetPropertyValue [PropertyID] [Value]"); return 1; } if(!DoesPropertyExists(prop)) return SendClientMessage(playerid, 0xFF0000AA, "This property does not exists!"); new str[128]; new value = strval(tmp); SetPropertySellValue(prop, value); format(str, 128, "You've set the value of \"%s\" (ID: %d) to $%d", PropInfo[prop][PropName], prop, value); SendClientMessage(playerid, 0x00FF00AA, str); return 1; } //=========================================================== if (strcmp("/SetPropertyEarning", cmd, true) == 0) { if(!IsPlayerAdmin(playerid)) return 0; new tmp[256]; tmp = strtok(cmdtext, idx); if(!strlen(tmp)) { SendClientMessage(playerid, 0xFF0000AA, "USAGE: /SetPropertyEarning [PropertyID] [Earning]"); return 1; } new prop = strval(tmp); tmp = strtok(cmdtext, idx); if(!strlen(tmp)) { SendClientMessage(playerid, 0xFF0000AA, "USAGE: /SetPropertyEarning [PropertyID] [Earning]"); return 1; } if(!DoesPropertyExists(prop)) return SendClientMessage(playerid, 0xFF0000AA, "This property does not exists!"); new str[128]; new earning = strval(tmp); SetPropertyEarning(prop, earning); format(str, 128, "You've set the earning of \"%s\" (ID: %d) to $%d", PropInfo[prop][PropName], prop, earning); SendClientMessage(playerid, 0x00FF00AA, str); return 1; } //=========================================================== if (strcmp("/disablecp", cmdtext, true) == 0) { DisablePlayerCheckpoint(playerid); return 1; } //========================================================== if (strcmp("/GetPropertyID", cmdtext, true) == 0) { new ID = IsPlayerNearProperty(playerid); if(ID == -1) return SendClientMessage(playerid, 0xFF0000AA, "You are too far away from a property!"); new str[128]; format(str, 128, "You are now near property ID '%d': \"%s\"", ID, PropInfo[ID][PropName]); SendClientMessage(playerid, 0x00FFFFAA, str); return 1; } //=========================================================== if (strcmp("/SaveProperty", cmd, true) == 0) { if(!IsPlayerAdmin(playerid)) return 0; new prop = IsPlayerNearProperty(playerid); if(prop == -1) return SendClientMessage(playerid, 0xFF0000AA, "You are not close enough to a property"); if(!DoesPropertyExists(prop)) return SendClientMessage(playerid, 0xFF0000AA, "This property does not exists!"); SaveProperty(prop, cmdtext[13]); SendClientMessage(playerid, 0x00FF00AA, "Property Saved!"); return 1; } //=========================================================== if (strcmp("/propertyhelp", cmdtext, true) == 0) { SendClientMessage(playerid, 0x0FFFFFFAA, "Property Commands:"); SendClientMessage(playerid, 0x0FFFFFFAA, "/buyproperty, /sellproperty, /myproperties, /getpropertyID"); SendClientMessage(playerid, 0x0FFFFFFAA, "/locateproperty [ID], /disableCP, /propertyinfo [ID]"); if(IsPlayerAdmin(playerid)) { SendClientMessage(playerid, 0x0FFFFFFAA, "/SetPropertyPrice [ID] [Price]"); SendClientMessage(playerid, 0x0FFFFFFAA, "/SetPropertyValue [ID] [Value]"); SendClientMessage(playerid, 0x0FFFFFFAA, "/SetPropertyEarnin [ID] [Earning]"); SendClientMessage(playerid, 0x0FFFFFFAA, "/disableproperty [ID], /enableproperty [ID]"); SendClientMessage(playerid, 0x0FFFFFFAA, "/saveproperty [comment (optional)]"); } return 1; } return 0; } public OnPlayerPickUpPickup(playerid, pickupid) { OnPropertyPickupPickup(playerid, pickupid); return 1; } strtok(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; }