Jump to content

lua confused with eachother problem


hulpje

Recommended Posts

Im not good with scripts but im using some scripts other people made (thank you) for my (race) maps. Now I have found a script on this forum http://forum.multitheftauto.com/viewtopic.php?f=91&t=30975 that exactly does what I want:

Speedboost:

function start() 
    Speedboost = { 
        createMarker (-3004,-841,0.11,"corona",10,255,0,0,105), 
  
    }                                                         
  
end 
addEventHandler ( "onClientResourceStart", getResourceRootElement(getThisResource()), start ) 
                                   
Multiplier = 5.0 
function SpeedBoost (player) 
    if player ~= getLocalPlayer() then return end 
    if getElementType(player) == "player" then 
        if isPedInVehicle ( player ) then 
            local car = getPedOccupiedVehicle(player) 
            if getVehicleController(car) == player then 
                speedx, speedy, speedz = getElementVelocity ( car ) 
                speedcnx = (speedx*Multiplier) 
                speedcny = (speedy*Multiplier) 
                speedcnz = (speedz*Multiplier) 
                setElementVelocity ( car, speedcnx, speedcny,speedcnz ) 
                fixVehicle(car) 
                playSoundFrontEnd(46) 
            end 
        end 
    end 
end 
addEventHandler ( "onClientMarkerHit", getResourceRootElement(getThisResource()), SpeedBoost ) 

And give my car a little bounce (changing Z) (same script actually:)

function start() 
    Speedboost = { 
        createMarker (-3374,-837,19.5,"corona",10,255,0,0,105), 
  
    }                                                         
  
end 
addEventHandler ( "onClientResourceStart", getResourceRootElement(getThisResource()), start ) 
                                    
Multiplier = 1.5 
function SpeedBoost (player) 
    if player ~= getLocalPlayer() then return end 
    if getElementType(player) == "player" then 
        if isPedInVehicle ( player ) then 
            local car = getPedOccupiedVehicle(player) 
            if getVehicleController(car) == player then 
                speedx, speedy, speedz = getElementVelocity ( car ) 
                speedcnx = (speedx*Multiplier) 
                speedcny = (speedy*Multiplier) 
                speedcnz = (speedz*Multiplier) 
                setElementVelocity ( car, speedcnx, speedcny,speedcnz+0.2 ) 
                fixVehicle(car) 
                playSoundFrontEnd(46) 
            end 
        end 
    end 
end 
addEventHandler ( "onClientMarkerHit", getResourceRootElement(getThisResource()), SpeedBoost ) 

problem is both scripts work fine stand-alone but get confused with each other when I place them together in a map.

I tried search for some other scripts but they don't work or bounce my car is a preset X,Y,Z (while I want it to bounce to the direction I drive).

I searched on forum and tried to add some marker1, marker2 and stuff, also tried to add something with "If == then" but I just can't figure it out.

If someone could help me with making both scripts work in 1 map would be really awsome.

Link to comment

Change the names of the following in ONE of the above mentioned scripts:

1. function attached to the onClientResourceStart event.

2. function attached to the onClientMarkerHit event.

3. Name of table containing the the marker.

Link to comment

thanks, but I don't really understand what to do now yet :(

1/2- change function "Speedboost" for something I make up (like bounce)?

3 - I don't really understand what I have to do here, is this with marker1 in the location and adding it in OnClientMarkerHit?

Link to comment

try this:

  
local unique = md5(math.random(1,999)..'smama') 
function start() 
    Speedboost = { 
        createMarker (-3004,-841,0.11,"corona",10,255,0,0,105), 
  
    }                                                         
 for i,v in pairs(Speedboost) do setElementData(v, unique, true, false) end 
end 
addEventHandler ( "onClientResourceStart", getResourceRootElement(getThisResource()), start ) 
                                   
Multiplier = 1.5 
function SpeedBoost (player) 
    if player ~= getLocalPlayer() then return end 
   if not getElementData(source, unique) then return end 
    if getElementType(player) == "player" then 
        if isPedInVehicle ( player ) then 
            local car = getPedOccupiedVehicle(player) 
            if getVehicleController(car) == player then 
                speedx, speedy, speedz = getElementVelocity ( car ) 
                speedcnx = (speedx*Multiplier) 
                speedcny = (speedy*Multiplier) 
                speedcnz = (speedz*Multiplier) 
                setElementVelocity ( car, speedcnx, speedcny,speedcnz +0.2) 
                fixVehicle(car) 
                playSoundFrontEnd(46) 
            end 
        end 
    end 
end 
addEventHandler ( "onClientMarkerHit", getResourceRootElement(getThisResource()), SpeedBoost ) 

Link to comment

I tried some more things but failed

I think the easiest thing is to make the script react on a specific marker, so add something like "local myMarker4 =" and also add that specific marker in the line of the event handler.

I tried adding it myself, but either the corona's became invisible or (and) stopped functioning.

If someone could help how to properly add markers in one of the scrips in the first post I would really be grateful >:

Link to comment

Thank you qais, I probaly did something wrong because it (somehow) worked this time ^^

But I have one more problem now, When I tried the script in my first post it speedboosted me (first corona) the way I was driving (I didn't had to do anything with setElementVelocity).

Now if I dont set a X or Y or Z the corona simply isn't doing anything. Which means I had to set X at setElementVelocity to make it work, but lets say if I want to drive trough the speedboost from another angle it will totally push me the wrong way. Is there a way to change it so it speedboosts me in the direction I drive?

(The script that make my car bounce works fine)

I add video so you can see what I mean:

this is the script (thank you qais) for the speedboost at first corona now:

local unique = md5(math.random(1,999)..'smama') 
function start() 
    Speedboost = { 
        createMarker (-3004,-841,0.11,"corona",10,255,0,0,105), 
  
    }                                                         
 for i,v in pairs(Speedboost) do setElementData(v, unique, true, false) end 
end 
addEventHandler ( "onClientResourceStart", getResourceRootElement(getThisResource()), start ) 
                                  
Multiplier = 5.0 
function SpeedBoost (player) 
    if player ~= getLocalPlayer() then return end 
   if not getElementData(source, unique) then return end 
    if getElementType(player) == "player" then 
        if isPedInVehicle ( player ) then 
            local car = getPedOccupiedVehicle(player) 
            if getVehicleController(car) == player then 
                speedx, speedy, speedz = getElementVelocity ( car ) 
                speedcnx = (speedx*Multiplier) 
                speedcny = (speedy*Multiplier) 
                speedcnz = (speedz*Multiplier) 
                setElementVelocity ( car, speedcnx-1.2,speedcny,speedcnz) 
                fixVehicle(car) 
                playSoundFrontEnd(46) 
            end 
        end 
    end 
end 
addEventHandler ( "onClientMarkerHit", getResourceRootElement(getThisResource()), Speed 

Link to comment

You have some errors ..

local unique = md5(math.random(1,999)..'smama') 
function start() 
    Speedboost = { 
        createMarker (-3004,-841,0.11,"corona",10,255,0,0,105), 
    }                                                         
for i,v in pairs(Speedboost) do setElementData(v, unique, true, false) end 
end 
addEventHandler ( "onClientResourceStart",resourceRoot, start ) 
  
Multiplier = 5.0 
function SpeedBoost (player) 
    if player ~= getLocalPlayer() then return end 
    if not getElementData(source, unique) then return end 
    if getElementType(player) == "player" then 
        if isPedInVehicle ( player ) then 
            local car = getPedOccupiedVehicle(player) 
            if getVehicleController(car) == player then 
                speedx, speedy, speedz = getElementVelocity ( car ) 
                speedcnx = (speedx*Multiplier) 
                speedcny = (speedy*Multiplier) 
                speedcnz = (speedz*Multiplier) 
                setElementVelocity ( car, speedcnx-1.2,speedcny,speedcnz) 
                fixVehicle(car) 
                playSoundFrontEnd(46) 
            end 
        end 
    end 
end 
addEventHandler ( "onClientMarkerHit",root, Speed) 

Link to comment

thanks qais,

I indeed can change the following numbers (×)

and it will speedboost me without changing my direction.

  
Multiplier = × 
speedcnx = (speedx*×) 
speedcny = (speedy*×) 
  

everything works fine in my map editor now, so I guess my problem is solved ^^

@ Al3grab, idk im just using qais script, that one works fine now ^^

Link to comment

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.
×
×
  • Create New...