Jump to content

onClientMouseWheel & GUI problem


Recommended Posts

Hey all, i'm having a small issue with my script... I wish to create a speed boost script which pushes the player's speed with scroll. My problem is though it needs a GUI element, and the cursor needs to be shown... This is the problem, the player cant drive with a cursor on the screen... I tested it with other active GUI's and it was slightly not working just a bad argument in the server script... So all i need you focusing on is the client... I can do the rest.

I just need the client's gui to be hidden, aka GUISetAlpha, and somehow make it always active... I dont think this is possible :| No cursor is good...

Meta.xml:

    "Chris" version="1.0" type="script" name="Speed Boost" description="Move your scroll wheel up and down to increase speed!" /> 
    

booster-c.lua:

window = {} 
window[1] = guiCreateWindow(0,0,1,1,"",true) 
  
addEventHandler( "onClientMouseWheel", getRootElement(), 
function(up_down) 
if (up_down == 1) then 
triggerServerEvent ( "pushSpeed", getLocalPlayer()) 
elseif (up_down == -1) then 
triggerServerEvent ( "pullSpeed", getLocalPlayer()) 
end 
end 
) 

booster-s.lua:

function getElementSpeed(element,unit) 
    if (unit == nil) then unit = 0 end 
    if (isElement(element)) then 
        local x,y,z = getElementVelocity(element) 
        if (unit=="mph" or unit==1 or unit =='1') then 
            return (x^2 + y^2 + z^2) ^ 0.5 * 100 
        else 
            return (x^2 + y^2 + z^2) ^ 0.5 * 1.61 * 100 
        end 
    else 
        outputDebugString("Not an element. Can't get speed") 
        return false 
    end 
end 
  
function setElementSpeed(element, unit, speed) 
    if (unit == nil) then unit = 0 end 
    if (speed == nil) then speed = 0 end 
    speed = tonumber(speed) 
    local acSpeed = getElementSpeed(element, unit) 
    if (acSpeed~=false) then 
        local diff = speed/acSpeed 
        local x,y,z = getElementVelocity(element) 
        setElementVelocity(element,x*diff,y*diff,z*diff) 
        return true 
    end 
  
    return false 
end 
  
addEvent("pushSpeed",true) 
addEventHandler( "pushSpeed", getRootElement(), 
function() 
theVehicle = getPedOccupiedVehicle(source) 
if (theVehicle) then 
setElementSpeed(theVehicle, 2, getElementSpeed(theVehicle,2)+55) 
end 
end 
) 
  
addEvent("pullSpeed",true) 
addEventHandler( "pullSpeed", getRootElement(), 
function() 
theVehicle = getPedOccupiedVehicle(source) 
if (theVehicle) then 
setElementSpeed(theVehicle, 2, getElementSpeed(theVehicle,2)-55) 
end 
end 
) 
  

After failing i tried this:

addEventHandler( "onClientKey", getRootElement(), 
function(button, press) 
if (button == mouse_wheel_up) then 
triggerServerEvent ( "pushSpeed", getRootElement()) 
elseif (button == mouse_wheel_down) then 
triggerServerEvent ( "pullSpeed", getRootElement()) 
end 
end 
) 
  

and i tried this:

function key(key, keyState) 
if (key == mouse_wheel_up) then 
triggerServerEvent ( "pushSpeed", getRootElement()) 
elseif (key == mouse_wheel_down) then 
triggerServerEvent ( "pullSpeed", getRootElement()) 
end 
end 
bindKey ("mouse_wheel_up", "both", key) 
bindKey ("mouse_wheel_down", "both", key) 

edit:    Updated some of the code

Edited by Guest
Link to comment

ehm, why do you want gui to always be active? you can use onClientKey with mouse_wheel_up and down without gui, and mouse_wheel_up and mouse_wheel_down should be strings, like:

addEventHandler( "onClientKey", getRootElement(), 
function(button, press) 
if (button == "mouse_wheel_up") then 
triggerServerEvent ( "pushSpeed", getLocalPlayer()) 
elseif (button == "mouse_wheel_down") then 
triggerServerEvent ( "pullSpeed", getLocalPlayer()) 
end 
end 
) 

and send localPlayer instead of root.

Btw, why do you have server sided script? all that can be done client sided

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...