Would these work?

I've been writing scripts I can't run and although they would compile fine if I was a high enough level, I'd just like to know if they would actually work? This is my first attempt at programming anything so advice would be helpful.

Simple Watch Script :

int main(){

string attacker = getTargetIP();
string port = getPort();
string targetport = getTargetPort();
string load = getCPULoad();
int maxload = 100;
int i = 0;

if (load < maxload) {
logMessage("False Alarm. Load dropped back down below 100% after script fired.");
}else if (load > maxload) {
attacked();
}
void attacked(string attacker, string port) {
sendEmail("You have been attacked by IP: " + attacker + " on port: " + port + " and your CPU load went above 100%");
logMessage("You have been attacked by IP: " + attacker + " on port: " + port + " and your CPU load went above 100%");
}
}

Simple Malicious Bank Script :

int main(){

string attacked = getSourceIP();
string attacker = getMaliciousIP();
float pettycash = checkPettyCashTarget();
int cashamount = 100;
int largeramount = 1000;

if (pettycash > cashamount) {
lowerTransfer(attacker, pettycash);
message(attacker, "Transferred " + pettycash + " to you, target had atleast $100");
}else if (pettycash >= largeramount){
lowerTransfer(attacker, pettycash);
message(attacker, "Transferred " + pettycash + " to you, target had atleast $1000");
}else{
message(attacker, "Didn't transfer any money, target had less than $100 in petty cash");
}

}

Any advice or input at all would be welcomed. I can't test them myself and I've never programmed before so I have no idea how they look or would run.

code review

Your watchscript doesn't make sense to me.
When your CPU balance is higher than 100% then you are OHed (overheated) and no watch will fire then. And keep in mind that a health watch only fires when the health of that observed portfell below the set value.
A damaged attack port only results in a worse CPU balance if this damaged port is (counter-) attacking. An active but not attacking attack port will not change your CPU balance - it will just loose health and eventually will fire installed health watch(es).

Your malicious bank script is much better, but use getAmount() instead of checkPettyCashTarget().
If you want to know the Petty Cash of your victim: checkPettyCash().
If you want to know the Petty Cash of the target of the transfer: not possible!
checkPettyCashTarget returns the result of a variable named PettyCashTarget - it does NOT return the Petty Cash of any target.

http://www.hackwars.net/wiki/index.php/Functions#Banking_Functions

Code review

Ok, a few things.

Watch Script
1)
string port = getPort();
string targetport = getTargetPort();
string load = getCPULoad();

port and target port functions return ints and cpu load returns a float ... you should have instead:
int port = getPort();
int targetport = getTargetPort();
float load = getCPULoad();

2) the general concept for this script will not work, because only scan watches work if your load is above 100%. Instead, I suggest having a watch that fires when your health drops below 100, for which you dont need the getCPULoad function, and can instead set the fire value at runtime.

3) Last for this script, you declare the attacked() function as taking two parameters, but when you actually call it in main(), you do not give it any arguments, so it would not work.

Mal Banking Script
1) There are no actual syntax errors in this script at first glance, but it is unnecessary to have the two statements for when cash is transferred to you. Instead, you should always send the money to yourself if the amount is greater than 100. (and only use one if, one else) Also, checkPettyCashTarget() is the wrong function to use (as silverlight mentioned), use checkPettyCash() instead.

2) There is a logical error in the way you determine when to send the money to you. you are looking at their petty cash, but instead you should be looking at the amount of money involved in the transaction. An example of this would be: player X has $100,000 in their petty cash. They decide to deposit $1. Because you script checks the petty cash, it would send that $1 to you. Therefore, check amount (obtained by getAmount() ) and use that value to determine whether the money goes to you.

3) I assume this would be in the "deposit" part of a bank script ... and therefore you should use lowerDeposit("yourIP",amount); not the transfer function.

4) you forgot to deposit the money into the victim's bank when the money is not sent to you -- they would notice and replace the script.

Last thing I would say is to use custom functions, they save a lot of CPU. Ask one of the active players to help you with this. (I am taking a break from playing Hackwars).

Overall, you did a good job for someone who has never programmed before. Keep scripting and you will get better, and never be afraid to ask for help. Hope this post helped.

-TTJ

(Im in ur compilerz lolin' ur codez !)

wrong parameters

3) Last for this [watch] script, you declare the attacked() function as taking two parameters, but when you actually call it in main(), you do not give it any arguments, so it would not work.

Using the wrong number or types of parameters is a very annoying mistake. Its effects range from strange/unhelpful compiler error messages to runtime errors which result in strange bugs (due to empty parameters) or sudden halts of the script with a message about an "exception in the script".
Easy to make hard to fnd mistake. :\

Hint: Press CTRL+F or CTRL+H in the script editor to have a function to highlight/search/replace some text (for example a function name).