Author Topic: How to make this script?  (Read 6197 times)

I want to make a script that changes your avatar in periods of time.

ex: 5 seconds later my avatar is a pirate
5 seconds later my avatar is renderman
5 seconds later my avatar is a blockhead
repeat.

Please show me how to do that. I am new to scripting and I want to figure out how to do this. So dont give me the code to do that pirate renderman blockhead thing. It was only an example. I just want to know how to that type of thing, and then type the scripting myself.

Thanks, sorry if this is confusing or doesnt make sense. I just want to be a scripter.


Don't.
is it abusable or something? I sometimes see people with this kind of script.

is it abusable or something? I sometimes see people with this kind of script.
It's just ridiculous and makes you look like a stupid skid when you use it. Just don't.

Your best bet would be to use the avatar favorites system and then switch between them.

The function for switching between avatar favorites is AvatarGui.ClickFav(desired favorite number)
Then, for setting the avatar, you use Avatar_Done().

Unfortunately this would require you to have a renderman, a pirate, and a blockhead taking up 3 slots of your avatar favorites.


As for the logic and formatting, you'll have to figure that out yourself. If you've never programmed before, I suggest you take the codecademy javascript course as an introduction, as Torquescript isn't really the best starter language. It'll better prepare you for making this script. It's hard to tell you how to write the script without doing it myself, so it'd be better to do the course first. If you are interested in me writing the script for you, I can annotate it heavily so you can get an idea of how it functions.

It's just ridiculous and makes you look like a stupid skid when you use it. Just don't.
oh forget off. it's a good starter project. better that he make his own than just download funkyshirt off of some shady mediafire.

I assume you want a clientsided script that does something like this:

-> ->

So, first off what you're gonna want to do is set each one of these as a favorite at the top of the window. This makes this mod immensely easier to make, and it makes it more modular because if you decide later that you want to change one of them, or add one, it's just as easy as overwriting that favorite.

Second, you need to figure out how to apply a favorite. To do this, you're going to use the trace() function. The trace() function prints out every single function that's called into your console. So you want to be quick when you do this, otherwise your console might get spammed by other stuff going on and you'll lose it. So what you're gonna do is have your Player Appearance window open, then open console. Type trace(1); into console. Quickly close console, press one of the non-greyed out favorites buttons, then open console again. When you open console, type in trace(0);.

You should find something in there that looks like AvatarGui::C******v(AvatarGui, x). I starred out the name so that you can do it yourself, and x is going to be whatever number you clicked on. The next thing you need to do is figure out is the function that applies this appearance to your player in game when you click the Done button. So you're going to run a trace again, the exact same way, with trace(1); and trace(0); but you're going to click Done this time instead of one of the favorites buttons.

This function looks a little different, it looks something like A*****_***e().

I recommend using a Global Variable to store the favorite number for the current look you're using. So define a start point at the top of your script, something like $CurrentFavorite = 1; that comes before you have any functions.

Then make a function that calls AvatarGui.C******v($CurrentFavorite);. You can also call this function like it looks in the trace with AvatarGui:: before the function name and AvatarGui as the first parameter, but it's shorter this way.

Then call A*****_***e(); to apply this look to your player.

Next step, you need to increase the value of $CurrentFavorite. You can do this a couple of ways, $CurrentFavorite = $CurrentFavorite + 1; or $CurrentFavorite += 1; are the two easiest to understand. There's a shorthand for increasing a variable built into most languages (Torque included) that allows you to just do $CurrentFavorite++;. There's one more thing you have to do with this variable though, you want to reset it once it's bigger than 3 so that it goes back to 1.
Code: [Select]
if($CurrentFavorite > 3)
{
    $CurrentFavorite = 1;
}

Now you've only got one step left. You need to make it so that this function will automatically be called again in five seconds. To do this we have a special function called schedule() that calls a function after a delay. Convenient! This function returns a number associated with the schedule created, so we want to store this in a different global variable so that we can use the cancel() function on it if you ever want to stop being a renderpiratehead.

So, the way you use schedule is with a couple of arguments: delay and function to call. There's a third argument that comes second, but wonderfully enough it doesn't even work so we just set it to zero. So, for you, this call will look something like $RenderPirateHeadSchedule = schedule(5 * 1000, 0, MyFunctionName);. The delay time is in milliseconds (one thousandth of a second) so we multiply five seconds by a thousand milliseconds to get 5000 milliseconds. In your function, you're probably just going to want to write 5000 instead of 5 * 1000, but I wanted to show you why it's 5000.

So that's pretty much it. You might want to make a second function that calls cancel($RenderPirateHeadSchedule); so that you don't have to remember the name of that variable, but that's totally optional. To start morphing your avatar, just call the function you made for that and watch it go.

Note to other coders: recursive programming ftw? Hopefully it's not confusing to him.


man forget you I went through the effort of censoring out the function names so he had to do it himself and you just spoon fed him. I know you came first, but I started writing that post before you even saw the topic :(

Double post intentional. Absolutely irrelevant to my above post, don't want the two combined.

Don't.
That's a little dismissive. I saw you post about someone else being dismissive too.

man forget you I went through the effort of censoring out the function names so he had to do it himself and you just spoon fed him. I know you came first, but I started writing that post before you even saw the topic :(

Double post intentional. Absolutely irrelevant to my above post, don't want the two combined.
Well if he's actually interested in becoming self sufficient he'll know to follow your advice on tracing. I was considering making a big write-up but considering that he doesn't know any Torquescript I figured it'd be better to learn a more general programming language, from which he could jump to writing Torquescript. If you want I can edit my post to censor the functions, but he may have seen them already.

-snip-
Thank you! This is just what I wanted! I will tell you guys if I run into a problem or something. I am working on the code right now :D! Also, I will take some tutorial on java on code academy just get used to coding and be more familiar with the functions and stuff. Thank you for your effort, And its alright if I got some of the function names. I wanted to learn by myself but if you guys accidentally put the functions its totally alright. Its only a few functions so it wont be bad. Thank you all for helping.


(Pictures are the avatar that I want to change in 5 seconds each)
Code: [Select]
$Hero = 1;
AvatarGui.Clickfav(1);
Avatar_done();
$Hero = $Hero + 1;
if($Hero > 3)
{
    $Hero = 1;
}
$Renderman = 1;
AvatarGui.Clickfav(2);
Avatar_done();
$Renderman = $Renderman + 1;
if($Renderman > 3)
{
$Renderman = 1;
}
$creepbear = 1;
AvatarGui.Clickfav(3);
Avatar_done();
$creepbear = $creepbear = 1;
if($creepbear > 3)
{
$creepbear = 1;
}
$HeroRendermancreepbearSchedule = schedule(5000, 0, MyFunctonName);
I am confused on the "MyFunctionName" part and I think I might have done something wrong... Help please?

Code: [Select]
$Hero = 1;
AvatarGui.Clickfav(1);
Avatar_done();
$Hero = $Hero + 1;
if($Hero > 3)
{
    $Hero = 1;
}
$Renderman = 1;
AvatarGui.Clickfav(2);
Avatar_done();
$Renderman = $Renderman + 1;
if($Renderman > 3)
{
$Renderman = 1;
}
$creepbear = 1;
AvatarGui.Clickfav(3);
Avatar_done();
$creepbear = $creepbear = 1;
if($creepbear > 3)
{
$creepbear = 1;
}
$HeroRendermancreepbearSchedule = schedule(5000, 0, MyFunctonName);
I am confused on the "MyFunctionName" part and I think I might have done something wrong... Help please?

Well this isn't going to work, you're using three different variables, that all get plus 1. You only want one variable, and instead of AvatarGui.ClickFav(#); you should throw the variable in there. And don't set them to 1 right off the bat, kinda gets rid of the +1 purpose and the if > 3 too.

As for the MyFunctionName part if I were to make a function like this:
Code: [Select]
function blah(%client)
{
    do this();
    do something else();
}
Then my function name would be blah, so you also need to put your script in a function.

Here's a basic logic:

function avatarCycle
   increment variable
   set variable to zero if > 3
   set avatar favorite to variable
   schedule next function call
end


Just replace each line with the proper way to do what that line does

Well this isn't going to work, you're using three different variables, that all get plus 1. You only want one variable, and instead of AvatarGui.ClickFav(#); you should throw the variable in there. And don't set them to 1 right off the bat, kinda gets rid of the +1 purpose and the if > 3 too.

This is more confusing than I thought... So if I have 3 variables the script doesn't work... But how can I have 1 variable but still do the thing I want? Since the 1 gets rid of the +1 purpose and the if > 3 too then what should I replace it with?
Here's a basic logic:

function avatarCycle
   increment variable
   set variable to zero if > 3
   set avatar favorite to variable
   schedule next function call
end


Just replace each line with the proper way to do what that line does
Ah thanks, this covers the problem with me being confused with the function part.
« Last Edit: July 16, 2014, 07:10:43 PM by Naked Human »

You only need one variable, because you can use that variable as the argument of the click fav function

//First favorite
$var = 1;
AvatarGui.ClickFav($var);

//Second favorite
$var++;
AvatarGui.ClickFav($var);

//Third favorite
$var++;
AvatarGui.ClickFav($var);


Just follow my previous post, all the logic is there for you, you just need to replace each line with actual code