Author Topic: Can Someone help me Please?  (Read 1392 times)

 I've been trying to get this old Roulette Bot Working but i have no Idea what to do. I've Looked into Torque scripting and all that stuff and i couldn't seem to find anything Wrong with the Script. Maybe its my lack of Experience or something but i'd appreciate it if someone could help me.

Thanks in Advance :)




//Made by ThinkInvisible, BLID 14511. NOTE : Some things in this code are misplaced so you don't just grab it and use it. This is only an example.

package rouletteBot {
     $rouletteBarrel = getrandomnum(1,6);
     $rouletteScoreCombo = 0;
     $rouletteLastShoot = NaN;
     function clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg) {
          parent::clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg);
          if (striPos(%msg,"Roulette") > 0) {
               if (striPos(%msg,"shoot me") > 0) {
               if ($rouletteLastShoot != %name) {
                    commandToServer('messageSent',%name@" spins the barrel and pulls the trigger...");
                    %tempval = getrandomnum(1,6);
                    if (%tempval = $rouletteBarrel) {
                         $rouletteScore[%name] ++;
                         export("$rouletteScore*","add-ons/client_roulette/scores.cs");
                         $rouletteLastShoot = NaN;
                         $rouletteBarrel = getRandomNum(1,6);
                         commandToServer('messageSent',"*BLAM*... "@%name@" got hit! "@%name@" has been hit "@$rouletteScore[%name]@" times.");
} else {
commandToServer('messageSent',"*Chk*... "@%name@" escaped the bullet! Good job!");
$rouletteLastShoot = %name;
}
} else {
commandToServer('messageSent',"Silly "@%name@", you can't shoot twice in a row! Let somebody else have a turn, please.");
}
}
}
};

There are numerous problems so let's just dig in.
To get a random range of numbers you do getRandom(start number that is included, end number that isn't).
NaN isn't a valid torquescript keyword, just use 0 or ''.
striPos returns -1 if it can't find it in the string, the way you're doing it is if it's at the start of the message, it won't work.
Don't use %string @ " rest of string", if you want a space, do %string SPC "rest of string".

That's all I can find quickly hovering over this and this doesn't even touch base on functionality or abuse protection.

Don't use %string @ " rest of string", if you want a space, do %string SPC "rest of string".
This really doesn't matter, %var @ " String" or %var SPC "String" is the same thing, but to me the former looks better.
In the end, it comes down to the coders preference.

Another thing, variables cannot be assigned inside a package.

Code: (Invalid Code) [Select]
package Package {
    $Variable = "Assignment";
    function Function() {}
};
Instead, you'd need to do
Code: (Valid Code) [Select]
$Variable = "Assignment";
package Package {
    function Function() {}
};
« Last Edit: January 31, 2016, 10:35:36 PM by Pah1023 »

This really doesn't matter, %var @ " String" or %var SPC "String" is the same thing, but to me the former looks better.
Good coding practices must always be the standard.

Good coding practices must always be the standard.

Using @ or SPC is user preference, has nothing to do with good coding practices lmao.

It improves readability. It may not matter as much in things where you would sensibly use a space (in a sentence, for example), but if you're making things where spaces matter and aren't a given, good readability helps.

Good coding practices must always be the standard.
Correct me if I am wrong, Torque is the only thing that uses anything such as SPC.
So good practice would be not getting used to it in the first place.

But as I said before,
In the end, it comes down to the coders preference.

Good coding practices must always be the standard.
why do you think using "SPC" is a better practice...

I understand what he means. Reading @ followed by " word" is harder to see and when it's something that uses a lot of message formatting it can get annoying. It's good practice to use what you need.

In the future it would help if you used a proper topic title. Topics like "help me please" or "cant figure this out" are very ambiguous and are often looked past.

A proper title for this topic would be something like "Roulette Bot Help" or similar. This will help people who know something about this add-on already to reply faster since they know what you need help with and don't accidentally skim past it

Just a small bit of advice since your new here  :cookie: