I have one SWEP on my gamemode and its purpose is to get information about an item a player equips. So when a player equips the item it can set the worldmodel and holdtype of the primary SWEP that is saved to the item. I have a function inside the SWEP, SetPrimaryInfo that is called on the server when the player equips the item. Since it is called on the server I then used a networkvar to send the information about worldmodel to the client. However for some reason after all this is done only the player that equipped the item can see the correct worldmodel.
If this seems a little confusing just tell me and I'll provide code to help show you what I'm trying to explain, thanks.
Code. We need the code to see what you did wrong.
Here's the shared.lua
[lua]
SWEP.WorldModel = "models/weapons/w_crowbar.mdl"
SWEP.HoldType = "normal"
function SWEP:Initialize()
self:SetWeaponHoldType(self.HoldType)
end
function SWEP:SetPrimaryInfo(itemInfo)
if itemInfo then
self:SetItemName(itemInfo.Name)
end
end
function SWEP:Think()
if self.weaponName != self:GetItemName() then //Both will equal nil until the name is actually networked
self.weaponName = self:GetItemName()
self.weapon = GetItem(self.weaponName)
self:SetWeaponHoldType(self.weapon.HoldType)
self.WorldModel = self.weapon.Model
end
end
function SWEP:SetupDataTables()
self:NetworkVar("String", 0, "ItemName")
end
[/lua]
This is just to show that I call on the server
[lua]
function meta:WieldPrimaryItem(item)
if self:GetActiveWeapon() then
self:StripWeapon("primary")
self:RemoveEquipment("primary")
end
self:Give("primary")
self:GetActiveWeapon():SetPrimaryInfo(item)
self:AddEquipment(item.Name, "primary")
end
[/lua]
Do a print(self.WorldModel) after you set it and see if the code was called on client ( text should be yellow ).
It prints the new model, both on the client and server.
[editline]9th December 2013[/editline]
Like when I run
[lua]
lua_run_cl print(Entity(1):GetActiveWeapon().WorldModel)
[/lua]
On the player who equipped it I get the correct model, but if I run it on the other player then I get the model that was first set in the shared.lua file(The crowbar)
Try self:SetModel()
This is really weird
[lua]
self:SetModel(self.weapon.Model)
print(self:GetModel(), self.weapon.Model)
[/lua]
Gave me this.
[lua]
models/weapons/w_crowbar.mdl models/morrowind/daedric/dai-katana/w_daedric_dai-katana.mdl
models/weapons/w_crowbar.mdl models/morrowind/daedric/dai-katana/w_daedric_dai-katana.mdl
[/lua]
Broadcasting a net message to all clients and then setting that swep's model on each client seemed to work. But when a new player joins they see the original model and sending a net message to the client when they join for every player's swep would be a lot.
Set the model on a shared file then?
I tried that already... in the SWEP's think hook I set the model and it only changed for the player using it, other players still saw the old model.
Sorry, you need to Log In to post a reply to this thread.