• Damage props to money?
    19 replies, posted
ive been asking a few questions recently however this has been killing me imagine your shooting another players base (pile of props) if you damage thier props i need it to give the player money but dont know how to code it? can anyone help? i can supply anything you awesome peoples need Edit - could i use this in any way? - all i need it to do is for every point of damage caused it adds +1 money to the players cash [CODE] pl:SetNWInt("Cash", pl:GetNWInt("Cash") + 1) [/CODE]
For what gamemode? Does it have a money system?
[QUOTE=jargen;36300036]For what gamemode? Does it have a money system?[/QUOTE] its for a base war type gamemode it has a money system using a serverside sql type database the cash is just called "Cash"
Rough idea: (From memory i think prop_physics is the class for a normal prop) [code] function GM:EntityTakeDamage( ent, inflictor, attacker, amount ) if ( ent:GetClass() == "prop_physics" ) then --whatever your function to give a player cash is end end [/code]
[QUOTE=jargen;36300135]Rough idea: (From memory i think prop_physics is the class for a normal prop) [code] function GM:EntityTakeDamage( ent, inflictor, attacker, amount ) if ( ent:GetClass() == "prop_physics" ) then --whatever your function to give a player cash is end end [/code][/QUOTE] No luck with this as of yet, im currently trying [CODE] function GM:EntityTakeDamage( ent, inflictor, attacker, amount ) if ( ent:GetClass() == "prop_physics" ) then pl:SetNWInt("Cash", pl:GetNWInt("Cash") + 1) end end [/CODE] however im thinking of making it into something more like this [CODE] local MD = {whatever goes here} [/CODE] so i can add it to this (md being the damage caused) [CODE] local MF = math.Clamp(MH / 5000, 0, self.Wide) local MW = (MF + 3 + MD) [/CODE] (MF being how much you earn per second for surviving) --------------------------------------------- So so far it looks like this.. [CODE] if LocalPlayer():GetNWInt("Cash") != nil && LocalPlayer():GetNWInt("Cash") != "" then local MH = LocalPlayer():GetNWInt("Cash") local MD = local MF = math.Clamp(MH / 5000, 0, self.Wide) local MW = (MF + 3 + MD) [/CODE] -------------------------------------------------------------------- -----------------------------Edit 2--------------------------------- -------------------------------------------------------------------- I dont mind which way its done tbh, just as long as it works :P -------------------------------------------------------------------- [editline]12th June 2012[/editline] sry for double posts but any help / responses?
MD would be the amount argument.
[QUOTE=Chessnut;36300881]MD would be the amount argument.[/QUOTE] i know this, but im just trying to figure out a way to get the damage to a value to add to the money >< its hurting my brain trying to do it :P
Just saying, pl should be inflictor. Also what do you mean figure out the value?
[QUOTE=Chessnut;36300947]Just saying, pl should be inflictor. Also what do you mean figure out the value?[/QUOTE] well, basicly i want this to add 1cash to the players money for every point of damage done, i just dont know how to do it
[lua] for i = 1, amount do -- Add one point. end; [/lua] Like that?
[QUOTE=Chessnut;36301736][lua] for i = 1, amount do -- Add one point. end; [/lua] Like that?[/QUOTE] Wow. I don't even know what to say. How about: [lua] --[[for i = 1, amount do -- Add one point. end;]] local newCash = oldCash + amount [/lua]
[QUOTE=nucleonic;36301022]well, basicly i want this to add 1cash to the players money for every point of damage done, i just dont know how to do it[/QUOTE] He gave it to you... pl is not defined. You need it use the inflictor argument. [editline]12th June 2012[/editline] Like so... [code] function GM:EntityTakeDamage( ent, inflictor, attacker, amount ) if ( ent:GetClass() == "prop_physics" ) then inflictor:SetNWInt("Cash", inflictor:GetNWInt("Cash") + amount) end end [/code]\ Im having issues with everything posting on the same fucking line again. Ill try to fix this later.
[QUOTE=SeveredSkull;36302786]He gave it to you... pl is not defined. You need it use the inflictor argument. [editline]12th June 2012[/editline] Like so... [code] function GM:EntityTakeDamage( ent, inflictor, attacker, amount ) if ( ent:GetClass() == "prop_physics" ) then inflictor:SetNWInt("Cash", inflictor:GetNWInt("Cash") + amount) end end [/code]\ Im having issues with everything posting on the same fucking line again. Ill try to fix this later.[/QUOTE] No problems
[code] function GM:EntityTakeDamage( ent, inflictor, attacker, amount ) // Is the entity a prop? if ( ent:GetClass() == "prop_physics" ) then // give the inflictor cash per point of damage inflicted on the prop inflictor:SetNWInt("Cash", inflictor:GetNWInt("Cash") + amount) // I am assuming you do not have a damage system, so here: //This sets up your health for the prop ent.PropHealth = ent.PropHealth or 100 //Subtract the amount of damage from the health ent.PropHealth = ent.PropHealth - amount //If the prop should die, remove it if ent.PropHealth <= 0 then ent:Remove() end end end [/code] Cant seem to get my damned browser to work with multiple lines, so Im startin' a new one. I also added in a damage system for you as well, If you don't need it, just take it out.
[QUOTE=SeveredSkull;36303131][code] function GM:EntityTakeDamage( ent, inflictor, attacker, amount ) // Is the entity a prop? if ( ent:GetClass() == "prop_physics" ) then // give the inflictor cash per point of damage inflicted on the prop inflictor:SetNWInt("Cash", inflictor:GetNWInt("Cash") + amount) // I am assuming you do not have a damage system, so here: //This sets up your health for the prop ent.PropHealth = ent.PropHealth or 100 //Subtract the amount of damage from the health ent.PropHealth = ent.PropHealth - amount //If the prop should die, remove it if ent.PropHealth <= 0 then ent:Remove() end end end [/code] Cant seem to get my damned browser to work with multiple lines, so Im startin' a new one. I also added in a damage system for you as well, If you don't need it, just take it out.[/QUOTE] i have a damage system :P ill just use the cash one Testing it in 5 mins btw -------Edit------ Sorry for late reply, just been recoding something, that code still isnt working O.o no idea why tbh
[QUOTE=_nonSENSE;36301828]Wow. I don't even know what to say. How about: [lua] --[[for i = 1, amount do -- Add one point. end;]] local newCash = oldCash + amount [/lua][/QUOTE] The way he described, he said to add one for every damage point.
[QUOTE=nucleonic;36303339]i have a damage system :P ill just use the cash one Testing it in 5 mins btw -------Edit------ Sorry for late reply, just been recoding something, that code still isnt working O.o no idea why tbh[/QUOTE] Is the code even being ran? Is it doing ANYTHING?
[QUOTE=jargen;36306106]Is the code even being ran? Is it doing ANYTHING?[/QUOTE] Agreed. That code I am currently using already... I know it works because its straight from my own game-mode. (Changed a bit of course) [editline]12th June 2012[/editline] Define "Not Working" Error codes, line numbers, results... SOMETHING we can go off of in order to help you. [editline]12th June 2012[/editline] [QUOTE=Chessnut;36306066]The way he described, he said to add one for every damage point.[/QUOTE] He knows. The way you did it was absolutely excessive and horrible. You made a loop from 1 to amount to add 1 (amount) number of times, when all you have to do is just add the amount.
[QUOTE=SeveredSkull;36307772]Agreed. That code I am currently using already... I know it works because its straight from my own game-mode. (Changed a bit of course) [editline]12th June 2012[/editline] Define "Not Working" Error codes, line numbers, results... SOMETHING we can go off of in order to help you. [editline]12th June 2012[/editline] He knows. The way you did it was absolutely excessive and horrible. You made a loop from 1 to amount to add 1 (amount) number of times, when all you have to do is just add the amount.[/QUOTE] As you jargen said - it may not be being ran, but im not too sure as i have code thats next to it that gets ran - ill move it when i get in from college today and ill just mess round with it untill its working. Thanks for all the help peoples!
Add some prints in the code, so you can see what is being ran (if anything).
Sorry, you need to Log In to post a reply to this thread.