Jump to content

Help.


manve1

Recommended Posts

Posted

I have a simple problem, the script outputs 4 messages instead of 2 and gives the player twice as much of stuff then he should get

Client:

addEvent('anims', true) 
addEventHandler('anims', getRootElement(), 
function( ) 
if isElement(localPlayer) then 
setPedAnimation( localPlayer, 'CARRY', 'liftup' ) 
triggerServerEvent('weapons"n"money', localPlayer) 
else return false 
end 
end 
) 
  
addEvent('anims2', true) 
addEventHandler('anims2', getRootElement(), 
function( ) 
if isElement(localPlayer) then 
setPedAnimation( localPlayer, false ) 
else return false 
end 
end 
) 

Server:

addEventHandler('onColShapeHit', col1, 
function( hitElement ) 
setTimer( 
function( ) 
triggerClientEvent('anims', hitElement, hitElement) 
if isElement(col1) then 
destroyElement( col1 ) 
end 
setTimer( 
function( ) 
triggerClientEvent('anims2', hitElement, hitElement) 
if isElement( box1 ) then 
destroyElement( box1 ) 
end 
end, 1500, 1 
) 
end, 50, 1 
) 
end 
) 
-- 
addEventHandler('onColShapeHit', col2, 
function( hitElement ) 
setTimer( 
function( ) 
triggerClientEvent('anims', hitElement, hitElement) 
if isElement(col2) then 
destroyElement( col2 ) 
end 
setTimer( 
function( ) 
triggerClientEvent('anims2', hitElement, hitElement) 
if isElement( box2 ) then 
destroyElement( box2 ) 
end 
end, 1500, 1 
) 
end, 50, 1 
) 
end 
) 
  
addEvent('weapons"n"money', true) 
addEventHandler('weapons"n"money', getRootElement(), 
function() 
local money = math.random( 10, 30000 ) 
local weapon = math.random( 1, 35 ) 
local ammo = math.random( 1, 1000 ) 
giveWeapon( source, weapon, ammo ) 
givePlayerMoney( source, money ) 
if (weapon == 1) then 
outputChatBox( '#FF0000Santa: #FFFFFFYou got '.. money ..'$ and Brassknucles.', source, 255, 255, 255, true )  
outputChatBox( '#FF0000Santa: #FFFFFF'.. getPlayerName( source ) ..' Found a Christmas Present and got: '.. money ..'$ and Brassknucles.', root, 255, 255, 255, true )  
elseif (weapon == 2) then 
outputChatBox( '#FF0000Santa: #FFFFFF'.. getPlayerName( source ) ..' Found a Christmas Present and got: '.. money ..'$ and Golf club.', root, 255, 255, 255, true ) 
outputChatBox( '#FF0000Santa: #FFFFFFYou got '.. money ..'$, Golf Club.', source, 255, 255, 255, true )  
elseif (weapon == 3) then 
outputChatBox( '#FF0000Santa: #FFFFFFYou got '.. money ..'$, Nightstick.', source, 255, 255, 255, true )  
outputChatBox( '#FF0000Santa: #FFFFFF'.. getPlayerName( source ) ..' Found a Christmas Present and got: '.. money ..'$ and NightStick.', root, 255, 255, 255, true ) 
elseif (weapon == 4) then 
outputChatBox( '#FF0000Santa: #FFFFFFYou got '.. money ..'$, Knife.', source, 255, 255, 255, true )  
outputChatBox( '#FF0000Santa: #FFFFFF'.. getPlayerName( source ) ..' Found a Christmas Present and got: '.. money ..'$ and Knife.', root, 255, 255, 255, true ) 
end 
end 
) 

NOTE: everything is defined

Posted

I don't understand what's your point , please explain better , what's your problem in this code?

also no need for this

if isElement(localPlayer) then 

Posted

Well, it repeats the script which gives player: money, ammo and weapon for as much time's as there is people online.

P.S. This is only a short piece which should have the bug

Posted
no everything looks fine, 1 trigger, 1 event, 1 event handler

Do you want to trigger 'anims' and 'anims2' events for every player on the server or just for one player (who entered the colshape). For one player use:

triggerClientEvent(hitElement,'anims',hitElement) 

And you should check in both events, that hitElement is a player and not a vehicle or something else.

Posted
it didn't work. No animation and nothing given to person who hit it

It should work if you use it good. It's working for me, I just changed the two events on server-side:

addEventHandler('onColShapeHit', col1, 
    function( hitElement ) 
        if getElementType(hitElement) == "player" then 
            setTimer( 
                function( ) 
                    triggerClientEvent(hitElement,'anims',  hitElement) 
                    if isElement(col1) then 
                        destroyElement( col1 ) 
                    end 
                setTimer( 
                    function( ) 
                        triggerClientEvent(hitElement,'anims2',  hitElement) 
                        if isElement( box1 ) then 
                            destroyElement( box1 ) 
                        end 
                    end, 1500, 1 
                ) 
                end, 50, 1 
            ) 
        end 
    end 
) 
-- 
addEventHandler('onColShapeHit', col2, 
    function( hitElement ) 
        if getElementType(hitElement) == "player" then 
            setTimer( 
                function( ) 
                    triggerClientEvent(hitElement,'anims',  hitElement) 
                    if isElement(col2) then 
                        destroyElement( col2 ) 
                    end 
                setTimer( 
                    function( ) 
                        triggerClientEvent(hitElement,'anims2',  hitElement) 
                        if isElement( box2 ) then 
                            destroyElement( box2 ) 
                        end 
                    end, 1500, 1 
                ) 
                end, 50, 1 
            ) 
        end 
    end 
) 

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