Jump to content

Server-side Event not triggering


Elmatus

Recommended Posts

The event is triggered if I only send one argument, "theShooter". I added the argument "object", ensuring is not nil. But the server event is not triggered after that

Any help is aprecciated

Client (Relevant: line 34-40)

function ObjectShot ( theShooter, weapon, ammo, ammoInClip, hitX, hitY, hitZ, hitElement ) 
  
  
    shooterX, shooterY, shooterZ = getElementPosition (theShooter) 
    targetDistance = getDistanceBetweenPoints3D ( shooterX, shooterY, shooterZ, hitX, hitY, hitZ ) 
     
     
     
     
     
    local startX, startY, startZ = getPointInFrontOfPlayer(theShooter, 1.5 ) 
    local rx,ry,rz = math.random(360),  math.random(360),  math.random(360) 
    startZ = startZ - 0.5 
  
    if isPedInVehicle(theShooter) == true or isBadWeapon(weapon) == true then 
     
    else 
        -- does object exist destroy if it did 
        if shells.object.obj[shells.object.shotCount] ~= nil then 
            if isElement(shells.object.obj[shells.object.shotCount])  then 
                destroyElement(shells.object.obj[shells.object.shotCount]) 
            end 
            shells.object.obj[shells.object.shotCount] = nil 
        end 
         
        shells.object.obj[shells.object.shotCount] = createObject(321, startX, startY, startZ)   
        setObjectScale ( shells.object.obj[shells.object.shotCount], 5) 
  
        moveObject ( shells.object.obj[shells.object.shotCount], targetDistance*10, hitX, hitY, hitZ, rx, ry, rz ) 
  
        outputChatBox ("Count: shells.object.obj" .. tostring(shells.object.shotCount) .. " objects") 
  
  
  
        if (shells.object.obj[shells.object.shotCount]) then 
            triggerServerEvent( "onSpecialEvent", resourceRoot, theShooter, shells.object.obj[shells.object.shotCount] ) 
            outputChatBox ("Sending to server-side") 
        else 
            outputChatBox ("Object does not exist") 
        end 
  
  
    end 
  
end 

Server:

addEvent ( "onSpecialEvent",true) 
function objectExplosion (theShooter, object) 
    outputChatBox ( "Player " .. getPlayerName(theShooter) .. " triggered object shoot " ) 
  
    if ( (targetDistance*10) < 50) then 
        createExplosion ( hitX, hitY, hitZ, 2, theShooter) 
        destroyElement (object) 
    else 
        setTimer ( function() 
            createExplosion ( hitX, hitY, hitZ, 2, theShooter ) 
            destroyElement(object) 
        end, targetDistance*10, 1 ) 
     end 
  
end 
  
addEventHandler ( "onSpecialEvent", getRootElement(), objectExplosion ) 

Edited by Guest
Link to comment

You need to use addEvent for your own events.

function objectExplosion (theShooter, object) 
    outputChatBox ( "Player " .. getPlayerName(theShooter) .. " triggered object shoot " ) 
  
    if ( (targetDistance*10) < 50) then 
        createExplosion ( hitX, hitY, hitZ, 2, theShooter) 
        destroyElement (object) 
    else 
        setTimer ( function() 
            createExplosion ( hitX, hitY, hitZ, 2, theShooter ) 
            destroyElement(object) 
        end, targetDistance*10, 1 ) 
     end 
  
end 
addEvent ( "onSpecialEvent", true ); 
addEventHandler ( "onSpecialEvent", getRootElement(), objectExplosion ) 

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