Command when spawning players

Simple, short question:

I want to implement the feature so when somebody spawns on the server he automatically writes a command in the chat. (Its for spawning a special environment for polo_drugs clientside).
Since I cant code can anyone give me a codeline in Luascript for that?

Thank you 100 times in advance!

So from what I understand you want a command to be executed by the client when he spawns after join?

Correct! Context is that the druglabor is empty by default and each player can customize the labor with a command for example: /weed_v5 , which spawns the plants and stuff. I want to spawn this by default so the players dont have to.

Well if it is command based you can easily use ExecuteCommand native on player spawn.

Well thanks i guess. Still no clue how to write it in code tho…

Should you be developing a server if you can’t implement a native function?

Well… I want to so yes. So far I am doing pretty well without any knowledge of coding.

Copy and pasting is not doing well, you need to learn to do things for yourself sometimes :man_shrugging:
You can’t expect things to be spoonfed to you, this is just a single native function within the OnPlayerSpawned event handler.

So putting a bunch of scripts together is “developing”? Also you say if I dont know how stuff is done I should not try and learn it? My friend if everyone would be like this, we wouldnt be about to fly to mars!

Dude lets not discuss this further pls I just want it to work.

AddEventHandler(‘playerSpawned’)

Citizen.Wait(1000)

TriggerEvent(ExecuteCommand(

    commandString "weed_basic"),

TriggerEvent(ExecuteCommand(

    commandString "weed_v6")

   

)

end)

I just wrote this, is this what you wanted? Can you at least tell me if this is somewhat a code or just a mess?

Well you have couple of mistakes.

  1. Using natives has nothing to do with events.
  2. commandString is just a example of what value you should pass in the native.
  3. There are different types of values. (string, float, int, bool etc.)

In the particular case we need a string to be passed.

Example of how you should use this native.

ExecuteCommand(“weed_v6”)

Try to figure out everything else yourself. It is easy. Google is your best friend in case you find it hard.

1 Like

Well thanks for the advice!
According to your input it should look like this?

AddEventHandler(‘playerSpawned’)

Citizen.Wait(5000)

ExecuteCommand(“weed_v6”)

end)

If you want it to execute the command only once (on first spawn), it would look something like this:

firstSpawn = true
AddEventHandler("playerSpawned", function()
 if firstSpawn == true then 
  ExecuteCommand("weed_v6")
  firstSpawn = false
 end
end)

If I remember correctly, you also have to give this resource permission to execute commands. I might be wrong on this because I haven’t used the executecommand native in a while. Anyway, google is your best friend.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.