[Tutorial] Simple Automatic Gate Tutorial
#1

In this tutorial you will how to create gates and how they will move when a player is close to the gate.

PS : This works with any object and some parts of the script may only be understood by professional scripters

FIRST STEP

pawn Code:
new Gate;
new GateOpen =0; //put this at the top of the script
SECOND STEP
pawn Code:
forward GatesOpen();
forward GatesClose(); //put these with other forwards or under the variables
THIRD STEP
pawn Code:
SetTimer("GatesOpen",1000,1); //This is the timer, put this under Public OnGameModeInIt
FOURTH STEP
pawn Code:
Gate = CreateObject(objectid,x,y,z,rotX,rotY,rotZ); //This is where you define which object you want to be moved
FIFTH STEP
pawn Code:
//put this anywhere in the script
public GatesOpen()
{
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(PlayerToPoint(10.0, i, x,y,z) && GateOpen == 0) //replace x,y,z with the gate coords
        {
            //if(gTeam[i] == TEAM_NOOBS) //use this if you wish to set this for a specific class
            {
                MoveObject(Gate, x,y,z, 5); //replace x,y,z with new coords for the object to be placed
                GateOpen =1;
                SetTimer("GatesClose",7000,0);
        }
        }
    }
}

public GatesClose()
{
     MoveObject(Gate, x,y,z, 5); //put the original x,y,z coords of the original gate coords
     GateOpen =0;
}
SIXTH STEP
pawn Code:
//the following is a function to get the current position of the player
//place the following code at the end of the script
PlayerToPoint(Float:radius, playerid, Float:X, Float:Y, Float:Z)
{
    new Float:oldpos[3], Float:temppos[3];
    GetPlayerPos(playerid, oldpos[0], oldpos[1], oldpos[2]);
    temppos[0] = (oldpos[0] -X);
    temppos[1] = (oldpos[1] -Y);
    temppos[2] = (oldpos[2] -Z);
    if(((temppos[0] < radius) && (temppos[0] > -radius)) && ((temppos[1] < radius) && (temppos[1] > -radius)) && ((temppos[2] < radius) && (temppos[2] > -radius)))
    {
        return true;
    }
    return false;
}
Well there you have it, a simple automatic gate tutorial, this is suitable for anyone
Reply
#2

lol that code wont work!!
you might want to reread what you wrote.

and try explaining WHY you are doing such stuff.
this is just a copy/paste tutorial and yet the code for them to copy and paste is not correct!

However its always good to see an effort,
try editing this and make it more understandable and Ill retract my statement,

regards
Reply
#3

Explain to me what's wrong? Everytime i used it in my script it works fine.
Reply
#4

well look at just this public

pawn Code:
public GatesOpen()
{
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(PlayerToPoint(10.0, i, x,y,z) && GateOpen == 0) //gate coords
        {
            //if(gTeam[i] == TEAM_NOOBS) //use this if you wish to set this for a specific class
            {
                MoveObject(Gate, x,y,z, 5); //new coords for the object to move
                GateOpen =1;
                SetTimer("GatesClose",7000,0);
        }
        }
    }
}
i dont see any where you have defined x,y,z with the "new" keyword or other wise
thats just one thing!

another is your using a function we dont have

PlayerToPoint
is not found on the wiki
(I know where to find it or how to make it but thats not the point)

also look threw the rest,
this should contain EVERYthing you need or otherwise youll confuse people.

I am just trying to help also please dont take offence to this, i know
its alot to write up a tutorial, but it is pointless if its not correct.

Also explain why you are doing what your doing,(for the noobies!!!)
or explain in the beginning you assume they can script..

hopefully this helps ya out a bit,
I know the tutorial could help alot of people just needs some touch ups.

if you havent read this yet I suggest you todo so,
it will help you when writing a tutorial
https://sampforum.blast.hk/showthread.php?tid=65567
Reply
#5

Fixed it, now I'll try to see where i can edit more for players to understand more easily.

Thanks for helping Jonny5
Reply
#6

Useful tutorial
How to make password gate?
Reply
#7

Quote:
Originally Posted by Wickeed
View Post
Useful tutorial
How to make password gate?
For password gate i suggest you view a tutorial on making a moveable gate with cmd
Reply
#8

C:\Users\user\Desktop\Sa-Mp\GF\gamemodes\gf.pwn(26353) : error 025: function heading differs from prototype
C:\Users\user\Desktop\Sa-Mp\GF\gamemodes\gf.pwn(26354) : error 021: symbol already defined: "PlayerToPoint"
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


2 Errors.
:S??
Reply
#9

nothing explained, put there, put here...

Code:
//the following is a function to get the current position of the player
u mad bro? that's the function for checking is player at some range, and you don't need that function since we have IsPlayerInRangeOfPoint
Reply
#10

This tutorial is terrible. You managed to post broken code, and better yet didn't even explain anything. Not trying to be rude, but you could go much more in depth.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)