View Full Version : !send command [Help Needed]
sun
20th March 2008, 19:30
Hello,
I've com accross somthing what i was really supposed of figured out.
Its the !send command. i know how to do others, but not this, i know that it goes out of your account like the !buy, but Transffering into other peoples accounts.
If any one can help please post in here, or Explain what i'am supposed to know or do.
Thanks,
Regards
Owen.
-----------------------------
Owner of:
Owens Cruise Server
-----------------------------
eight8acht
20th March 2008, 19:34
Hello,
I've com accross somthing what i was really supposed of figured out.
Its the !send command. i know how to do others, but not this, i know that it goes out of your account like the !buy, but Transffering into other peoples accounts.
If any one can help please post in here, or Explain what i'am supposed to know or do.
Thanks,
Regards
Owen.
-----------------------------
Owner of:
Owens Cruise Server
-----------------------------
You need to learn how to code... that's all :P
mcgas001
20th March 2008, 19:46
You need to learn how to code... that's all :P
Exactly, but for some insane reason. He wont. :shrug:
vane
20th March 2008, 19:56
I have had great fun learning to code, i may be wrong but am i the only "crazed guy who wants to make a cruise server" who has bothered to try and learn? except of course for bose :)
sun
20th March 2008, 20:07
OMG I 'am bothered to learn how to code... omg i cant say because i can code, i can make windows games (little) i can make applications, but when it comes to !send command its all of topic, So STOP THAT STUFF! FOR THE LAST TIME !
Rooble
20th March 2008, 21:33
OMG I 'am bothered to learn how to code... omg i cant say because i can code, i can make windows games (little) i can make applications, but when it comes to !send command its all of topic, So STOP THAT STUFF! FOR THE LAST TIME !
What's so difficult to understand?
Check to see if the user has the available 'funds' - If he has then add them to the user he is sending them to and deduct it from his 'funds' what else is there?
P.S : From what I've seen of all your previous threads, my guess is you know little to nothing about developing code, but I'm sure you're well aware of that.
dougie-lampkin
20th March 2008, 23:26
I'm sure you're well aware of that.
If only...
My advice (which will either be ignored, or have to be explained), is to use a foreach loop that looks for the specified Username (from the !send command) and then adds the specified cash (also from the !send command) to their cash, at the same time, subtracting the specified cash from the person who typed the command...
Without explaining each tiny process there, that's as simple as it can be said. If you can't even make a reasonable attempt at that, there is no hope. I'm not knocking you, that's just fact. (Besides the fact that Google (www.google.ie) has much better answers than the LFS forum...)
sun
21st March 2008, 08:24
yer, thanks dougie i'll give it a go :D
sun
23rd March 2008, 19:52
!send command:
Can somebody give me an Example of a Send command ?
like ppl are saying its diffrent to a !pay or !buy or !sell, buts its confusing me, please i need help i'am stuggling on this.:(
dougie-lampkin
23rd March 2008, 20:09
Can somebody give me an Example of a Send command ?
Does anyone have a list of what Sun has been given, against what's in his InSim? I would be very interested in seeing that :really:
Jakg
23rd March 2008, 20:11
I have VERY little programming experience (BASIC ftw), and i've refrained from posting in these topics earlier to make sure I didn't look like an idiot but...
Can't you just query if the feild "cash" (or "$cash" or however you do it) for user "x" and if the value minus the value they send is greater then zero then remove £x from user "x" and add £x to the user they are sending it to.
JamesF1
23rd March 2008, 20:33
From here on in i'm using Pseudo-Code btw...
Can't you just query if the feild "cash" (or "$cash" or however you do it) for user "x" and if the value minus the value they send is greater then zero then remove £x from user "x" and add £x to the user they are sending it to.
That's not pseudocode :razz:
Jakg
23rd March 2008, 20:33
How did I know I was gonna get pulled up on that...
I planned on writing it like that, but after not knowing if it would be "cash" or "$cash" i gave up.
NINJA EDIT!
JamesF1
23rd March 2008, 20:43
Try something more like:
if (payment <= user[x].cash) {
remove value of payment from user[x].cash
add value of payment to user[y].cash
} else {
LAWL, NO MONIES. LAWL.
}
sun
24th March 2008, 09:21
ok.......
amp88
24th March 2008, 10:34
How far have you got so far?
What I'd suggest doing (without knowing how you're trying to do things at the moment) is firstly find out if the player who wants to send the money has enough to send. If they don't have enough to send then do nothing or print a message informing them they don't have enough. If they do have enough, find out the id of the player they want to send it to. Add to their money then remove from the player who sent it. Something you might want to think about is what would happen if there was an error in the middle of the transaction. If only one part of the transaction happens (i.e. if only the person who wants to send the money loses money or if only the person who is being sent money gets it) then you're in a bad state. You might want to put in some error handling that will compensate for that.
Something else you might want to think about is how you validate the send command. I noticed in another of your threads someone said your InSim crashed when a player tried to pay "2.2" credits. This would suggest to me (although I can't say for certain without seeing your code (no, I don't want to see your code ;) )) that your code doesn't do proper validation of input. You might want to, for example, ensure the input is only a positive whole number. If you detect a negative amount of a number with decimal places then print a message and don't carry out the transaction. You could do that by, for example, checking for the presence of a full stop in the amount of money.
dougie-lampkin
24th March 2008, 13:45
What I'd use is a try-catch, and cast to a UInt :nod:
amp88
24th March 2008, 13:56
What I'd use is a try-catch, and cast to a UInt :nod:
Yeah, if I were writing it (in Java), I'd have a try/catch around it too.
try {
amount = Integer.parseInt(input);
} catch (NumberFormatException nfe) {
// input couldn't be parsed to an int (contained punctuation, non-numeric characters etc...)
amount = -1;
}
Then you could check if the return from that method was -1 and if it was you could print a message about invalid input. In this case it's safe to use -1 to signal an error because -1 isn't a valid input anyway, but if -1 was considered a valid input you could use an Integer object rather than the primitive int (checking for a non-null Integer in that case...).
Of course, that's specific to what language you're using and how it fits in with the rest of your programming style.
DarkTimes
24th March 2008, 18:11
If you want to parse an int from a string in C#, it's better to use Int32.TryParse.
string input = "2";
int amount = 0;
if (Int32.TryParse(input, out amount))
// Amount was successfully parsed
else
// Amount couldn't be parsed.
dougie-lampkin
24th March 2008, 18:47
What's the difference (if any) between Convert.ToInt32 and Int32.Parse?
I always use Convert, but that's just me :shrug:
mcgas001
24th March 2008, 18:48
What's the difference (if any) between Convert.ToInt32 and Int32.Parse?
I always use Convert, but that's just me :shrug:
http://blog.happyarts.net/2005/08/29/3
dougie-lampkin
24th March 2008, 18:51
Ah, that explains it :nod: Thanks :)
Something I just thought of, which one is .ToString()?
DarkTimes
24th March 2008, 19:27
Any performance benefit from using Convert vs Parse is academic, but using TryParse is better in my opinion, as it's neater and allows you to avoid exception handling. People overuse exception handling in C#, if you can avoid using try catch then you should. It's like if you are opening a file...
try
{
StreamReader sr = new StreamReader(path);
}
catch (FileNotFoundException)
{
Console.WriteLine("The file was not found.");
}
It's better to do this...
if(File.Exists(path))
StreamReader sr = new StreamReader(path);
else
Console.WriteLine("The file was not found.");
I guess that's a silly example, as you probably wouldn't open a file like that, but you get the idea.
I'm not sure what you mean about ToString(), but you can read up about it in the language reference. http://msdn2.microsoft.com/en-us/library/system.object.tostring.aspx
dougie-lampkin
24th March 2008, 19:32
I meant is it faster to Convert.ToString, String.Parse or .ToString()...
From what I've read now, it seems .ToString() is fastest :tilt:
mcgas001
24th March 2008, 19:39
Theres no such thing as string.Parse() you just use ToString().
dougie-lampkin
24th March 2008, 20:03
Oh lol...I've never used String.Parse, I just assumed there was one :shy:
DarkTimes
24th March 2008, 20:23
ToString() doesn't actually parse string data from objects, what it does is give you a string representation of an object. That's a subtle difference. In fact, ToString() is a lot more powerful really.
Edit: Actually a good way to say it is that ToString() 'manufactures' a string, rather than parses it.
JamesF1
24th March 2008, 22:10
ok.......
And that attitude is exactly why you'll never be good at programming. You can't even understand pseudo-code.
UKMANUK
25th March 2008, 07:35
come on now he is learning give him a chance dont put him down help him thats what he wants not a argument about he cant code not very polite tnot at all at least he is trying
eight8acht
25th March 2008, 09:58
yeah yeah... owen.... you can code very well :D you just take commands all over spread in the forum and just put it together to a insim. If you cold code as you said it wouldn't be a problem for ya.
BTW you have now your own layout? or still using ours....
I won't help ya but probably GOOGLE will help you.
the_angry_angel
25th March 2008, 10:28
Ok gentlemen, this has turned from friendly advice into plain bashing and spam, enough is enough.
If the OP doesn't feel the question has been answered sufficiently please get in touch with a mod to reopen the thread. In my opinion things have been explained rather clearly, however.
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.