Jump to content

[Help] attachMusic


Recommended Posts

function createSpeaker(thePlayer) 
    local x, y, z = getElementPosition(thePlayer) 
    speakerObject = createObject(2229, x, y, z-1) 
    outputChatBox("You have Succesfully created a speaker!", thePlayer, 0, 250, 0) 
    if (isPedInVehicle(thePlayer)) then 
        local vehicle = getPedOccupiedVehicle(thePlayer) 
        attachElements(speakerObject, vehicle) 
        triggerClientEvent(root, "playTheSound", root, x, y, z, vehicle) 
    else 
        triggerClientEvent(root, "playTheSound", root, x, y, z) 
    end 
end 
addCommandHandler("ps", createSpeaker) 
  
function deleteSpeaker(thePlayer) 
    if (isElement(speakerObject)) then 
        destroyElement(speakerObject) 
        outputChatBox("You have Succesfully destroyed the Speaker!", thePlayer, 0, 0, 255) 
                triggerClientEvent("stopTheSound", root) 
    else 
        outputChatBox("Speaker is not created!", thePlayer, 250, 0, 0) 
    end 
end 
addCommandHandler("ds", deleteSpeaker) 

how to make this commands only for Admins?

Link to comment

If you want to check all that on server-side, then only use these.

Server-side

isObjectInACLGroup 
getPlayerAccount 
getAccountName 

But if you also want to check it client-side, then use these.

Server-side

isObjectInACLGroup 
getPlayerAccount 
getAccountName 
getElementData 

Client-side

getElementData 

Link to comment

ok i will post it but don't laugh on me :D i try to put it in all lines :D

function createSpeaker(thePlayer) 
    local x, y, z = getElementPosition(thePlayer) 
    speakerObject = createObject(2229, x, y, z-1) 
          local acc = getAccountName(getPlayerAccount(player)) 
          if isObjectInACLGroup("user."..acc, aclGetGroup("Admin")) then 
    outputChatBox("You have Succesfully created a speaker!", thePlayer, 0, 250, 0) 
    if (isPedInVehicle(thePlayer)) then 
        local vehicle = getPedOccupiedVehicle(thePlayer) 
        attachElements(speakerObject, vehicle) 
        triggerClientEvent(root, "playTheSound", root, x, y, z, vehicle) 
    else 
        triggerClientEvent(root, "playTheSound", root, x, y, z) 
    end 
end 
addCommandHandler("ps", createSpeaker) 
  
function deleteSpeaker(thePlayer) 
    if (isElement(speakerObject)) then 
        destroyElement(speakerObject) 
        outputChatBox("You have Succesfully destroyed the Speaker!", thePlayer, 0, 0, 255) 
                triggerClientEvent("stopTheSound", root) 
    else 
        outputChatBox("Speaker is not created!", thePlayer, 250, 0, 0) 
    end 
end 
addCommandHandler("ds", deleteSpeaker) 

Link to comment
ok i will post it but don't laugh on me :D i try to put it in all lines :D
function createSpeaker(thePlayer) 
    local x, y, z = getElementPosition(thePlayer) 
    speakerObject = createObject(2229, x, y, z-1) 
          local acc = getAccountName(getPlayerAccount(player)) 
          if isObjectInACLGroup("user."..acc, aclGetGroup("Admin")) then 
    outputChatBox("You have Succesfully created a speaker!", thePlayer, 0, 250, 0) 
    if (isPedInVehicle(thePlayer)) then 
        local vehicle = getPedOccupiedVehicle(thePlayer) 
        attachElements(speakerObject, vehicle) 
        triggerClientEvent(root, "playTheSound", root, x, y, z, vehicle) 
    else 
        triggerClientEvent(root, "playTheSound", root, x, y, z) 
    end 
end 
addCommandHandler("ps", createSpeaker) 
  
function deleteSpeaker(thePlayer) 
    if (isElement(speakerObject)) then 
        destroyElement(speakerObject) 
        outputChatBox("You have Succesfully destroyed the Speaker!", thePlayer, 0, 0, 255) 
                triggerClientEvent("stopTheSound", root) 
    else 
        outputChatBox("Speaker is not created!", thePlayer, 250, 0, 0) 
    end 
end 
addCommandHandler("ds", deleteSpeaker) 

What errors do you have?

EDIT : You forgot to add "end" for function createSpeaker

Edited by Guest
Link to comment
function createSpeaker(thePlayer) 
    local x, y, z = getElementPosition(thePlayer) 
    speakerObject = createObject(2229, x, y, z-1) 
          local acc = getAccountName(getPlayerAccount(thePlayer)) 
          if isObjectInACLGroup("user."..acc, aclGetGroup("Admin")) then 
    outputChatBox("You have Succesfully created a speaker!", thePlayer, 0, 250, 0) 
    if (isPedInVehicle(thePlayer)) then 
        local vehicle = getPedOccupiedVehicle(thePlayer) 
        attachElements(speakerObject, vehicle) 
        triggerClientEvent(root, "playTheSound", root, x, y, z, vehicle) 
    else 
        triggerClientEvent(root, "playTheSound", root, x, y, z) 
    end 
end 
addCommandHandler("ps", createSpeaker) 
  
function deleteSpeaker(thePlayer) 
    if (isElement(speakerObject)) then 
        destroyElement(speakerObject) 
        outputChatBox("You have Succesfully destroyed the Speaker!", thePlayer, 0, 0, 255) 
                triggerClientEvent("stopTheSound", root) 
    else 
        outputChatBox("Speaker is not created!", thePlayer, 250, 0, 0) 
    end 
end 
addCommandHandler("ds", deleteSpeaker) 

like this?

Link to comment
in what line?
    function createSpeaker(thePlayer) 
        local x, y, z = getElementPosition(thePlayer) 
        speakerObject = createObject(2229, x, y, z-1) 
              local acc = getAccountName(getPlayerAccount(thePlayer)) 
              if isObjectInACLGroup("user."..acc, aclGetGroup("Admin")) then 
        outputChatBox("You have Succesfully created a speaker!", thePlayer, 0, 250, 0) 
        if (isPedInVehicle(thePlayer)) then 
            local vehicle = getPedOccupiedVehicle(thePlayer) 
            attachElements(speakerObject, vehicle) 
            triggerClientEvent(root, "playTheSound", root, x, y, z, vehicle) 
        else 
            triggerClientEvent(root, "playTheSound", root, x, y, z) 
        end 
    end 
    end 
    addCommandHandler("ps", createSpeaker) 
      
    function deleteSpeaker(thePlayer) 
        if (isElement(speakerObject)) then 
            destroyElement(speakerObject) 
            outputChatBox("You have Succesfully destroyed the Speaker!", thePlayer, 0, 0, 255) 
                    triggerClientEvent("stopTheSound", root) 
        else 
            outputChatBox("Speaker is not created!", thePlayer, 250, 0, 0) 
        end 
    end 
    addCommandHandler("ds", deleteSpeaker) 

added it for you

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