Jump to content

Who can write a simple script for mec?


mores

Recommended Posts

I'm sorry for bad place I 'm new in this forum and thank you for your help but I want script like this (server script not map) :

PS: Sorry Noki Becouse I pressed "quick replay" and sent something for you xD

Edited by Guest
Link to comment
  
setTimer( 
    function () 
        for _, v in ipairs(getElementsByType("player")) do 
            if (isPedInVehicle(v)) then 
            local x, y, z = getElementPosition(v) 
                local veh = getPedOccupiedVehicle(v) 
                    destroyElement(veh) 
                    veh = nil 
                    vehicle = createVehicle(vehicle id here, x, y, z) 
                    warpPedIntoVehicle(v, vehicle) 
            end 
        end 
    end, 15000, 0 
) 
  

This is what you mean? Just use math.random to change vehicle

Link to comment

You know just like on this video man. Server should do it automatically for all players at the same moment every 15 secound for random vehicle for all players. And can you make a sign (vehicle will be change in 1-15 seconds)

Like there man

And tell me where I should write vehicles IDs in this script. (Script will random choose car from ID's which I will write in script)

AND THE MOST IMPORTANT: Thanks for your help

Edited by Guest
Link to comment

try making a table and math.random

try this ,add more ids in the table { } make sure to add , when u add more ids!

found a problem in this : warpPedIntoVehicle in argument 2 got boolean, it happens sometimes.

local vehicles = {356, 411 } 
  
setTimer( 
    function () 
        for _, v in ipairs(getElementsByType("player")) do 
            if (isPedInVehicle(v)) then 
            local x, y, z = getElementPosition(v) 
                local veh = getPedOccupiedVehicle(v) 
                    destroyElement(veh) 
                    veh = nil 
                    local randomveh = vehicles[math.random(#vehicles)] 
                    vehicle = createVehicle(randomveh, x, y, z) 
                    warpPedIntoVehicle(v, vehicle) 
end 
end 
end 
, 15000, 0 
) 

Edited by Guest
Link to comment
try making a table and math.random

try this ,add more ids in the table { } make sure to add , when u add more ids!

found a problem in this : warpPedIntoVehicle in argument 2 got boolean, it happens sometimes.

local vehicles = {356, 411 } 
  
setTimer( 
    function () 
        for _, v in ipairs(getElementsByType("player")) do 
            if (isPedInVehicle(v)) then 
            local x, y, z = getElementPosition(v) 
                local veh = getPedOccupiedVehicle(v) 
                    destroyElement(veh) 
                    veh = nil 
                    local randomveh = vehicles[math.random(#vehicles)] 
                    vehicle = createVehicle(randomveh, x, y, z) 
                    warpPedIntoVehicle(v, vehicle) 
end 
end 
end 
, 15000, 0 
) 

He wants to change the vehicle model, what's the point of destroying them? just use setElementModel.

Link to comment

This will work for every player's vehicle on your server.

Here's a list of ID's that you can use: https://wiki.multitheftauto.com/wiki/Vehicle_IDs

Currently every ID is added to the table so it'll turn you in litterally anything like boats, planes, trailers....

vehicleIDS = { 602, 545, 496, 517, 401, 410, 518, 600, 527, 436, 589, 580, 419, 439, 533, 549, 526, 491, 474, 445, 467, 604, 426, 507, 547, 585, 
405, 587, 409, 466, 550, 492, 566, 546, 540, 551, 421, 516, 529, 592, 553, 577, 488, 511, 497, 548, 563, 512, 476, 593, 447, 425, 519, 520, 460, 
417, 469, 487, 513, 581, 510, 509, 522, 481, 461, 462, 448, 521, 468, 463, 586, 472, 473, 493, 595, 484, 430, 453, 452, 446, 454, 485, 552, 431,  
438, 437, 574, 420, 525, 408, 416, 596, 433, 597, 427, 599, 490, 432, 528, 601, 407, 428, 544, 523, 470, 598, 499, 588, 609, 403, 498, 514, 524,  
423, 532, 414, 578, 443, 486, 515, 406, 531, 573, 456, 455, 459, 543, 422, 583, 482, 478, 605, 554, 530, 418, 572, 582, 413, 440, 536, 575, 534,  
567, 535, 576, 412, 402, 542, 603, 475, 449, 537, 538, 570, 441, 464, 501, 465, 564, 568, 557, 424, 471, 504, 495, 457, 539, 483, 508, 571, 500,  
444, 556, 429, 411, 541, 559, 415, 561, 480, 560, 562, 506, 565, 451, 434, 558, 494, 555, 502, 477, 503, 579, 400, 404, 489, 505, 479, 442, 458,  
606, 607, 610, 590, 569, 611, 584, 608, 435, 450, 591, 594 } 
  
setTimer( -- initiate a timer 
    function() -- create a function within the timer 
        for _,plr in pairs(getElementsByType("player")) do -- loop through every player in the server 
            local veh = getPedOccupiedVehicle(plr) -- get their vehicle if they have one 
            local model = vehicleIDS[math.random(1,#vehicleIDS)] -- pick random value from the table 
            if veh and model and getPedOccupiedVehicleSeat(plr) == 0 then -- check if veh and model are present and wether the player is the one driving it 
                local x,y,z = getElementVelocity(veh) -- get the vehicle's current velocity 
                setElementVelocity(veh,x,y,z+0.05) -- set its new velocity and add 0.05 to the z value. the z value means up and down 
                local hp = getElementHealth(veh) -- get the vehicle's current health 
                setElementModel(veh,model) -- change the vehicle's model 
                setElementHealth(veh,hp) -- re-apply the vehicle's health 
            end -- end if statement 
        end -- close for loop 
    end -- end the function 
,15000,0) -- trigger function after 15000 milliseconds and 0 for infinite calls -- close timer. 

If you don't want the vehicles to retain their health remove these 2 lines:

local hp = getElementHealth(veh) 
setElementHealth(veh,hp) 

It also makes your car jump slightly so the vehicles won't get stuck in the ground.

If you don't want that remove these lines:

local x,y,z = getElementVelocity(veh) 
setElementVelocity(veh,x,y,z+0.05) 

Link to comment

Yeah script works :D

But two thinks i need more :D

1 is the Counter

2 can it start change cars after 3.2.1.go <--- then should be start of this 15 seconds on every map. you know guys

BIG THANK YOU GUYS FOR THIS WHAT YOU DID :P

Edited by Guest
Link to comment

I can't really help you to get it exactly on 3, 2, 1, go, since you'd have to use the functions in the race script and I have no idea what they are or how to use them. Maybe someone else does. This should work as a fix though. All I did is add a timer to the entire function so it will start after 10 seconds.

setTimer(function() 
    setTimer( 
        function() 
            for _,plr in pairs(getElementsByType("player")) do 
                local veh = getPedOccupiedVehicle(plr) 
                local model = vehicleIDS[math.random(1,#vehicleIDS)] 
                if veh and model and getPedOccupiedVehicleSeat(plr) == 0 then 
                    local x,y,z = getElementVelocity(veh) 
                    setElementVelocity(veh,x,y,z+0.05) 
                    local hp = getElementHealth(veh) 
                    setElementModel(veh,model) 
                    setElementHealth(veh,hp) 
                end 
            end 
        end 
    ,15000,0) 
end,10000,1) 

Edited by Guest
Link to comment
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...