[Tutorial] How to Create a Moving object [Simple+well explained]
#1

Starting

Hello!, this is my second tutorial and im gonna show you how to make a "Moving objects"
hope i explain it in a good way , good luck
lets start

now we must use a_samp include ,it defines every function with pawno, on the very top of the script add it:
PHP код:
#include <a_samp> 
now we added it , ill make this tutorial about a filter script so lets define it as a filter script:
PHP код:
#if defined FILTERSCRIPT 
now we gonna get deeper!
we need to call the gate something specific to not mix with another gate ids in the future, our gate will be gate1,
below
PHP код:
#if defined FILTERSCRIPT 
add this:
PHP код:
new gate1;//make sure to end it with ; 
after that we need to add the place where exactly this gate should be, and we need to define it to the script,
for defineing it we need to add it under:
PHP код:
public OnFilterScriptInit() 
or:
PHP код:
public OnGameModeInit() 
but in our case its under public
PHP код:
OnFilterScriptInit() 
because if you focused we defined this as a FilterScript, now when adding the gate it should be like this :
PHP код:
gate1 CreateObject(objectid,x,y,z,rot:x,rot:y,rot:z); 
now explain time,
CreateObject is obvouis to the create the object
x,z,y are a floats to set the place of the object, rot = rotation
now a realy example:
PHP код:
gate1 CreateObject(9801245.5999755859, -767.0999755859493.9000015258790.00.00.0100.0);// like this 
now we have the gate In game but it wont move unless we do the opening/closing Command now below everything
enter this function :
PHP код:
public OnPlayerCommandText(playeridcmdtext[]) 
lets start:
PHP код:
public OnPlayerCommandText(playeridcmdtext[])
{
    if(!
strcmp(cmdtext"/open"true)){
        if(
IsPlayerInRangeOfPoint(playerid15.01245.5999755859, -767.0999755859493.900001525879)){
            
MoveObject(gate11256.5999755859,-767.0999755859493.9000015258793.00.00.00.0);
            
SendClientMessage(playerid0x0000BBAA"the Gate Opened Successfuly , Weclome !");
            return 
1;
        }
    }
    if(!
strcmp(cmdtext"/close"true)){
        if(
IsPlayerInRangeOfPoint(playerid15.01245.5999755859, -767.0999755859493.900001525879)){
            
MoveObject(gate11245.5999755859, -767.0999755859493.9000015258793.00.00.00.0);
            
SendClientMessage(playerid0xAA3333AA"the Gate Closed successfuly !");
            return 
1;
        }
    }
  return 
0;

now explaining time:
PHP код:
if(!strcmp(cmdtext"/open"true)){ 
this is the command to open the gate
PHP код:
if(IsPlayerInRangeOfPoint(playerid15.01245.5999755859, -767.0999755859493.900001525879)){ 
this for checking that if the play is close to the gate , to not move it from anywhere.and the 15.0 is the distance and the other numbers are coords (x,y,z that i explained before)
PHP код:
MoveObject(gate11245.5999755859, -767.0999755859493.9000015258793.00.00.00.0); 
this is the most important thing which moves the gate , (gate1 = the gate id we defined before (coords x,y,z and its now a new coords because we moved the gate to another place) and the 3.0 is the speed of the gate movment.
PHP код:
SendClientMessage(playerid0x0000BBAA"the Gate Opened Successfuly , Weclome !"); 
this is the message that displays when the gates is opened (0x0000BBAA = blue color )
the /close Command is the same but we add the origin coords back.
in the last our code should be like this:

PHP код:
#include <a_samp>
#define FILTERSCRIPT
new gate1;
public 
OnFilterScriptInit()
{
    
Gate1 CreateObject(9801245.5999755859, -767.0999755859493.9000015258790.00.00.0100.0);//gate 1
public OnPlayerCommandText(playeridcmdtext[])
{
    if(!
strcmp(cmdtext"/open"true)){
        if(
IsPlayerInRangeOfPoint(playerid15.01245.5999755859, -767.0999755859493.900001525879)){
            
MoveObject(gate11256.5999755859,-767.0999755859493.9000015258793.00.00.00.0);
            
SendClientMessage(playerid0x0000BBAA"the Gate Opened Successfuly , Weclome !");
            return 
1;
        }
    }
    if(!
strcmp(cmdtext"/close"true)){
        if(
IsPlayerInRangeOfPoint(playerid15.01245.5999755859, -767.0999755859493.900001525879)){
            
MoveObject(gate11245.5999755859, -767.0999755859493.9000015258793.00.00.00.0);
            
SendClientMessage(playerid0xAA3333AA"the Gate Closed successfuly !");
            return 
1;
        }
    }
  return 
0;

thats it , i hope you understood something from it and if it helped you please +rep me , thanks for reading and good luck!
Reply
#2

Why use 2 commands for opening and closing you could of simply done /gate to open and close, and a variable to check if the gate is open so you can close it when you write /gate, and if the gate is closed you can open it using /gate.

And why strcmp, why not zcmd ?
Reply
#3

Quote:
Originally Posted by Lexi'
Посмотреть сообщение
Why use 2 commands for opening and closing you could of simply done /gate to open and close, and a variable to check if the gate is open so you can close it when you write /gate, and if the gate is closed you can open it using /gate.

And why strcmp, why not zcmd ?
thanks for your post , 1- im a newbie scripter i just want to help other newbie scripters like me
2- its not as you said coz it meant to be simple , thats why, but thanks for your comment.
Reply
#4

Quote:
Originally Posted by xMCx
Посмотреть сообщение
thanks for your post , 1- im a newbie scripter i just want to help other newbie scripters like me
2- its not as you said coz it meant to be simple , thats why, but thanks for your comment.
By using strcmp you are leading newbies to the bad way.
Reply
#5

Quote:
Originally Posted by Lexi'
Посмотреть сообщение
By using strcmp you are leading newbies to the bad way.
owh i didnt figure that .. but in last we learn of our mistakes dont we
Reply
#6

Good Work And Thnz
Reply
#7

Quote:
Originally Posted by [LB]BlAcK_DeViL
Посмотреть сообщение
Good Work And Thnz
thanks
Reply
#8

I really needed to know that, thanks a lot.
Reply
#9

You can make auto gates by using OnPlayerUpdate and IsPlayerInRangeOfPoint

Other than that good work!
Reply
#10

Quote:
Originally Posted by gtakillerIV
Посмотреть сообщение
You can make auto gates by using OnPlayerUpdate and IsPlayerInRangeOfPoint

Other than that good work!
yep, but that is easier for newbies , although zcmd is much easier.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)