Jump to content

Non server-side functions to Server-side?


anumaz

Recommended Posts

Hey,

I created a little script that works just fine client-side:

It creates a fire, a blip and PlaySound3D.

However, that is all client-side and no one in the server can see/hear them. These functions (or most of them) are just available client-side. My question is: how to make them hearable/visible to others?

Thanks,

Anumaz

Link to comment
function makeitburn (player, commandName, fdfire) 
    triggerClientEvent( "createfdfire", getRootElement(), fdfire ) 
end 
addCommandHandler ( "fdfire", makeitburn ) 

Anything wrong with that? It always shows the syntax as if I didn't put a number next to it?

Link to comment

Client side:

function fdbell() 
    local Sound = playSound3D( "alarm/firealarm.mp3", 1725, -1130, 24, false )  
    setElementInterior(Sound, getElementInterior(localPlayer)) 
    setElementDimension(Sound, getElementDimension(localPlayer)) 
    setSoundMinDistance(Sound, 25)  
    setSoundMaxDistance(Sound, 70) 
    -- setSoundVolume( Sound, 1 ) 
end 
addEvent("ringTheBell", true) 
addEventHandler("ringTheBell", root, fdbell) 
function loadthescript() 
    outputChatBox("Script loaded -- debug") 
end 
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), loadthescript) 
addCommandHandler("bell", fdbell) 
function fdfire(commandName, fireid) 
    if fireid then 
        if tonumber(fireid) == 1 then 
            createFire(1700, -1168, 23, 60) 
            createFire(1698, -1168, 23, 60) 
            local blipicon = createBlip( 1700, -1168, 23, 43, 0, 0, 0, 255 ) 
            outputChatBox("Fire created at 1700, -1168, 23") 
            local onlinePlayers = getElementsByType("player") 
            for index, player in pairs(onlinePlayers) do 
                local x, y, z = getElementPosition(player) 
                local distance = getDistanceBetweenPoints3D(1725, -1130, 24, x, y, z)  
                if (distance <50) then 
                    setTimer(function () 
                        destroyElement(blipicon) 
                    end, 900000, 1) 
                    setTimer(function () 
                        triggerEvent("ringTheBell", player) 
                    end, 5000, 1) 
                end 
            end 
        elseif tonumber(fireid) == 2 then 
            createFire(1729, -1174, 23, 60) 
            createFire(1727, -1174, 23, 60) 
            local blipicon = createBlip( 1729, -1174, 23, 43, 0, 0, 0, 255 ) 
            outputChatBox("Fire created at 1729, -1174, 23") 
            local onlinePlayers = getElementsByType("player") 
            for index, player in pairs(onlinePlayers) do 
                local x, y, z = getElementPosition(player) 
                local distance = getDistanceBetweenPoints3D(1725, -1130, 24, x, y, z)  
                if (distance <50) then 
                    setTimer(function () 
                        destroyElement(blipicon) 
                    end, 900000, 1) 
                    setTimer(function () 
                        triggerEvent("ringTheBell", player) 
                    end, 5000, 1) 
                end 
            end 
        else 
            outputChatBox("Missing ID") 
        end 
    else 
        outputChatBox("Syntax: /fdfire [id]", thePlayer) 
        outputChatBox("IDs available: 1, 2", thePlayer) 
    end 
end 
-- addCommandHandler("fdfire", fdfire) 
addEvent ( "createfdfire", true ) 
addEventHandler ( "createfdfire", getRootElement(), fdfire ) 
  
  
     

Server side:

function makeitburn (player, commandName, fdfire) 
    triggerClientEvent( "createfdfire", getRootElement(), fdfire ) 
end 
addCommandHandler ( "fdfire", makeitburn ) 

Issue is it doesn't get the numer I type (1 or 2) after /fdfire. It always outputs the syntax as if there was no number.

Link to comment
--SERVER 
function makeitburn ( player, commandName, fdfire ) 
    triggerClientEvent( "createfdfire", player, fdfire ) 
end 
addCommandHandler ( "fdfire", makeitburn ) 
     
--CLIENT 
function fdfire ( fireid ) 
    if fireid then 
        if tonumber(fireid) == 1 then 
            createFire(1700, -1168, 23, 60) 
            createFire(1698, -1168, 23, 60) 
            local blipicon = createBlip( 1700, -1168, 23, 43, 0, 0, 0, 255 ) 
            outputChatBox("Fire created at 1700, -1168, 23") 
            local onlinePlayers = getElementsByType("player") 
            for index, player in pairs(onlinePlayers) do 
                local x, y, z = getElementPosition(player) 
                local distance = getDistanceBetweenPoints3D(1725, -1130, 24, x, y, z) 
                if (distance <50) then 
                    setTimer(function () 
                        destroyElement(blipicon) 
                    end, 900000, 1) 
                    setTimer(function () 
                        triggerEvent("ringTheBell", player) 
                    end, 5000, 1) 
                end 
            end 
        elseif tonumber(fireid) == 2 then 
            createFire(1729, -1174, 23, 60) 
            createFire(1727, -1174, 23, 60) 
            local blipicon = createBlip( 1729, -1174, 23, 43, 0, 0, 0, 255 ) 
            outputChatBox("Fire created at 1729, -1174, 23") 
            local onlinePlayers = getElementsByType("player") 
            for index, player in pairs(onlinePlayers) do 
                local x, y, z = getElementPosition(player) 
                local distance = getDistanceBetweenPoints3D(1725, -1130, 24, x, y, z) 
                if (distance <50) then 
                    setTimer(function () 
                        destroyElement(blipicon) 
                    end, 900000, 1) 
                    setTimer(function () 
                        triggerEvent("ringTheBell", player) 
                    end, 5000, 1) 
                end 
            end 
        else 
            outputChatBox("Missing ID") 
        end 
    else 
        outputChatBox("Syntax: /fdfire [id]", thePlayer) 
        outputChatBox("IDs available: 1, 2", thePlayer) 
    end 
end 
-- addCommandHandler("fdfire", fdfire) 
addEvent ( "createfdfire", true ) 
addEventHandler ( "createfdfire", root, fdfire ) 

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