A simple command in PAWN - pawn

San Andreas Multiplayer (GTA) uses PAWN as its programming language. I'm an owner of a server on SA-MP and I'm not that pro so I'd like to get some help if possible. Basically, I have a command that checks player's statistics when he/she is online, but I'd like to have a command to check them when they're offline. That's the code of the commmand which checks player's statistics when he's online.
CMD:check(playerid, var[])
{
new user;
if(!Logged(playerid)) return NoLogin(playerid);
if(Player[playerid][pAdmin] >= 2 || Player[playerid][pStaffObserver])
{
if(sscanf(var,"us[32]", user, var))
{
SendClientMessage(playerid, COLOR_WHITE, "{00BFFF}Usage:{FFFFFF} /check [playerid] [checks]");
SendClientMessage(playerid, COLOR_GRAD2, "** [CHECKS]: stats");
return 1;
}
if(!strcmp(var, "stats", true))
{
if(!Logged(user)) return NoLoginB(playerid);
ShowStats(playerid, user);
}
}
else
{
NoAuth(playerid);
}
return 1;
}
I use ZCMD command processor and Dini saving system. So I'd like to make CMD:ocheck that would display the stock ShowStats and it'll work like /ocheck [Firstname_Lastname].
Any help? Please help if possible.
Thanks
~Kevin

For the command that you require, you'll have to load data from the player's userfile.
You'll obviously begin with
if(!Logged(playerid)) return NoLogin(playerid);
if(Player[playerid][pAdmin] >= 2 || Player[playerid][pStaffObserver])
{
To check if the player using this is authorized to use this command.
Following this,
if(str, "s[32]", name))
You cannot use 'u' as a formatter here, simply because you're checking an offline player's statistics.
After this, you need to check if the user is actually registered
If he isn't, you return that error the user of this command
If he is, then check if he is online already. If he is online, return error to admin to use this command instead of 'ocheck'
If he's offline, then you can safely proceed to load his statistics (you can use the code used for loading data when a player logs in, except this time it should only be printed
for eg,
format(str, sizeof(str),
"Score: %s, Money: %d",
dini_Int(file, "score"), dini_Int(file, "score") );

Yes, basically, you have to get all the information from the file, so ShowStats will not work, because I suppose it gets all the information from enumerations and such, you have to write a brand new function, of getting all the offline info.

Related

I am trying to use classes in C++

I am working on a project where I think a need to use classes. I want to make a bank system and for that I need to create accounts formed by a password and a name. The problem is when I try to make a new account, the previous account is deleted so I can have just one account at a time.
I researched on internet and I think the solution is to use classes. Can somebody help me with an adivice or a ideea? I will attach the code below.
The function
Main
In the file Input.txt I add initial 1 and then increase in variable cont with every account created. The problem is the file Conturi.txt because there I have only one account, the latest one and I don t know why because a make a write everytime i use the void creare_cont....
First of all please format your code. And attach it into your question.
To write a banking system you can obviously use classes. But that's not the case here.
Your problem is not with classes but with application's logic. It's hard to tell exactly what your code suppose to do, because it is incomplete and I'm not familiar with Romanian, but I'll try to guess.
When you try to write such a project, you must first ask yourself a few questions:
What does the banking system do?
What features should it have?
What kind of data does it store?
How will this data be stored?
I think we all know answer to first question: It keeps customers money. That was easy.
Based on the published code, I'll try to answer the remaining questions.
What features should it have?
I translated your menu into something like this:
Create a new bank account.
Log into an existing account.
Display balance of existing accounts.
What kind of data does it store?
Let's keep it very simple and store only username, password and user's balance. To do so we will create our own structure. We could use classes, but as I said: keep it simple and short.
struct BankAccount
{
std::string username;
std::string password;
int balance;
};
How will this data be stored?
To store some data we usually usesome kind of database. I'll use a simple file just as you did. But first we must decide how to store accounts inside our database? I would suggest again to keep it simple and make few rules:
Username and password can't contain any whitespaces
Password will be stored in plain text
Balance must fit into int
Everything will be separated by a space
I would add one more rule (to make it more readable in case of debugging): Every user will be kept in different line. So our database might look like this:
adam pass 123
eva qwerty 666
henry qaz123 -100
... and so on ...
After answering all our questions, we can start thinking on how our system should work?
How should it work?
I would split our logic into 4 steps:
Load the database.
Ask user what to do.
Do whatever user requested.
Save the database.
Of course this is not the best or fastest way of doing this. But as I said: Keep it simple. We will also assume that database is not corrupted, so we won't have to validate it on loading.
Now let's divide each step into atoms.
1. Load the database.
To do that we need a file with data and some kind of structure to load data into. We will use std::vector because it can extend automatically and we won't have to worry about it. Now, what do we need to do? We know exactly how our file is structured and we can assume that database is not corrupted. So all we need to do is read characters until we will encounter a whitespace. Fortunately we can do it without writing any sophisticated functions. Standard library will do it for us:
#include <vector>
#include <string>
#include <fstream>
std::vector<BankAccount> LoadDatabase(const std::string &dbFile)
{
std::vector<BankAccount> accounts;
std::ifstream file(dbFile);
if (!file)
{
std::cerr << "Cannot open database file!" << std::endl;
return accounts;
}
BankAccount account;
while (file >> account.username >> account.password >> account.balance)
accounts.push_back(account);
return accounts;
}
Because every field in our database is separated by space we can easly read the whole file. I'll leave implementation of SaveDatabase(const std::string &dbFile, const std::vector<BankAccount> &accounts) to you. It should be very similar to our loading function.
2. Ask user what to do.
I won't write this code either. You already did this. What I can do is suggest you to move it into separate function and return the result (requested action). You should keep asking for user's input until it is valid (i.e. it is an integer and corresponds to any element in the menu).
3. Do whatever user requested.
Now we should call apropriate function based on what user choosed in previous step. We will use switch statement for it. I translated (so blame Ggoogle if anything is wrong) your menu to know what kind of features we must implement and I ended with these three:
Create a new bank account.
Log into an existing account.
Display balance of existing accounts.
Creating a new account should be very easy. We already have our database loaded in std::vector and we know that it will be saved back to the file when closing the application. All we have to do is ask for new user data (username and password), build a new object and add it to std::vector. It may look like this:
void CreateAccount(std::vector<BankAccount> &accounts)
{
BankAccount account;
std::cout << "Provide username and password (separated by space):" << std::endl;
std::cin >> account.username >> account.password.
account.balance = 0;
accounts.push_back(account);
}
I have no idea what logging in to an existing account should do (maybe display a new menu?), so I'll leave it to you to write. But displaying balance of all accounts should be easy:
void DisplayAllAccounts(const std::vector<BankAccount> &accounts)
{
std::cout << "All accounts in database:\n";
for (size_t i = 0; i < accounts.size(); ++i)
std::cout << "\t" << accounts[i].username << " has $" << accounts[i].balance << "\n";
}
4. Save the database.
As I said, I'll leave it to you. Shouldn't be that hard to write based on what you have now.
Oh, I would forget. Your main function with switch statement:
int main()
{
const std::string dbFile = "Conturi.txt";
// Load the database
std::vector<BankAccount> accounts = LoadDatabase(dbFile);
// SelectAction shows the menu, gathers user's input and return 1, 2 or 3 depending on action he choosed
switch(SelectAction())
{
case 1:
CreateNewAccount(accounts);
break;
case 2:
LogIntoAccount(accounts);
break;
case 3:
DisplayAllBalances(accounts);
break;
default:
// This should never happend because SelectAction should handle incorrect input
std::cerr << "Incorrect input!" << std::endl;
return 1;
}
// Save the database
SaveDatabase(dbFile, accounts);
return 0;
}
As you can see it wasn't that hard. And code is more readable when it's properly formated.
Now that I've done most of your homework, good luck with the rest!

Alexa, there was an issue processing your input

I'm following a video which explain how to create a skill and intents, to use Alexa. (Here is the link to see this video: https://www.youtube.com/watch?v=YMb0y66UCxs)
I have a problem, I can't go inside an Intent but I can run the skill with the sentence "Alexa open [Name of the skill]". I will show you the index.js from aws and after that the JSON file from developer amazon.
AWS
And here, the JSON:
I built this project in english in the developer amazon website, but i live in france. Maybe I can have a conflict there. And i also choose, in aws, the city east USA (virginia...). So when i say : ask [name of the skill] for [Un unterance], i have this problem:
When I click on the exclamation point, it says: "There was an issue processing your input". Do you see my problem ?
I don't know, and I could be wrong, but do you need to add a GetNewFactHandler? It doesn't look like you defined one anywhere and your trying to add it in .addRequestHandlers.
Based on the other handlers in your code I'm guessing it should look something like this:
const GetNewFactHandler = {
canHandle() {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest' && request.intent.name === 'GetNewFact'
},
handle(handlerInput) {
return handlerInput.responseBuilder
.speak('Hello from the get new fact intent')
.getResponse()
}
}
Oh sorry, I just forgot to put the part where I have this code in my aws.
The forgotten part

Ember.js - What purpose does Ember.lookup serve

Can anyone tell me what purpose Ember.lookup serves?
It is used to lookup string keys.
An example of its use in the ember source is:
if(typeof modelType === "string"){
return Ember.get(Ember.lookup, modelType);
} else {
return modelType;
}
I can see that it returns a type from a string but I don't see where it is set or what the bigger picture is for its usage.
Ember.lookup was introduced along with Ember.imports and Ember.exports as a way to remove the dependency on window.
If you are running Ember in the browser, all three values will refer to the window, however if you are running without the browser, for instance, through NodeJS or with AMD, you will need to supply values yourself.
See the commit message for more information.

Allowed To Read Statuses Even With Permission Denied?

I'm following a tutorial on programming with Flash / Flex and Facebook (see http://www.adobe.com/devnet/facebook/articles/flex_fbgraph_pt1.html). This is a desktop app that connects to Facebook, rather than a web app.
When first testing the ability to read statuses I allowed the app to read them (obviously) when asked, so that worked just fine.
For the hell of it, I then revoked permission and when it asked me again, said Skip. It was still allowed to read them! (result object was valid, fail object was null).
So I then tried again (and it asked me again, since it still did not have permission), and this time I specifically clicked the cross to deny permission... and it was still able to read them!
Have I perhaps missed something? This is the code I'm using:
private function showStatus(): void
{
FacebookDesktop.requestExtendedPermissions(onGetStatusGranted,"read_stream");
}
private function onGetStatusGranted(resultData: Object, failData: Object): void
{
FacebookDesktop.api("/me/statuses", onGotStatus);
}
private function onGotStatus(resultData: Object, failData: Object): void
{
if (failData != null && failData.error.code == 200)
{
// User didn't allow it.
return ; **** Doesn't get here! ****
}
if (failData == null && resultData != null && resultData.length > 0)
this.userStatusLabel.text = "Status: " + resultData[0].message ; **** Always gets here ***
}
You most likely encountered a bug. Statuses require read_stream permission, unless you are a public page.

How to obtain display devices information regardless of session?

I using EnumDisplayDevices that give me obtain information about the display devices in the current session.
But i need information about the display devices regardless of session. Because i create some windows service application (System process).
Does anybody know some alternative for this code:
vncDesktop::GetNrMonitors()
{
if(OSversion()==3 || OSversion()==5) return 1;
int i;
int j=0;
helper::DynamicFn<pEnumDisplayDevices> pd("USER32","EnumDisplayDevicesA"); // it's EnumDisplayDevices function
if (pd.isValid())
{
DISPLAY_DEVICE dd;
ZeroMemory(&dd, sizeof(dd));
dd.cb = sizeof(dd);
for (i=0; (*pd)(NULL, i, &dd, 0); i++)
{
if (dd.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP)
if (!(dd.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER))j++;
}
}
return j;
}
Thanks in advance!
sources below
Well, the reason why this doesn't work is because session 0 isn't connected to a console. What's more, because many more video settings are per user on Windows 7 it would be bad to assume that anything you get from one user even applies to another user.
You could also try to find the display monitors in the registry.
The display monitors should be stored here:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\DISPLAY
The class GUID for display monitors is {4D36E96E-E325-11CE-BFC1-08002BE10318}. you can try to find the monitors in system using the Setup API (SetupDiGetClassDevs, ...)
If you are coding specifically for Win7 and later, you might want to have a look at QueryDisplayConfig and related functions.
Sources
EnumDisplayDevices function not working for me
http://social.msdn.microsoft.com/Forums/en/vcgeneral/thread/4384f8d2-c429-410b-87e4-1e031ddc8167
I found solution for this issue. Only need create process user - System and SessionID - some user. And then all working fine.