Jump to content

Giving weapon to a ped from client script


EvilB12

Recommended Posts

I have been trying to give weapon to a ped which i have created in a client sided script but its not working.

Server sided:-

addEvent ( "giveWeaponS", true ) 
addEventHandler("giveWeaponS", getRootElement (), function ( ped, wID, ammo ) 
    giveWeapon ( ped, tonumber ( wID ), tonumber ( ammo ), true ) 
    outputChatBox("trigger") 
    end 
) 
  

Client sided:-

addCommandHandler("ped",function () 
    ped = createPed ( 100, 2707.11621, 2219.65137, 6.74981 ) 
    triggerServerEvent ( "giveWeaponS", getLocalPlayer(), ped, 27, 500) 
    end 
) 

Link to comment

* Server Side

addCommandHandler( "ped", function (    ) 
   if ( isElement( ped ) ) then destroyElement( ped ) end 
     ped = createPed ( 100, 2707.11621, 2219.65137, 6.74981 ) 
    if ( ped ) then 
        giveWeapon ( ped, 27, 500, true ) 
    end 
end )    
Edited by Guest
Link to comment
What the hell. Why do I need to destroy the ped element, I need the ped to be seen by only one person, the one who uses the commands, why should I use that server sided code?

As i said above you can't give a 'PED' Weapon which created from the client side you can deal with that by create an object and attaching it to the PED with bone_attach script.

Link to comment

local ped = {   }; 
  
addCommandHandler( "ped", function (  player  ) 
   if ( isElement( ped[player] ) ) then destroyElement( ped[player] ) end 
      ped[player] = createPed ( 100, 2707.11621, 2219.65137, 6.74981 ) 
    if ( ped[player] ) then 
        giveWeapon ( ped[player], 27, 500, true ) 
        setElementVisibleTo ( ped[player], player, true ) 
        setElementVisibleTo ( ped[player], root, false ) 
    end 
end ) 
  
  
addEventHandler( "onPlayerQuit", root, function(  ) 
 if ( isElement( ped[source] ) ) then  
      destroyElement( ped[source] )  
      ped[source] = nil 
   end 
end ) 
Link to comment
What the hell. Why do I need to destroy the ped element, I need the ped to be seen by only one person, the one who uses the commands, why should I use that server sided code?

As i said above you can't give a 'PED' Weapon which created from the client side you can deal with that by create an object and attaching it to the PED with bone_attach script.

And if I do that, I won't be able to fire it, thats the point I am doing this, set ped's control state to fire the weapon

Link to comment
What the hell. Why do I need to destroy the ped element, I need the ped to be seen by only one person, the one who uses the commands, why should I use that server sided code?

As i said above you can't give a 'PED' Weapon which created from the client side you can deal with that by create an object and attaching it to the PED with bone_attach script.

And if I do that, I won't be able to fire it, thats the point I am doing this, set ped's control state to fire the weapon

try my code

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