Giving players items on spawn?

I’m trying to figure out if there’s a way to give players items when they spawn. I’ve tried digging through the tutorials/wiki but I can’t seem to figure it out. Anyone have any scripts already pre-made or can lead me in the right direction?

Example: Player spawns in with Pistol/ammo on login/load from death.

Thanks.

4 Likes

+1 That’s a very interesting question.

You need to use the playerSpawn event, which is on the wiki. Then you can give a weapon with the natives.

@epbort My idea is that (Similar to some Arma 3 servers) a player would spawn in very high up, across several possible points in the map, with a parachute and pistol. So far I’m not making that great of progress so if anyone could contribute, that would be great.

@kanersps Thanks for the info, you pointing out where I should be looking connected some missing wires in my head. :bow: Thanks!

@ioxo If you want to spawn player across several possible points in the map (choosen by you) there is a very useful post somewhere here.
http://forum.fivereborn.com/topic/734/tutorial-change-default-spawning-locations/6
For the rest of the question I’m not able, at the moment, to help you.
Good work.

Has anyone figured out a comfortable syntax for this in Lua? I am looking to spawn players in my server with some weapons, and if possible a motorcycle next to them, every time they respawn.

AddEventHandler('playerSpawned', function(spawn)
    local player = GetPlayerPed(-1)
    local weapon = GetHashKey("weapon_snowball")

	GiveWeaponToPed(player, weapon, 10, false)

end)

Made this up real quick, this gives 10 snowballs to the player when spawning.

2 Likes

Hi !

Where can i find the list with weapon/item name/id like “weapon_snawball” ?

here; https://www.se7ensins.com/forums/threads/weapon-and-explosion-hashes-list.1045035/

i found it, thanks !

do you know how to give a gadget at player when spawn ?

Not tested, but in native I found this; SetPedGadget(ped, gadgetHash, p2)

EDIT : SetPedGadget(ped, gadgetHash, p2) only work for parachute

SetNightvision(Toggle) should set the player in nightvision mode

yes and; GetIsPedGadgetEquipped, i want to give parachute at spawn

i saw that code

AddEventHandler(‘playerSpawned’, function(spawn)
local player = GetPlayerPed(-1)
local weapon = GetHashKey(“weapon_snowball”)

GiveWeaponToPed(player, weapon, 10, false)

end)

how can i do with SetPedGadget or GetIsPedGadgetEquipped ?

SetPedGadget(GetPlayerPed(-1), 0xFBAB5776, true)

Should work, not tested (but, I think peds have parachute at spawn, press “A” on xbox controller (don’t know the keyboard key) to open it

sorry for double post…

i saw that code

AddEventHandler('playerSpawned', function(spawn)
local player = GetPlayerPed(-1)
local weapon = GetHashKey("weapon_snowball")

GiveWeaponToPed(player, weapon, 10, false)
end)

how can i do with SetPedGadget or GetIsPedGadgetEquipped ?

use “SetPedGadget” because GetIsPedGadgetEquipped is to verify if player have it or not

“Set” to give a player/ped a state or something, “Get” to verify if the player/ped are in the state/have something

ok thanks, i will try with the code posted and SetPedGadget

i tried that code

AddEventHandler('playerSpawned', function(spawn)
    local player = GetPlayerPed(-1)
    local gadget = GetHashKey("GADGET_PARACHUTE")

	SetPedGadget(player, gadget, 1, false)

end)

but not work

1 Like

how to use it:
void SET_PED_GADGET(Ped ped, Hash gadgetHash, BOOL p2)
// 0xD0D7B1E680ED4A1A 0x8A256D0A
p1/gadgetHash was always 0xFBAB5776 (“GADGET_PARACHUTE”).
p2 is always true.

1 Like

sorry i don’t understand…

can i use “AddEventHandler” and the same code like that ?

AddEventHandler('playerSpawned', function(spawn)
    local player = GetPlayerPed(-1)
    local gadget = GetHashKey("GADGET_PARACHUTE")

	SetPedGadget(player, gadget, 1, false)

end)

can you explain me more ?
where do you find these informations:

void SET_PED_GADGET(Ped ped, Hash gadgetHash, BOOL p2)
// 0xD0D7B1E680ED4A1A 0x8A256D0A
p1/gadgetHash was always 0xFBAB5776 (“GADGET_PARACHUTE”).
p2 is always true.

1 Like