Jump to content

Coding - need help with changing code


Recommended Posts

So ... I have this code and I'm pretty sure it affects all players on the server.

----------------------------------------------------------------------------------------------------------------------------------------------------------


local IsServer = GLOBAL.TheNet:GetIsServer()
local startInventory = {}


local noItems = GetModConfigData("MOONROCKS")
for i = 1, noItems, 1 do
    table.insert(startInventory,"moonrocknugget")
end

local OnPlayerSpawn = function(src, player)    
    player.prev_OnNewSpawn = player.OnNewSpawn or function() return true end
    player.OnNewSpawn = function(...)
        for _,v in pairs(startInventory) do
            local item = GLOBAL.SpawnPrefab(v)
            if(item and player.components.inventory) then
                player.components.inventory:GiveItem(item)
            end
        end            
        return player.prev_OnNewSpawn(...)
    end
end
local Init = function(inst)
   inst:ListenForEvent("ms_playerspawn", OnPlayerSpawn, inst)
end

AddPrefabPostInit("world",Init)

----------------------------------------------------------------------------------------------------------------------------------------------------------

What I want to do is make this to affect only my character. I really need help with this.

Edited by Veketh
Link to comment
Share on other sites

This code definitely affects all players, and is waaay too complicated for what you're trying to do. You should be fine by simply using the start_inv list in your player's Lua file. Is that giving you problems?

Update...

Edited by Ultroman
Link to comment
Share on other sites

You can still do that. How would you want the host to choose which starting items the character gets? A simple setting with "Easy", "Medium" and "Hard" and then have three different sets of items? Or maybe a numerical setting for a bunch of different prefabs they can start with so they can set each of them separately, e.g., 4 Cutgrass, 2 Moonrock, 0 Twigs, 8 Rocks?

Link to comment
Share on other sites

@Ultroman I guess I will not make your life miserable trying to help me, so I will just leave it as it is (just wrote a bunch of the same item in start_inv that's all). And if you are already here... do you know how to make that, the specific mob doesn't attack my character?

(I was wishing that wolves do not attack my character)

Edited by Veketh
Link to comment
Share on other sites

Just now, Veketh said:

@Ultroman I guess I will not make your life miserable trying to help me

I'm here to help, by choice. There is no gun to my head. I just want people to have a good time learning how to mod and code. Ask, and I will try to answer. It isn't hard to make the functionality I proposed in my last post.

3 minutes ago, Veketh said:

do you know how to make that, the specific mob doesn't attack my character?

(I was wishing that wolves do not attack my character)

If by "wolves" you mean the hounds which spawn at regular intervals, you can simply give your character the tag "houndfriend" AFAIK. Try it out.

Link to comment
Share on other sites

2 minutes ago, Ultroman said:

If by "wolves" you mean the hounds which spawn at regular intervals, you can simply give your character the tag "houndfriend" AFAIK. Try it out.

I am so new in coding... how can I add the tag to my character, and what if "AFAIK" ?

Link to comment
Share on other sites

AFAIK = As Far As I Know

In your character's Lua file, there should be a common_postinit function. Inside that, add the following line

inst:AddTag("houndfriend")

 

If you're very new to all of this, please read the newcomer post. It's packed with good information for newcomers. Please do the Lua Crash Course linked there, and do some more Lua tutorials for your own sake. It'll ease your entry into modding tremendously.

Link to comment
Share on other sites

You are most welcome :) Do let me know if you still want the difficulty setting thing, so I can help you do it. If you start off by learning Lua, perhaps it can be a good first modding project for you. I can try to help you without giving you too much complete code, so it can be a learning experience.

Link to comment
Share on other sites

No, you helped me enough... even gave me a site that I can learn from. If I will have more problems I will just post it like this one, but for now, I am good. Again, thank you so much

Edited by Veketh
Link to comment
Share on other sites

Sorry if I seemed pushy about helping xD It's just that your replies were the exact opposite of what I'm used to :confused: Usually, people refuse to put their nose to the ground and learn for themselves, and just ask endless questions instead of trying things out. Good for you! You'll be going places ;)

Link to comment
Share on other sites

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
 Share

×
  • Create New...