Known

Map's scripts.

Recommended Posts

Hello there, again. I'm here to show you guys how to add few scripts to your map.

Let's get started!

1- Teleport

Step 1 : Create a .lua file and call it "teleport.lua" then, copy this.

marker = createMarker(x, y, z, 'corona', size, 0, 0, 0, 0) -- [Here, add the information of the marker]

 function teleport(player)
 if getElementType(player)=="player" then
 local vehicle=getPedOccupiedVehicle(player)
 if source == marker then
 setElementPosition(vehicle , x, y, z) --[Add the information of the marker you want to teleport to]
 setElementRotation(vehicle, X, Y, Z) --[Add the rotations of the vehicle]
 setElementFrozen(vehicle, true)
 setTimer(setVehicleFrozen, 1000, 1, vehicle, false)
 end
 end
 end
 addEventHandler("onClientMarkerHit", getRootElement(), teleport) 

Step 2 : Open your map's meta file and add this line "<script src="teleport.lua" type="client"></script>"

2- Explosions

Step 1 : Create a .lua file and call it "explosions.lua" then, copy this.

gMe1 = getLocalPlayer()

function marker()
 marker1 = createMarker(x, y, z, "corona", size, 0, 0, 0, 0) --[Here, add the information of the marker]
 end

function MarkerHit ( hitPlayer, matchingDimension )
 vehicle = getPedOccupiedVehicle ( hitPlayer )
 if hitPlayer ~= gMe1 then return end
 if source == marker1 then
       explosion = createExplosion(x, y, z, <type>) --[Add coordinations to x, y, z. there are a lot of explosion types(look below)]
 end
 end
 
 addEventHandler( "onClientResourceStart", getResourceRootElement(getThisResource()), marker)
 addEventHandler ( "onClientMarkerHit", getRootElement(), MarkerHit)
 
 
-- 0: Grenade
-- 1: Molotov 
-- 2: Rocket
-- 3: Rocket Weak
-- 4: Car
-- 5: Car Quick
-- 6: Boat
-- 7: Heli
-- 8: Mine
-- 9: Object
-- 10: Tank Grenade
-- 11: Small
-- 12: Tiny

Step 2 : Open your map's meta file and add this line "<script src="explosions.lua" type="client"></script>"

3- Slow motion

Step 1 : Create a .lua file and call it "slowmotion.lua" then, copy this.

gMe1 = getLocalPlayer()

 function gravity1()
 marker1 = createMarker(x, y, z,"corona", s, 0, 0, 0, 0) --[Here, add the information of the first marker]
 marker2 = createMarker(x, y, z,"corona", s, 0, 0, 0, 0) --[Here, add the information of the second marker]
 end

 function MarkerHit ( hitPlayer, matchingDimension )
 vehicle = getPedOccupiedVehicle ( hitPlayer )
 if hitPlayer ~= gMe1 then return end
 if source == marker1 then
setGameSpeed(P ) --[Replace P with a number between 0 and 1]
 end
 if source == marker2 then
setGameSpeed(1)
 end
 end

 addEventHandler( "onClientResourceStart", getResourceRootElement(getThisResource()), gravity1 )
 addEventHandler ( "onClientMarkerHit", getRootElement(), MarkerHit )

Step 2 : Open your map's meta file and add this line "<script src="slowmotion.lua" type="client"></script>"

4- Scene camera

Step 1 : Create a .lua file and call it "scene_camera.lua" then, copy this.

marker1 = createMarker(X, Y, Z, "corona", Size, 0, 0, 0, 0) --[Here, add the information of the first marker]
marker2 = createMarker(X, Y, Z, "Type", Size, 0, 0, 0, 0) --[Here, add the information of the first marker]

function sceneCamera(hitPlayer, matchingDimension)
    if(hitPlayer ~= getLocalPlayer() or not matchingDimension) then return end

    if(source == marker1)then
        setCameraMatrix(X, Y, Z, TX, TY, TZ, Rotation, View) --[Add Information of the location of the camera and the look target. Rotation is the rotation of the camera (from 0 to 360) and the view of the camera (from 0 to 180)]
    end
    if(source == marker2)then
        setCameraTarget(hitPlayer)
    end
end

addEventHandler("onClientMarkerHit", getRootElement(), sceneCamera)

Step 2 : Open your map's meta file and add this line "<script src="scene_camera.lua" type="client"></script>"

5- Velocity

Step 1 : Create a .lua file and call it "velocity.lua" then, copy this.

speed1 = createMarker(x, y, z, "corona", size, 0, 0, 0, 0) --[Here, add the information of the marker]

function boost(player)
 if getElementType(player)=="player" then
     local vehicle = getPedOccupiedVehicle(player)
        if source == speed1 then
            setElementVelocity(vehicle, 0, 0, 0) --[Change the "0 , 0 , 0". The first 0 is X coordination, Second 0 is Y coordination, Third 0 is Z coordination]
        end
  end
end
addEventHandler("onClientMarkerHit", resourceRoot, boost)

Step 2 : Open your map's meta file and add this line "<script src="velocity.lua" type="client"></script>"

5- Moving objects (This is the most complicated one)

Step 1 : Create a .lua file and call it "movement.lua" then, copy this.

marker1 = createMarker(X, Y, Z, "corona", Size, 0, 0, 0, 0) --[Here, add the information of the marker]

<name> = createObject(ID, X, Y, Z, RX, RY, RZ) --[Add informations of the object into ID, X, Y, Z, RX (Rotation X), RY(Rotation Y), RZ(Rotation Z)]
[<name> = createVehicle(ID, X, Y, Z, RX, RY, RZ)] --[Add informations of the vehicle into ID, X, Y, Z, RX (Rotation X), RY(Rotation Y), RZ(Rotation Z)]
setElementCollisionsEnabled(<name>, false) --[Put the name of the movable object/vehicle inside <name>. (example: <name> replaced by panel.)]
setElementFrozen(<name>, true)

function movement(hitPlayer, matchingDimension)
    if(hitPlayer ~= getLocalPlayer() or not matchingDimension) then return end
    
    if(source == marker1)then
        addEventHandler("onClientRender", getRootElement(), move)
        startTime = getTickCount()
        endTime = startTime + <move> --[Add the time in millisecond inside <move> to make the movement]
        setTimer(function()
            removeEventHandler("onClientRender", getRootElement(), move)
        end, <move>, 1)
    end
end
addEventHandler("onClientMarkerHit", getRootElement(), movement)

function move()
    local now = getTickCount()
    local elapsedTime = now - startTime
    local duration = endTime - startTime
    local progress = elapsedTime / duration
    
    local x, y, z = interpolateBetween(X, Y, Z, --[Copy the coordinations of X, Y, Z from your movable object/vehicle inside X, Y, Z of this function. (don't change x, y, z at local x, y, z)]
                                        TX, TY, TZ, --[Add the coordinations of the target to move]
                                        progress, "Linear")
    setElementPosition(<name>, x, y, z) --[Change only <name> of this line]
end

Step 2 : Open your map's meta file and add this line "<script src="movement.lua" type="client"></script>"

That's all for now. If anybody has a problem or wants to know about another script, leave a comment.

Edited by Known

Share this post


Link to post
Share on other sites

Appreciable effort but let's be more optimistic here - you could have just shown how markers work and posted direct links to various functions (MTA wiki). I'm sure if a player has head on his shoulders, he can manage to understand how simply everything works here out, nothing too much to explain though :P

Edited by xSimas

Share this post


Link to post
Share on other sites

Appreciable effort but let's be more optimistic here - you could have just shown how markers work and posted direct links to various functions (MTA wiki). I'm sure if a player has head on his shoulders, he can manage to understand how simply everything works here out, nothing too much to explain though :P

Simas, this tutorial is more for beginners. I mean, with 0 scripting knowledge, you could make any of those scripts by following the steps.

Share this post


Link to post
Share on other sites

After a while I glanced clearly and noticed something, in your second snippet the explosion one, you are declaring a global var gMe1 whereas on the marker hit event you are comparing source ~= gMe and forgot to put 1 which will generate an error ofcourse.

Since its for people with 0 scripting knowledge I wanted to make it clear so that you can edit the post and change it to gMe1 :D

Total nerd!

Share this post


Link to post
Share on other sites
1 hour ago, sahil007 said:

I want to increase the size of moving object ..how can i do that ... i added line :- setscaleobject(id,size) but did not work please help 

you do it by using:

setObjectScale(theObject, scale)

 

Share this post


Link to post
Share on other sites
On 13.04.2016 at 1:43 PM, sahil007 said:

I want to increase the size of moving object ..how can i do that ... i added line :- setscaleobject(id,size) but did not work please help 

@sahil007

object1        = createObject (ObjectID, LX, LY, LZ, RX, RY, RZ) -- LX/Y/Z Location X/Y/Z   RX/Y/Z Rotation X/Y/Z
 setObjectScale(object1, size)
        
 

Example:

 

 

 

object1        = createObject (6959, 3693.2998046875, -1879.400390625, 1.6000000238419, 270, 180, 0)

setObjectScale(object1, 0)

 

 

 

Edited by Flexxy

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.