Author Topic: LevelingWeapons  (Read 1008 times)

0 Members and 1 Guest are viewing this topic.

Offline Cheeser

  • Major(1)
  • Posts: 36
  • The Pleaser
LevelingWeapons
« on: February 28, 2010, 02:45:43 am »
Note: This is a script that I do not plan on expanding upon, and was made for fun and practicing my programming "skills." Suggestions on what to add are cool, though.

Lowdown:
Each player can level up their weapons (Yeah, their weapons, lol.) by killing opponents. Same idea as any other RPG server, but instead of leveling up yourself, you level up whatever weapon you use most often. Higher level = More Damage Done. Pretty simple idea and code, created within several days.

Flaws or Problems I had:
1. One shot kill weapons are always one shot kills, so leveling them is meaningless, right? :(
2. I couldn't find anything to detect what a player's weapon was, except
Code: [Select]
GetPlayerStat(i,'Primary')which wouldn't do exactly what I wanted, since secondary weapons are level-able, too. To solve this I created an array which works beautifully, however I feel that there might be a better way.
3. Something that had to be typed over and over by me was the formula for the expReq variable. Any time I changed that little math-y formula once, I had to change it two other times. There's definitely an easier way to do that, dunno what it is.
4. In general, this is a stupid idea, because at some point all players have their favorite weapon at the highest levels and are one-shotting each other every time, which isn't fun. Please don't criticize me on this fact, I am so very aware of it.

Questions/comments are nice, criticism that will make me a better programmer would be awesome.

If anyone wants to use this or edit this at their own will, feel free, it's not like this is a huge project that I want to hide from the world.

Code is attached.
Chuck Norris joke here.

Offline y0uRd34th

  • Camper
  • ***
  • Posts: 325
  • [i]Look Signature![/i]
Re: LevelingWeapons
« Reply #1 on: February 28, 2010, 04:29:28 am »
Yeah, pretty simple code :D
The idea is like iMod, even though it is different since you can level each weapons and they have no special abilitys.
Alot of soldat scripters here know the problem with detecting a weapon in OnPlayerDamage(), afaik enesce is going to add a weapon var into OnPlayerDamage() in 1.5.1 :)

Suggestions of things you could add:
Max. possible levels for all guns.
Some account system to save your weapons level.
Use type to store player vars since it looks more aesthetic in the scripts.
Try to make a custom array for the weapons levels and experience. (not 0..255, like 0..17: 1-14 normal guns, 15-17, flamer, bow, flame bow and 0 fists)

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: LevelingWeapons
« Reply #2 on: February 28, 2010, 11:09:22 am »
Instead of having many myvar: array[1..32] of sometype, it may be easier to do:
Code: (pascal) [Select]
TPlayer = record
  WeaponLevel: array[0..255] of word;
  Experience: array[0..255] of word;
end;

var
  Players: array[1..32] of TPlayer;
You could even create a TWeapon type to contain level and experience or something if you wanted to.


Also, if a number is never going to be negative, I personally use types that won't ever be negative, to allow the largest possible value without wasting bits (refer to the wiki's topic [a=http://devs.soldat.pl/wiki/index.php?title=Data_Types]Data Types[/a] for a list of them).
One possible 'issue' with using unsigned integers is how you MUST do a 'if GetArrayLength > 0' before your loop, because if the length is 0, doing for 'for i := 0 to -1' would be for i := 0 to 255 if i is a byte, and even larger if i is another larger type.

Quote
Something that had to be typed over and over by me was the formula for the expReq variable. Any time I changed that little math-y formula once, I had to change it two other times. There's definitely an easier way to do that, dunno what it is.
You could create your own custom function. A random unrelated example:
Code: (pascal) [Select]
function RequiredExperience(const Lvl: byte): word;
begin
  Result := Lvl * Lvl * 750 + 250; // not actually your formula ^^ I was kind of lazy on trying to get it out of the code
end;

This is another approach on required experience: trying to calculate all the required experiences at the beginning.
Code: (pascal) [Select]
var
  RequiredExperience: array[0..255] of word;

procedure ActivateServer();
var
  i: byte;
begin
  for i := 0 to 255 do RequiredExperience[i] := ReqExpFormulaGivenLevel(i);
end;
assuming all weapons have the sme exp per level, otherwise the use of array[0..255] of array[0..255] of word; or something similar would be necessary (assuming level 255 = max).
Kind of a bad idea just to say since all of these bytes would be sitting in the ram. Would probably be better to do what ur doing, calculate it every time.

Offline mich1103

  • Flagrunner
  • ****
  • Posts: 558
  • Did you say chocolate ? O.o
    • ZoMbIe-DeStRoYeR pk server
Re: LevelingWeapons
« Reply #3 on: March 09, 2010, 05:08:46 pm »
Your script is nice  :D
i've tought that i can do a save n load system with that !
When a player do /char
that will say his lvl on all weapon and % of hit !
But is why i say that i need help for that in my signature ...  :'(