Jump to content

Who can write a simple script for mec?


mores

Recommended Posts

try.

function startVehicleChanging() 
    if isTimer(vehChangeTimer) then killTimer(vehChangeTimer) end 
    vehChangeTimer = 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 
  
addEvent("onRaceStateChanging",true) 
addEventHandler("onRaceStateChanging",root, 
function (new) 
if (new == "Running") then 
    startVehicleChanging() 
    triggerClientEvent(source,"onCounterStart",source) 
end 
if (new =="LoadingMap") then 
triggerClientEvent(source,"removeCounter",source) 
if isTimer(vehChangeTimer) then resetTimer(vehChangeTimer) end 
if isTimer(vehChangeTimer) then killTimer(vehChangeTimer) end 
end 
end 
) 

function startEverything() 
addEventHandler("onClientRender",root,drawCounterSHI) 
timer = setTimer(function() 
    counter = counter - 1 
    if counter < 0 then 
        counter = 15 
        r,g,b = 0,255,0 
    end 
    if counter <= 3 then 
        r,g,b = 255,0,0 
    end 
end,1000,0) 
  
end 
addEvent("onCounterStart",true) 
addEventHandler("onCounterStart",getRootElement(),startEverything) 
  
addEvent("removeCounter", true) 
addEventHandler("removeCounter", getRootElement(), 
function () 
removeEventHandler("onClientRender", root, draw) 
if isTimer(timer) then resetTimer(timer) end 
if isTimer(timer) then killTimer(timer) end 
end 
) 

Link to comment
shaman thank for your attemps but it only freeze it during the map loading

that's why it's "LoadingMap", i can't help you if you don't know anything, i can also barely understand what you mean.

check what you need here and change it with it:

undefined

NoMap

LoadingMap

PreGridCountdown

GridCountdown

Running

MidMapVote

SomeoneWon

TimesUp

EveryoneFinished

PostFinish

NextMapSelect

NextMapVote

ResourceStopping

Link to comment
shaman thank for your attemps but it only freeze it during the map loading

that's why it's "LoadingMap", i can't help you if you don't know anything, i can also barely understand what you mean.

anyways if possible can u show me a video of whats wrong so i can understand what you mean.

check what you need here and change it with it:

undefined

NoMap

LoadingMap

PreGridCountdown

GridCountdown

Running

MidMapVote

SomeoneWon

TimesUp

EveryoneFinished

PostFinish

NextMapSelect

NextMapVote

ResourceStopping

Link to comment

look

when news map is start after 3.2.1.go the counter should start again like main script on every map

Look ( your vehicle will be change ) when new map starts it start work again 15.14.13..... on every map

Edited by Guest
Link to comment

Replace everything with this. The timer doesn't always match up perfectly with the server, though. Probably getTimerDetails or making everything client-side would be better so the timer would match up correctly.

It's the best I can do for you for now. And, mores. Instead of begging constantly for every little change, why not put that effort in trying to fix it on your own? I was hesistant about replying again to this thread but this is the final thing I will post here unless you actually try and show some code (that indicates you've put some time and thought into) of your own. Good luck :fadein:

Some great learning material:

https://wiki.multitheftauto.com/wiki/Main_Page

https://en.wikibooks.org/wiki/Lua_Programming

http://lua-users.org/wiki/TutorialDirectory

http://luatut.com/crash_course.html

Client:

-->> 
-- This piece of code probably won't make a lot of sense to you. It replaces the original dxDrawText function to make it scale and fit on every resolution, so you don't have to worry about it. 
local osW, osH = 1024,768 -- Original screen width and height, do not change it unless you're trying to position dxDrawText's on your own screen then change this to your own resolution. 
local csW, csH = guiGetScreenSize() -- Client/player screen width and height 
local DrawText = dxDrawText 
  
function dxDrawText(...) 
    arg[2], arg[3], arg[4], arg[5], arg[7] = arg[2]/osW*csW, arg[3]/osH*csH, arg[4]/osW*csW, arg[5]/osH*csH, (arg[7] or 1)/osW*csW 
    return DrawText(unpack(arg)) 
end 
--<< 
  
local isTimerVisible = false 
  
function displayCounter() 
    dxDrawText("Your vehicle will change in: "..count, 237 + 1, 644 + 1, 811 + 1, 685 + 1, tocolor(0, 0, 0, 255), 1.60, "default", "center", "center", false, false, true, false, false) -- background (shadow) 
    dxDrawText("Your vehicle will change in: "..count, 237, 644, 811, 685, tocolor(255, 162, 0, 255), 1.60, "default", "center", "center", false, false, true, false, false) -- foreground 
end 
  
function showCounter(Time) 
    if Time then 
        count = Time 
        counting = setTimer(function() 
            count = count - 1 
        end,1000,count) 
         
        if not isTimerVisible then 
            addEventHandler("onClientRender",root,displayCounter) 
            isTimerVisible = true 
        end 
    else 
        if isTimer(counting) then 
            killTimer(counting) 
        end 
        removeEventHandler("onClientRender",root,displayCounter) 
        isTimerVisible = false 
    end 
end 
addEvent("showCounter",true) 
addEventHandler("showCounter",resourceRoot,showCounter) 

Server:

local Time = 15 -- Change this to your preferred time in seconds 
  
function onRoundStart(state) 
    if state == "Running" then 
        changeVeh() 
        changeTimer = setTimer(changeVeh,Time*1000,0) 
    elseif state == "PostFinish" or state == "TimesUp" or state == "EveryoneFinished" or state == "SomeoneWon" or state == "ResourceStopping" or state == "NoMap" or state == "LoadingMap" then 
        if isTimer(changeTimer) then 
            killTimer(changeTimer) 
        end 
        triggerClientEvent("showCounter",resourceRoot,false) 
    end 
end 
addEvent("onRaceStateChanging",true) 
addEventHandler("onRaceStateChanging",root,onRoundStart) 
  
function onRacerWasted() 
    outputChatBox(getPlayerName(source).." died.") 
    triggerClientEvent(source,"showCounter",resourceRoot,false) 
end 
addEvent("onPlayerRaceWasted",true) 
addEventHandler("onPlayerRaceWasted",root,onRacerWasted) 
  
function changeVeh() 
    for _,plr in ipairs(getElementsByType("player")) do 
        if not isPedDead(plr) then 
            triggerClientEvent(plr,"showCounter",resourceRoot,Time) 
            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 
end 

Link to comment
  • 1 month later...

Hi Guys again !

I want to tell you something. I've forgotten my password to "mores" so I 've creted this account. I know I know I closed this topic but after my holiday I thought I want to create this script and I promise I will try to do this with your help,( not only you like before)

Can you give me secound chance ? I promise I will try :D

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

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