[Tutorial] How to make moving Objects
#1

Hello everyone, since alot of people helped me out with the moving objects I want to make a little tutorial...
I know there are already alot of tutorials for it, but who carezzz?

For this tutorial I will use a little cage...

First of all we are going to make the map in MTA:
As you can see we have the cage WHITOUT THE DOOR ! !

Save this map and put it in your server,
If you don't know how to put maps in your server, watch this: [ame]http://www.youtube.com/watch?v=7N4qd3HGi_U[/ame]

OK, the next thing you are going to do is making the door, to do that , simply make add the door in its Closed State ! on your cage, and remove everything but the door:

Ok, now save the map with the closed door too, (for example, save it as: cagecloseddoor)
Now comes the scripting:

Open your gamemode and on the beginning of the script you write this: new cagecloseddoor;

Like this:

pawn Code:
new cagecloseddoor;
I'm not going to show you the entire beginning of my gamemode, because it's huge, so...
Make sure you write it under: include,pragma,forward, define and static. Not somewhere in between those things !

Ok now we will need the cagedoor object, to get the object go into your MTA file, then click server -> mods -> deathmatch and finally resources, then find the file: cagecloseddoor, and convert the .map file as shown in the "adding maps" tutorial...
After you converted it you will get something like: CreatObject(...)
Now, you copy the entire "CreateObject(coords)" and you write in pawno, under OnGameModeInit:
"cagecloseddoor = the CreatObject (coords) that you just copied."

Like this:

pawn Code:
public OnGameModeInit()
{

cagecloseddor = CreateObject(blahblah)
Ok, now we are going to make the commands, for that go to OnPlayerCommandText

pawn Code:
if(strcmp("/opengate1", cmdtext, true) == 0)  //We make the command  
       {
        MoveObject(cagecloseddoor, 2897.8764648438, -2059.2080078125, 5.4179458618164, 2.0);        
         //THE moveobject function
        SendClientMessage(playerid, 0xFF8000FF, "The gate is open close it right after you enterd!.");
       }
       return 1;
       }
**The coords you see after : (cagecloseddoor, ) are the coords of the Opengate...
To get those coords you go back In MTA, now instead of the closed door state you simple set it open, now double click on the open state gate, and copy the x,y and z coordinates, and paste them behind:

(cagecloseddoor, x here, y here, z here , Speed)

You also see the 2.0 after the coordinates, this is the speed value, I like speed value 2, but if you want it faster just make it 2.00001 or more, for slower: 1.99999 or less...

Now we made a command to open the door, to close the door you copy everything from the open command, and paste it under the open command. like this:

pawn Code:
if(strcmp("/opengate1", cmdtext, true) == 0)
       {
        MoveObject(gateone, 2897.8764648438, -2059.2080078125, 5.4179458618164, 2.0);
        SendClientMessage(playerid, 0xFF8000FF, "The gate is open close it right after you enterd!.");
       }
       return 1;
       }
       if(strcmp("/opengate1", cmdtext, true) == 0)
       {
        MoveObject(gateone, 2897.8764648438, -2059.2080078125, 5.4179458618164, 2.0);
        SendClientMessage(playerid, 0xFF8000FF, "The gate is open close it right after you enterd!.");
       }
       return 1;
       }
       if(strcmp("/closegate1", cmdtext, true) == 0)
         {
But now you have to change the command from open to close, and change the coordinates, you have to change the coordinates after moveobject blahblah, into the coordinates of the opend gate, to get those coords, you just go back to: ongamemodeinit, and copy the coords. so you would have this:

pawn Code:
if(strcmp("/opengate1", cmdtext, true) == 0)
       {
        MoveObject(gateone, 2897.8764648438, -2059.2080078125, 5.4179458618164, 2.0);
        SendClientMessage(playerid, 0xFF8000FF, "The gate is open close it right after you enterd!.");
       }
       return 1;
       }
       if(strcmp("/closegate1", cmdtext, true) == 0)
         {
               MoveObject(gateone, 2897.9375, -2051.705078125, 5.4179458618164, 4.0);
               SendClientMessage(playerid, 0xFF8000FF, "The gate is closed.");
         }
         return 1;
         }

now , you simply compile, and go ingame and test it

NOTE: If you want the gate to close with a timer check out this tutorial:

http://forum.sa-mp.com/showthread.ph...ht=move+object


I hope it helped, if you have any further questions, feel free to post them here, or send me a PM


BTW: this is my very first scripting tutorial :P
Reply
#2

thanks, i always had problems with it :P

nice!

-J
Reply
#3

Thanks .
With your tutorial i made my first moving gate =D.
Reply
#4

Thanks for the Tutorial Mr.....knackworst.
Reply
#5

you are all welcome : )
Reply
#6

Nice TuTorial
Reply
#7

So, with the 'cagecloseddoor' thing, do i save it as a .map?
Reply
#8

ITS this for SA-MP or MTA
Reply
#9

Quote:
Originally Posted by Mehtab
View Post
ITS this for SA-MP or MTA
Samp obviously. Nice tutorial any way
Reply
#10

Quote:
Originally Posted by Mehtab
View Post
ITS this for SA-MP or MTA
It's scripted for SAMP, but I make the map with MTA map editor...
Reply
#11

Good for new scripters. Nice tut dough.
Reply
#12

Very nice tutorial, It would help for begginers :]

Good one!
Reply
#13

Nice tutorial xD
Reply
#14

Really nice tutorial for Beginners
Congratz
Reply
#15

Nice!!! 10/10
Reply
#16

anytime i try compleing, my pawno will crash...
Reply
#17

hmm, I had the same problem before...

it\'s caused by a fault in the script, show me your script pl0x : )
Reply
#18

Simple + Easy to do.. But nice!
Reply
#19

Nice work.
Reply
#20

Easy to do, but very nice explanations!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)