Hi, I'm working on an addon and I'm trying to figure something out... how do you make it so that a derma DTextEntry adds to a data for only one player? I'm making a hitmenu and I can't figure out how to let people add hits, all I have now is the derma menu with the list of players hooked with a chat command. THanks!
You can save data to the player object by doing things such as
[lua]ply.data = "Data"[/lua]
This will be removed once the player object has been i.e disconnecting or server restarting.
In case you don't know the above
[code]
ply.data
[/code]
Is a table on the player (ply) with an index of "data" so
[code]
ply["data"]
[/code]
Is the same thing.
I'm confused since I just started learning lua as my first real language (Scratch and html don't count) - how do I apply this?
What are you exactly doing.
Making a menu where you can place hits. Want a pastebin of the code so far?
i'm not sure how to better explain this you asked for a method of saving data temporarily for the player and I gave it, what exactly don't you understand?
How to implement it.
[QUOTE=Pazda;40049813]How to implement it.[/QUOTE]
What feature exactly are you trying to make and don't just say a hitman system, I want to know what data you want to be saved and what you will use it for.
The hits themselves. I have a DListView with DoDoubleClick that opens up a DTextEntry. I want this to let players enter a number, and that adds to the target player's hit what they entered.
[QUOTE=Pazda;40050160]The hits themselves. I have a DListView with DoDoubleClick that opens up a DTextEntry. I want this to let players enter a number, and that adds to the target player's hit what they entered.[/QUOTE]
So just save the value to the of the hit like so
[lua]ply.HitValue = 100 [/lua]
This would of course be saved on the server and networked to the client if they ever need to know the value of a hit, I would then use the hook PlayerDeath to check when a player is killed if the HitValue is set to anything. Now all you need to do is pay the killer and reset the hit value back to nil so they no longer have a hit on them.
Yeah, that second part would be easy. Would it really just be
[CODE]HittText.OnEnter = function()
ply.HitValue = 100
DermaPanel:SetVisible( false )
end
[/CODE]
or would I need something else? Yeah, yeah, I know I'm really bad at lua, I'm trying to learn and this is my first big script.
[QUOTE=Pazda;40050530]Yeah, that second part would be easy. Would it really just be
[CODE]HittText.OnEnter = function()
ply.HitValue = 100
DermaPanel:SetVisible( false )
end
[/CODE]
or would I need something else? Yeah, yeah, I know I'm really bad at lua, I'm trying to learn and this is my first big script.[/QUOTE]
You need that value on the server not the client I suggest using a console command to send the hit value to the server along with the player you want to put a hit on
Ahh, this is so confusing to me, how would I go about doing that?
[QUOTE=Pazda;40050621]Ahh, this is so confusing to me, how would I go about doing that?[/QUOTE]
You want to make a console command on the server look at [url]http://wiki.garrysmod.com/page/concommand/Add[/url]
Then on the client use
[url]http://wiki.garrysmod.com/page/Global/RunConsoleCommand[/url]
to call the console command you will want to pass two arguments an identifier like unique ID to work out who has the hit on them and the value of the hit
Arguments are confusing to me and I've never found a good tutorial on them, do you know any helpful pages for that? Also, what does v: mean and how do I use it? I found it in the tutorial for the loop tutorial.
[QUOTE=Pazda;40050744]Arguments are confusing to me and I've never found a good tutorial on them, do you know any helpful pages for that?[/QUOTE]
Might be worth giving this a read [url]http://www.lua.org/pil/5.html[/url] should teach you all about functions and that should give you a good overview of arguments, it is really quite simple.
So on the server file would this work?
[CODE]function HitComnd( v, amt )
v:bounty = amt
end
concommand.Add( "setbty", v, amt, HitComnd )
[/CODE]
Also, this is kinda unrelated but I'm making it so you can buy ranks in pointshop. When you buy one of them, you get the money but not the ULX rank. Any idea why this is going on? Thanks!
[CODE]function ITEM:OnBuy( ply )
game.ConsoleCommand( "ulx adduserid "..ply:SteamID().." admin")
ply:AddMoney( 100000 )
end[/CODE]
[QUOTE=Pazda;40050880]So on the server file would this work?
[CODE]function HitComnd( v, amt )
v:bounty = amt
end
concommand.Add( "setbty", v, amt, HitComnd )
[/CODE][/QUOTE]
This is wrong look at this page again [url]http://wiki.garrysmod.com/page/concommand/Add[/url]
HitComnd will have args like so
[lua]function HitComnd( ply,cmd,args,str )[/lua]
if you don't understand what each one is I suggest printing the values to console to help you understand
[QUOTE=Shenesis;40058490]Add \n at the end of the command.[/QUOTE]
In the parentheses?
[QUOTE=Pazda;40065361]In the parentheses?[/QUOTE]
yes
[QUOTE=jack10685;40065602]yes[/QUOTE]
Wouldn't be in the quotes so that the \n (new line) is registered by console?
Wiki has:
[code]
game.ConsoleCommand( "sv_gravity 400\n" )
[/code]
[QUOTE=Pandaman09;40066001]Wouldn't be in the quotes so that the \n (new line) is registered by console?
Wiki has:
[code]
game.ConsoleCommand( "sv_gravity 400\n" )
[/code][/QUOTE]
the wiki is correct, /n must be inside quotes, it basically is like pressing enter after you type a command.
Garry's Mod has two sides [I](this is a lie but for now this is all you need to know)[/I] [b]server[/b], and [b]client[/b]. The client cannot directly effect what happens to other clients without the server- e.g. if I run Player(y):Kill() on my client it will not work because if you check on the wiki, Player.Kill is a serverside function meaning you cannot run it on a client.
You want to make a hit system- I don't know the exact specifications of what you want but here is generally what you would want.
Player 1 places a hit via the menu.
When the button to place the hit is clicked it sends a console command to the server.
The server listens to the console command and locates which player the client is looking for.
Once the target has been located you save a variable to that player such as HitAmount or whatever.
Send the hit to all hitmen announcing that the player is to be killed.
Listen for player deaths and check if the player that died had a hit on them, and then remove the variable / give hitman money or whatever.
When listening to events, you use a hook. You can find a list of hooks under GM on the wiki.
To send data to the server use [URL="http://wiki.garrysmod.com/page/Global/RunConsoleCommand"]RunConsoleCommand [/URL]on the client.
To send data to the client(s) [I](for this purpose)[/I] use usermessages.
Sorry, you need to Log In to post a reply to this thread.