hello there, so i made a quest and when you done the quest will check your level and give you the correct gift. but idk why i worry to much how i made the last part and i need to make sure this wont harm the player.
so lets say 10 people finish the quest and trune it same time, will this do anything bad? i feel there is better way to do the way i coded but idk, any idea?
This script does nothing besides call add/delete item methods. Assuming those are written properly then there's no reason for it to lag people out.
That being said... not a big fan of that giant if/else string. You sure you wouldn't rather use a reward for each 20-30 levels and use a switch statement?
Well, this might be a cleaner way of doing it (however, the level 25 wouldn't work). On my server, I keep track of the level class (10 levels for every one level class) the player's in (so I don't do the arithmetic that you'd be doing every time this runs). It should be more efficient though because you're only doing one check per level class instead of two (depending on what level ranges you're checking). It also looks cleaner. I have each level class defined in an enumeration type as well; you can do that too to replace the numbers with something a bit more understandable. Really, you don't need to worry too much about efficiency with something like this. Any little change is still O(n) efficiency. We're talking about a couple nanoseconds of difference.
Code:
switch (client.Entity.Level / 10)
{
// Example:
case 1: // Level 10
case 2: // Level 20
client.Inventory.Add(1458756, 0, 1);
break;
}
// Put this on the outside since it's always called. Looks cleaner.
client.Inventory.DeleteItem(729310, 1);
@Fang, just curiosity: what will happen if the inventory is full before you add the prize?
That's not my problem, and not what my code was getting at. It was just showing a cleaner alternative.
Edit: I like your alternative btw. I do that for walking coordinates. I'm not sure I would like using it for features like that though (just preference - which we have room for since we're talking about a couple nanoseconds for a feature that's used once a year).
since the quest will give more then 4 items, so i will add a check to make sure the inv have at list 5 empty spot open.
here is a exmaple for you if you like.
if (client.Inventory.Count < 37)
{
add item here
}
else
client.Send(new Message("You need to make atleast 3 free spots in your inventory.", System.Drawing.Color.Red, Message.TopLeft));
since the quest will give more then 4 items, so i will add a check to make sure the inv have at list 5 empty spot open.
here is a exmaple for you if you like.
if (client.Inventory.Count < 37)
{
add item here
}
else
client.Send(new Message("You need to make atleast 3 free spots in your inventory.", System.Drawing.Color.Red, Message.TopLeft));
Using many if cases is acceptable IMO, you could wrap them in another function though. Don`t neglect using ifs just because you can use other stuff, conditionals are always one of the fastest parts of a programming language.
Coming Soon!! How to make a Lagg!! 03/15/2010 - S4 League - 6 Replies Ich werde demnächst zeigen wie man im S4 League Laggen Kann.
Man hat dem entsprechen Vorteile und Warum Meine Methote nicht Gepatch oder Gefixt werden kann.
How to make SV DC on all players 05/19/2007 - Conquer Online 2 - 16 Replies as the topic says, how to make SV disconnect on every player? at the moment I can only write down names of when you see them you disconnect, but to make it more safe, I want to make it dc on all players
How to do that?
text2schild.php?smilienummer=1&text=Help Appreciated, and karma awarded =D' border='0' alt='Help Appreciated, and karma awarded =D' />
Make players go red 11/26/2005 - Lin2 Exploits, Hacks, Bots, Tools & Macros - 4 Replies Ask some1 who can cast poison to do so on you.
Let him poison you until you have very low HP and slow regenerate HP.
Ask some1 to pvp and let him hit you first. Then you die lol.
Then he goes red and everyone starts attacking him and he will drop items :D
Make sure that a friend of you is near and can pick up the items :D
Well, that's it