Add item in pocket

hello everyone,

I have created a dark rp server and I have a problem. I create a job but I want than he has an item in him pocket when he spawn.
for that I had tried this code in the job.lua of the darkrpmodification folder:


TEAM_MAYOR = DarkRP.createJob("Seigneur Souverain De Brumia", {   color = Color(242, 139, 81, 255),
   model = {"models/player/bobert/ACRas.mdl"},
   description = [[Oh Grand Monarque, Seul et Unique Dirigeant Legitime de la Cite De Brumia, Grand Maitre De La Garde, Commandeur Du Tresor, Que Dieu veille sur Vous, et que long soit votre regne ! Cette terre est votre terrain de jeu, a votre entiere disposition: Roi absolu de droit divin? Pilleur de comptes du Royaume? Maitre adore de la population ? Vous jouez le jeu que vous voulez, avec les lois que vous voudrez. En plus de Votre salaire de base, vous pouvez charger votre tresorier de la collecte d'impots. Vous devez vous meme payer la Garde, vos domestiques, vos Gardes Royaux, et si vous le souhaitez, des mercenaires.
Plus vous payer la Garde, plus elle sera fidele; mais ils faudra charger les impots du peuple... Grand Seigneur de Brumia, Saurez-vous batir une civilisation capable de resister au passage du temps ? ]],
   weapons = {"weapon_bs_greatsword","weapon_fists","pocket"},
   command = "jobKing",
   max = 1,
   salary = 0,
   admin = 0,
   vote = false,
   hasLicense = false,
   candemote = true,
   -- CustomCheck
   medic = false,
   chief = false,
   mayor = true,
   hobo = false,
   cook = false,
   category = "Famille Royale",
   PlayerSpawn = function(ply) 
   ply:addPocketItem("mixtures_health_10hp")
   end,
PlayerDeath = function(ply, weapon, killer)
      ply:teamBan()
      ply:changeTeam(GAMEMODE.DefaultTeam, true)
      if killer:IsPlayer() then
         DarkRP.notifyAll(0, 4, "Le Roi est mort! Longue vie au Roi!")
      else
         DarkRP.notifyAll(0, 4, "Le Roi est mort! Longue vie au Roi!")
      end
   end
})

I don’t have error with this code but i have nothing in the pocket.

thank you for your help.

up

:goodjob:

Wow, try using a playerspawn hook, that’s probably the safest thing to use.

Also, addPocketItem probably doesn’t take a classname:String, it takes an entity, which you’ll need to create first. Try this

ents.Create, and come back if you’re still having problems.

I have some knowledge in other language but not in lua it’s why I make errors.

How exactly I must do with the ents.create?
I had tried that but without success:


   PlayerSpawn = function(ply)
   props = ents.Create("mixtures_health_10hp"),   
   ply:addPocketItem(props)
   end,

no error but don’t work.



props = ents.Create("mixtures_health_10hp")
props:Spawn()
ply:addPocketItem(props)


i have an error with this code :confused:

and the error is?

You need to set a position for the entity, also add a fail-safe in-case the creation wasn’t successful.

Also, just noted, you also left a random comma there, that’d probably mess your code up.

Check out the example of the wiki page above, that one spawns a 100% entity, which then you can put in the players’ pockets.

:snip:

no error finaly with the code(i make a mistake) but don’t work anyway.

Can you send us your script, please?

Pouvez-vous nous envoyer votre script, s’il vous plaît?

Puedes enviarnos tu script de lua, por favor?

El tudnád küldeni a lua scriptedet, kérlek?

[trying to get you a bit more co-operative, we are here to help, if you don’t give us info, we cannot help you and you can go on paying a developer on SF 5 bucks.]

i send the entire code for see it correctly.


TEAM_MAYOR = DarkRP.createJob("Seigneur Souverain De Brumia", {
   color = Color(242, 139, 81, 255),
   model = {"models/player/bobert/ACRas.mdl"},
   description = [[Oh Grand Monarque, Seul et Unique Dirigeant Legitime de la Cite De Brumia, Grand Maitre De La Garde, Commandeur Du Tresor, Que Dieu veille sur Vous, et que long soit votre regne ! Cette terre est votre terrain de jeu, a votre entiere disposition: Roi absolu de droit divin? Pilleur de comptes du Royaume? Maitre adore de la population ? Vous jouez le jeu que vous voulez, avec les lois que vous voudrez. En plus de Votre salaire de base, vous pouvez charger votre tresorier de la collecte d'impots. Vous devez vous meme payer la Garde, vos domestiques, vos Gardes Royaux, et si vous le souhaitez, des mercenaires.
Plus vous payer la Garde, plus elle sera fidele; mais ils faudra charger les impots du peuple... Grand Seigneur de Brumia, Saurez-vous batir une civilisation capable de resister au passage du temps ? ]],
   weapons = {"weapon_bs_greatsword","weapon_fists","pocket"},
   command = "jobKing",
   max = 1,
   salary = 0,
   admin = 0,
   vote = false,
   hasLicense = false,
   candemote = true,
   -- CustomCheck
   medic = false,
   chief = false,
   mayor = true,
   hobo = false,
   cook = false,
   category = "Famille Royale",
      PlayerSpawn = function(ply)
   props = ents.Create("mixtures_health_10hp")  
   props:Spawn()
   ply:addPocketItem(props)
   end,
PlayerDeath = function(ply, weapon, killer)
      ply:teamBan()
      ply:changeTeam(GAMEMODE.DefaultTeam, true)
      if killer:IsPlayer() then
         DarkRP.notifyAll(0, 4, "Le Roi est mort! Longue vie au Roi!")
      else
         DarkRP.notifyAll(0, 4, "Le Roi est mort! Longue vie au Roi!")
      end
   end
})

Once again, you need to set a position for the entity, you can’t just expect it to magically appear without a proper position. I’d suggest to use some fair-enough offmap position, [even if it’s just for a milisec, put it] somewhere where players can’t see it. (You can use the console command getpos in game for that.)

Also, you had better make the ‘props’ variable local.

I correct some error, change the name of the variable, add a space position.


   PlayerSpawn = function(ply)
		local couronne = ents.Create( "couronne" )
		if ( !IsValid( couronne ) ) then return end
		couronne:SetModel("models/mixtures_health/mixtures_health_10hp.mdl") 
		couronne:SetPos( Vector(-4015.780, 2185.403, 1000.281))   
		couronne:Spawn()
		ply:addPocketItem(couronne)
   end,