if(strcmp(cmdtext, "/command", true) == 0) { new string3[286]; format(string3,sizeof(string3),"ASAKDJIAJIFUF:"); ShowPlayerDialog(playerid,7676,DIALOG_STYLE_INPUT,"title",string3,"SENT","CALL"); return 1; }
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) { // Textfile // Example // Money=value // like (money=200000) if(dialogid == 7676) { if(response) { print("Debug."); new BankInfo[286]; new message[286]; new amount[286]; amount = dini_Get("company_account/money.ini", "money"); // Gets "money" value and fill it to amount GivePlayerMoney(playerid, inputtext); BankInfo = amount-inputtext; // Operation its like this (Current bank amount, wich come from "amount" MINUS "inputtext" amount = X; answer should be now filled to BankInfo now) format(message, sizeof(message), "You did: %sЂ", inputtext); SendClientMessage(playerid, COLOR_WHITE, message); dini_Set("company_account/money.ini", "money", BankInfo); // Open dini "money" and saves "money" value wich come from BankInfo } return 1; } return 0; }
new BankInfo[286]; new message[286]; new amount[286]; new carcost = 265; new vid = GetPlayerVehicleID(playerid); // DINI GET amount = dini_Get("company_account/money.ini", "money"); // DINI GET end // COUNT bank minus carfixcost is X BankInfo[285] = BankInfo[285]-carcost; // COUNT bank minus carfixcost is X end format(message, sizeof(message), "Your car repair cost %iЂ", carcost); // MINUS MONEY FROM PLAYER GivePlayerMoney(playerid, -carcost); // MINUS MONEY FROM PLAYER end SendClientMessage(playerid, COLOR_WHITE, message); // DINI WRITE VALYE TO MONEY dini_Set("company_account/money.ini", "money", BankInfo); // DINI WRITE VALYE TO MONEY end // REPAIR VEHICLE if (vid) RepairVehicle(vid); // REPAIR VEHICLE end
Originally Posted by woaha
Bump, still need help with this
|
new BankInfo[286]; // not needed
new message[286]; // 286 is overkill, the message is only like 25 characters, that's 261 wasted but all is not needed as I explain below
new amount[286]; // why a string, this is a huge waste of memory ?
new carcost = 265; //why create the var if you know the cost ?
new vid = GetPlayerVehicleID(playerid); // this is fine, you use it twice and variables are fast
amount = dini_Get("company_account/money.ini", "money"); //isn't there GetINT or something, or use "strval( dini_Get..."
BankInfo[285] = BankInfo[285]-carcost; //this isn't needed, do the math when you write it
format(message, sizeof(message), "Your car repair cost %iЂ", carcost); //could just be 265 instead of "carcost", no need to format the string really
GivePlayerMoney(playerid, -carcost); //again just minus 265 from thier current cash
SendClientMessage(playerid, COLOR_WHITE, message); //this could contain just "Your car repair cost 265" as we know the price already
dini_Set("company_account/money.ini", "money", BankInfo); //you could use IntSet or something (I don't know dini) so no need for the string (amount) like I noted above
if (vid) RepairVehicle(vid); //all good, you saved on one function call
new
amount, // integer
vid = GetPlayerVehicleID(playerid);
amount = dini_Int("company_account/money.ini", "money"); // grab it as an integer, no need to mess about with strings
GivePlayerMoney(playerid, (GetPlayerMoney(playerid) -265)); // take away the cost from the players current cash, no need for variables etc
SendClientMessage(playerid, COLOR_WHITE, "Your car repair cost 265"); // send the raw message, no need to format as we know the cost.
dini_IntSet("company_account/money.ini", "money", (amount - 265)); // write the amount minus the cost back into the file
if (vid) RepairVehicle(vid);
strval( inputtext );