• How would I make a /hit command, and a saving inventory?
    24 replies, posted
Okay, before you go ranting on me, PLEASE, read this. I DONT WANT YOU TO SCRIPT IT. COULD YOU PLEASE TELL ME WHAT I WOULD USE? NETWORK VARS, DATASTREAM STUFF LIKE THAT TO BUILD THE SCRIPT. I'D ACTUALLY LIKE TO LEARN THIS TIME. SO HERE ARE MY IDEAS. A /hit command that a player would give to the hitman (eg. Me, a player, /hit bob, and the hitman would get the hit and a payment of 'x' dollars. There has to be a hitman to use this command.), that you must use in-order to kill someone in RP, and if you don't kill someone that has a hit, than you'll get automatically demoted. This is in DarkRP. Now second request, a saving inventory that saves after you relog. So, it'd just be the regular darkrp pocket, except stuff save. Whoever will troll me, go ahead. I'll get alot of hate, but I'd like to learn lua, and these scripts i'd like to script on my own, and I have passion to do it. Also, if someone could add me on Steam, just to walk me through, i'd appreciate it. Lol, i'd also like to request stamina bars for running, and flashlight. All in HUD, how would I go on doing that? THANKS! <3
For the first, record the steam/unique ID for the player from the provided name. Store this in a table with the hitmans steam/unique ID. Use a hook to check for both killer and killed, and if the killer is a hitman and the killed is the person to hit, do whatever. If not, de-rank them. As for the second... I'd guess the current pocket has some kind of order. I don't know so much for this one, such as storage method and/or hooks to load and save in. I'll leave it to someone else.
So I'd have to create tables correct? And in these tables the Steam ID of the person who called the hit would be recorded, as well as the hitman's Steam ID, correct? Hook's i'll have to look into. Hm, thinking about it the tables I wouldn't need for the hitman, since I could do if t == "team_hitman" then, but here's my question im bummed out on. How do you record who's killed, and record STEAM ID's?
Stamina is pretty simple. Just do it like this: (Shared) [lua] function StaminaKeyPress( ply, key ) if key == IN_SPEED then timer.Destroy( LocalPlayer( ):UniqueID( ) ) timer.Create( LocalPlayer( ):UniqueID( ), .25, 0, function( ply ) RunConsoleCommand( "lowerstamina" ) end ) end end hook.Add( "KeyPress", "StaminaKeyPress", StaminaKeyPress ) function StaminaKeyRelease( ply, key ) if key == IN_SPEED then timer.Destroy( LocalPlayer( ):UniqueID( ) ) timer.Create( LocalPlayer( ):UniqueID( ), 1, 0, function( ply ) RunConsoleCommand( "raisestamina" ) end ) end end hook.Add( "KeyRelease", "StaminaKeyRelease", StaminaKeyRelease ) [/lua] Then in init.lua make it lower and raise the stamina, and set the stamina to 100 when spawning.
[QUOTE=Persious;26156688]Stamina is pretty simple. Just do it like this: (Shared) [lua] function StaminaKeyPress( ply, key ) if key == IN_SPEED then timer.Destroy( LocalPlayer( ):UniqueID( ) ) timer.Create( LocalPlayer( ):UniqueID( ), .25, 0, function( ply ) RunConsoleCommand( "lowerstamina" ) end ) end end hook.Add( "KeyPress", "StaminaKeyPress", StaminaKeyPress ) function StaminaKeyRelease( ply, key ) if key == IN_SPEED then timer.Destroy( LocalPlayer( ):UniqueID( ) ) timer.Create( LocalPlayer( ):UniqueID( ), 1, 0, function( ply ) RunConsoleCommand( "raisestamina" ) end ) end end hook.Add( "KeyRelease", "StaminaKeyRelease", StaminaKeyRelease ) [/lua] Then in init.lua make it lower and raise the stamina, and set the stamina to 100 when spawning.[/QUOTE] That's really exploitable, and you didn't specify what to do when the stamina is 0.
Yeah, I know it's realy exploitable, but I didn't want to show him all the things as he wanted to do something himself.
But you shouldn't have gave him exploitable code anyway.
Okay guys, so this is what I've got now. It looks like crap, i'm just starting to script from scratch. I do know how to edit, but that's bout it. [code] local function HitCall(ply, args) local namepos = string.find(args, " ") if not namepos then return "" end target = FindPlayer(name) if v:Team(TEAM_HITMAN) then Msg("You have recieved a hit from"..ply:Nick().."for"..target..".") if not v:Team(TEAM_HITMAN) then return end hook.Add("/hit", "playername", HitCall) local function HitDemote(v) if t == "TEAM_HITMAN" Player:Deaths() not HitCall then v:TeamBan() if v:Alive then v:ChangeTeam(TEAM_CITIZEN, true) if RPArrestedPlayers[v:SteamID()] then v:Arrest end [/code]
[QUOTE=Loures;26157061]But you shouldn't have gave him exploitable code anyway.[/QUOTE] Well yeah, but atleast I'm helping him.
Bump, any idea if im doing it right?
Thanks joker. I'll look through tutorials on Wiki, and slowly learn it from there. Than I'll try again. I took some of the script from the /pm script in DarkRP.
Alright at the moment I am also trying to make a hitman script. This is just the pay part for it. This is what I have so far [code]function PayForService(ply,cmd,args) local target = FindPlayer(args[1]) local allplayers = player.GetAll( ) local amount = 5000 Hits = {} if target == nil then Notify(ply,1,4, "You must supply a target.") return end if (ply:CanAfford(5000) == true) then ply:AddMoney(-amount) Notify(ply,1,4, "You have put a hit on " .. target .. ".") else Notify(ply,1,4, "You cannot afford to purchase the hitmans' services.") end for k,v in pairs ( allplayers ) do if v:IsAdmin() then v:PrintMessage(HUD_PRINTCONSOLE, ply:Nick() .. " has put a hit on " .. target .. ".") end end for k,v in pairs ( allplayers ) do if v:Team()=="TEAM_HITMAN" then Notify(v,1,4, ply:Nick() .. " has put a hit on " .. target .. ".") end end table.insert(Hits,target) table.insert(Hits,amount) end concommand.Add("hit", PayForService) AddChatCommand("/hit",Hitman)[/code] The error that I get is [code][gamemodes\darkrp5\gamemode\modules\hitman.lua:16] attempt to concatenate local 'target' (a userdata value[/code]
[QUOTE=Persious;26157051]Yeah, I know it's realy exploitable, but I didn't want to show him all the things as he wanted to do something himself.[/QUOTE] *cough* my functions *cough* and you need to remove the con commands.
The hitman script looks amazing, and after some help from a friend, I actually understand what's happening. Also, i think the error is happening cause you didn't state what target was in the first place. Nvm, didn't read local = target
So joker, Notify(v,1,4, ply:Nick() .. " has put a hit on " .. target:Name() .. ".") ?
Don't use too many NWVars it can give clients buffer overflow. Anyways, I made this. Tell me if there are any errors it may not work and has not been tested. [lua] local hits = {} function AddHit(ply,cmd,args) local HitsEnabled = true -- Turn hits on or off local MaxHits = 5 -- Max hits at one time HitAmmt = 500 -- Hit ammt local target = FindPlayer(args[1]) -- You must have DarkRP if HitsEnabled == false then ply:ChatPrint('Hits are currently disabled.') return '' end if not args[1] then ply:ChatPrint('You need to specify the person to put the hit on.') return '' end if table.Count(hits) > MaxHits then ply:ChatPrint('Sorry, the max hit limit has been reached.') return '' end table.insert(hits,target) ply:AddMoney(-HitAmmt) end concommand.Add('rp_addhit',AddHit) function Hitman(ply,cmd,args) HitmanTeam = TEAM_HITMAN -- The team for hitman local Chat = true -- Print in chat? local Console = true -- Print in console? if (!ply:Team == HitmanTeam) then ply:ChatPrint("You are not a hitman!") return '' end if table.Count(hits) == 0 then ply:ChatPrint("There are no hits at the moment.") return '' end for inc=1,table.Count(hits) do if Chat == true then ply:ChatPrint("There is a hit on "..hits[inc]) end if Console == true then ply:PrintMessage("There is a hit on "..hits[inc]) end end end function HitComplete(victim,killer) if (!killer:Team() == HitmanTeam) then return '' end if (!table.HasValue('hits',victim:Nick())) then return '' end table.remove(hits,victim:Nick()) killer:ChatPrint("Hit complete. Paid $"..HitAmmt) killer:AddMoney(HitAmmt) victim:ChatPrint("You have been killed by a hitman.") end hook.Add("PlayerDeath","HitManHook",HitComplete) [/lua]
I provided a very basic outline, as I would call it, for him to edit. But, thank you for pointing that out.
[QUOTE=thejjokerr;26184448]What zzaacckk posted wont work, he used a variable called HitAmmt to save the amount of money rewarded for a kill, if there would be more hitmans it would interfere. Rather use something like player_object.hitAmount[/QUOTE] I am very confsued what you mean by player_object.hitAmount
[QUOTE=dpoolas;26188470]I am very confsued what you mean by player_object.hitAmount[/QUOTE] You can actually assign each player a new variable. For instance: I could have a script that does something to get a player, like the first one connected or something. Then I could do something like ply.Derp = 1. So for that first player, the variable Derp is just assigned to him. If I tried to get another players Derp value they wouldn't have one as it has not been assigned to them. So you could manage each players bounty that way. ply.Bounty = amount_of_cash_goes_here This can be serverside or clientside, but wherever you declare it that's where it'll stay. And you have to use the . in it.
[QUOTE=zzaacckk;26184206][lua] local hits = {} function AddHit(ply,cmd,args) local HitsEnabled = true -- Turn hits on or off local MaxHits = 5 -- Max hits at one time HitAmmt = 500 -- Hit ammt local target = FindPlayer(args[1]) -- You must have DarkRP if HitsEnabled == false then ply:ChatPrint('Hits are currently disabled.') return '' end if not args[1] then ply:ChatPrint('You need to specify the person to put the hit on.') return '' end if table.Count(hits) > MaxHits then ply:ChatPrint('Sorry, the max hit limit has been reached.') return '' end table.insert(hits,target) ply:AddMoney(-HitAmmt) end concommand.Add('rp_addhit',AddHit) function Hitman(ply,cmd,args) HitmanTeam = TEAM_HITMAN -- The team for hitman local Chat = true -- Print in chat? local Console = true -- Print in console? if (!ply:Team == HitmanTeam) then ply:ChatPrint("You are not a hitman!") return '' end if table.Count(hits) == 0 then ply:ChatPrint("There are no hits at the moment.") return '' end for inc=1,table.Count(hits) do if Chat == true then ply:ChatPrint("There is a hit on "..hits[inc]) end if Console == true then ply:PrintMessage("There is a hit on "..hits[inc]) end end end function HitComplete(victim,killer) if (!killer:Team() == HitmanTeam) then return '' end if (!table.HasValue('hits',victim:Nick())) then return '' end table.remove(hits,victim:Nick()) killer:ChatPrint("Hit complete. Paid $"..HitAmmt) killer:AddMoney(HitAmmt) victim:ChatPrint("You have been killed by a hitman.") end hook.Add("PlayerDeath","HitManHook",HitComplete) [/lua][/QUOTE] local HitsEnabled = true -- Turn hits on or off local MaxHits = 5 -- Max hits at one time Those should be global. They set to true and 5 max hits everytime a hit is done.
Sorry, you need to Log In to post a reply to this thread.