Need some answers to lua questions

So let me first explain what i am trying to do (note that its more of a personal practice idea :p)
So the idea was to make some sort of rpg where the stats like damage, hp, rof and such can increase and such
The thing to differentiate this from others is that players have a destroyable source of power, if its destroyed, all your stats revert to defaults until you have a new source of power

Now, i have been doing some tutorials and such. I took the bouncing ball sent as a base and wanted to go from there (the bouncing ball being the source of power for now)
The thing is, if want the player to get a menu when they press the use key on the ball. The HP adding is done server side, but derma panels are done client side, so i am kinda stuck now :frowning: any can give me some pointers?

EDIT: I have the derma frame defined in another lua file and included that one in cl_ini.lua to call the function but client does not have ENT:Use() D:

gonna ask my future questions here also so i don’t have to make multiple topics :slight_smile:

  • To increase the rate of fire, damage and such for weapons, where and how should i do this? And for player stats (HP, sprint capacity, etc…)

  • The spawnmenu should be disabled, so i guess it should be done in its own gamemode right?

this is all i got atm :slight_smile: please not that this ain’t a request or so, just for me to get on learning :smiley:
couldn’t really find these questions in this context so i hope that you at least can point me in the right direction :slight_smile:
also like i said, not going to release this (maybe i will, but at the moment not) its just a personal learning thingy :slight_smile: having goals while learning is extra motivating i think :smiley:

I see a lot of text and I’m not quite sure what’s going on here. Try just giving me one question at a time and I can help you.

Ok sorry about that :slight_smile:

First thing is

How can i make a SENT (i used the bouncing ball sent as base) to open a menu when used?

You need to send a usermessage to the activator telling them to open the menu. You could even make it so that when a player uses your SENT it calls a clientside version of the ENT:Use function.

server
[lua]function ENT:Use(act, cal)
if ValidEntity(act) and act:IsPlayer() then
umsg.Start(“sent use”, act)
umsg.Entity(self)
umsg.End()
end
end[/lua]

client
[lua]usermessage.Hook(“sent use”, function(um)
local ent = um:ReadEntity()
if ValidEntity(ent) and ent.Use then
ent:Use()
end
end)

function ENT:Use() – client side ENT.Use
– Open your menu here
end[/lua]

You should set the entities use type to SIMPLE_USE.

But the client doesn’t have a hook for use (according to the documentation)
i even tried it :stuck_out_tongue:
[lua]function ENT:Use()
FrameOpen()
end

function FrameOpen()
local f1 = vgui.Create(“DFrame”)
f1:SetPos(100, 100)
f1:SetSize(200, 200)
f1:SetTitle(“Test”)
f1:MakePopup()
end[/lua]
Note that i had a function called Frame() in frame.lua but i changed it to this for the sake of testing

also i thought the lua tags where [ lua ][ /lua ] right?

I know they don’t. The code I provided allows you to use ENT.Use on the client.

oooh i see, i will try that :slight_smile: sorry about sounding like a smart ass then :stuck_out_tongue:

EDIT: awesome, it works :smiley:

Now for my next question (Entoros said i needed to split them up :p)
How can i apply “mods” to players and weapons? so to increase their hp, sprint capacity, jump height, etc… and weapon rate of fire, power (like defaultdmg * 1.05) clipsize and so on. If that even is possible
Should definitely work on the default HL2 weapons and on my own sweps, if possible a method to make it “community proof” so any swep should work.
Not asking for solution here btw (because it sounds like i am) just help :3 so pointers in the right direction are awesome to :smiley:

It all really depends on what you want to do.

If you want to increase HP, you use **[Entity.SetHealth

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Entity.SetHealth)**.
If you want to make them run faster, you use **[Player.SetRunSpeed

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Player.SetRunSpeed)**.
If you want to increase jump height, you use **[Player.SetJumpPower

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Player.SetJumpPower)**.
If you want to affect the damage someone takes, you use **[Gamemode.EntityTakeDamage

http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=Gamemode.EntityTakeDamage)**.

If you want to directly modify a default SWEP, that’s a wee bit more difficult and something I haven’t messed around with. You’re better off just making a custom SWEP with the modifications you want.

Those are the things i need indeed :slight_smile:

about the weapon damage
thought so. Well more practice for me :smiley:
but how should i go about doing that?
the idea was to have damage multipliers. So when you “level up” you can add points to that.
In other words, where do i store that for each player?

(you are all being most helpful btw :slight_smile: learning allot)

A very useful function for saving data unique to each player is **[Player.SetPData

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Player.SetPData)**. For example,

[lua]hook.Add(“PlayerInitialSpawn”,“Stuff”,function(pl)
pl:ChatPrint("Welcome, " … pl:Name() … "! Your current level is " … pl:GetPData(“Level”) … “.”)
end)
[/lua]

And applied to EntityTakeDamage,

[lua]
hook.Add(“EntityTakeDamage”,“Stuff”,function(ent,inflict,attack,amt,dmg)
if attack:IsPlayer() then
dmg:ScaleDamage( math.Clamp( tonumber(attack:GetPData(“Level”)), 1 ) )
end
end)[/lua]

Does that make sense?

That is a handy function :smiley: But where is the data saved? Or is the script supposed to write to a database now and then?
And i think this should have to be done in a game mode right?
But it isn’t possible to let it “communicate” with the swep? (it won’t be spawnable since i am going to disable the spawn menu anyway)
for example, in the SWEP code you have a multiplier var. So you can set dmg mod on a per weapon base…Maybe thats a bit to far.

Every server and client has a “sv.db” file, which is where Garry’s Mod stores these datas. You don’t need to worry about that - just know that the PData is saved automatically whenever you set it to something.
And no, it doesn’t have to be done in a gamemode. It can be a standalone script.
A unique name is just used to distinguish it from other hooks of the same type, which makes it easy for the engine to handle them and for us to remove them. Generally you would name it something more specific than “Stuff”, but this was just an example. Note: you can have the same unique name for different kinds of hooks, but not for the same kind of hook.

ok, i got a simple derma panel up to set the speed.
but how do i transfer that value from the client to the server? (or tell the server it has been increased/decreased
i suppose it has to be done with usermessages, but i don’t get them completely

i kinda get MakeR’s example, i think
(from his example couple posts back):
you send a message called “sent use” to the client
at the client you hook the usermessage system and if the message was “use sent” it does stuff (opening the menu in this case)
so to get the change from the client to the server you just turn it around: send a usermessage to the server
right?
but where does this message gets received? Just in a lua file included in init.lua? in init.lua itself?

Force a console command for client->server

You can’t send usermessages from the client to the server, you need to do what Disseminate said and use console commands.

so define a console command on the server and the client tells the server to execute it?
how would i do that? i tought clients should have no controll over server operating things (generaly speaking then)

I have looked all over the wiki but i cannot find a function to force a server console command D:

(side note: to add the server console command, thats just the same as on the client right?)

EDIT: sorry about the double post D: noticed it to late