Sign in to follow this  
CanTotu

Porting a mod to DST

Recommended Posts

CanTotu    5

Well I'm trying to port a mod to Dst. I know that I need to change GetPlayer() to the ThePlayer because there are now lots of players rather than one. However, there is a part of code like:

function Inventory:GuaranteeItems(items)    self.inst:DoTaskInTime(0,function()                for k,v in pairs(items) do            local item = v                        if self:Has(item, 1) then                for k,v in pairs(Ents) do                    if v.prefab == item and v.components.inventoryitem:GetGrandOwner() ~= GetPlayer() then                        v:Remove()                    end                end            else                for k,v in pairs(Ents) do                    if v.prefab == item then                        item = nil                        break                    end                end                if item then                    self:GiveItem(SpawnPrefab(item))                end            end        end    end)end

So should I just change it like

if v.prefab == item and v.components.inventoryitem:GetGrandOwner() ~= ThePlayer then

How would be effective such a way?

Share this post


Link to post
Share on other sites
Seiai    56

iam not sure what u are trying to do, but if u are just trying to give your character a starting inventory, u can actually just pass a table with the itemprefabs in the makeplayercharacter-function for that. (see willow's code for example.)

else u have to be aware, that ThePlayer always references the player of where the code is executed, and i guess your could will always be executed on the server, so i guess ThePlayer in your code will always refer to the host.

Edited by Seiai

Share this post


Link to post
Share on other sites
CanTotu    5

iam not sure what u are trying to do, but if u are just trying to give your character a starting inventory, u can actually just pass a table with the itemprefabs in the makeplayercharacter-function for that. (see willow's code for example.)

else u have to be aware, that ThePlayer always references the player of where the code is executed, and i guess your could will always be executed on the server, so i guess ThePlayer in your code will always refer to the host.

 

 

I'm trying to port 'vending machine' mod to DST. And ThePlayer must refer to the player interact with machine prefab

Edited by CanTotu

Share this post


Link to post
Share on other sites
Seiai    56

@CanTotu,

from what i have seen, it looks like it's an UI Widget. the UI Widget will get called on the Client, but u receiving the item has to take place on the server. i dont know if u have looked into that already, but u will have to use RPC(remote procedure calls).

http://forums.kleientertainment.com/topic/47353-guide-getting-started-with-modding-dst-and-some-general-tips-for-ds-as-well/

here's an example for one, the hotkey happens on the client and the spawning of the spider and everything related on the server: http://forums.kleientertainment.com/topic/54536-help-with-a-mod-spider-summoning/

u can also add additional parameters to SendModRPCToServer(probably the name of the item u wanna buy), which will get passed to the function, that the RPCHandler calls, along with the player who sent the RPC.

 

edit: i just downloaded your mod on DS, it seems u have made a copy of the WHOLE inventory component in your veminventory.lua. DST has a very reworked inventory component, and u shouldn't overwrite the whole thing anyway, u should just overwrite the functions that need to be changed. Reworking that mod for DST is gonna be some work^^

are u the original author? if not, u will probably have a lot of trouble understanding why he did certain things like copying the whole inventorycomponent, making it even harder to port it...

 

 

Edited by Seiai

Share this post


Link to post
Share on other sites
CanTotu    5

@CanTotu,

from what i have seen, it looks like it's an UI Widget. the UI Widget will get called on the Client, but u receiving the item has to take place on the server. i dont know if u have looked into that already, but u will have to use RPC(remote procedure calls).

http://forums.kleientertainment.com/topic/47353-guide-getting-started-with-modding-dst-and-some-general-tips-for-ds-as-well/

here's an example for one, the hotkey happens on the client and the spawning of the spider and everything related on the server: http://forums.kleientertainment.com/topic/54536-help-with-a-mod-spider-summoning/

u can also add additional parameters to SendModRPCToServer(probably the name of the item u wanna buy), which will get passed to the function, that the RPCHandler calls, along with the player who sent the RPC.

 

edit: i just downloaded your mod on DS, it seems u have made a copy of the WHOLE inventory component in your veminventory.lua. DST has a very reworked inventory component, and u shouldn't overwrite the whole thing anyway, u should just overwrite the functions that need to be changed. Reworking that mod for DST is gonna be some work^^

are u the original author? if not, u will probably have a lot of trouble understanding why he did certain things like copying the whole inventorycomponent, making it even harder to port it...

 

Thank you for information. I'm not the original author I really wish that original author port his mod DST, which I really need in my server. Since I'm very new to this modding stuff, I'm trying to learn these things by trying to copy the codes and edit them.

Share this post


Link to post
Share on other sites
Seiai    56

@CanTotu

i suggest u try to create a simple DST-mod of your own, with something clickable on the UI, to learn how it all works, and maybe then try porting the vendingmachine one (or probably just remake it yourself, since u will most likely realize it's easier^^).

Share this post


Link to post
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
Sign in to follow this