Author Topic: Cash Script  (Read 1000 times)

0 Members and 1 Guest are viewing this topic.

Offline BRADEN

  • Camper
  • ***
  • Posts: 319
Cash Script
« on: May 19, 2008, 02:05:23 pm »
OK, I want to make like a gun shop. I know how to do everything except the cash system. What I need to know is how to make cash and how it is reduced and what happens when not enough cash is available. Also, with every kill, a player gets a certain amount of cash.

And please write notes beside every line so that I know how to change some values if I need to.

Thanks in advance.

Death is the solution to all problems. No man; no problem.
-Joseph Stalin

Offline JFK

  • Camper
  • ***
  • Posts: 255
    • My TraxInSpace Account
Re: Cash Script
« Reply #1 on: May 20, 2008, 05:51:07 am »
You're asking for someone to make a (almost) complete script for you. You might want to check out DorkeyDear's counter strike script.

Anyway, if you want to figure it out yourself (and maybe learn a lot). I can help you start a bit. What you need to do is keep track of how much money every player has and what weapons he/she possesses. An elegant way to do that is making your own type:

Code: [Select]
//code has NOT been tested!

const
MaxPlayers = 18 //Maximum number of players on the server, including admins/bots

type // here goes:

CapitalInfo = Record //We call our type CapitalInfo. This is a 'record' that has other variables in it:
  cash : int;
  weapon : Array[1..10] of Boolean //these represent the 10 primary weapons
  //maybe some other booleans for stuff like a vest to be handed out after respawn
end;

var

Player = Array[1..MaxPlayers] of CapitalInfo; //here you make an array of CapitalInfo called Player[]


Now all the money is stored in Player[ID].cash. To increase someone's cash do: inc(Player[ID].cash, Amount)
To decrease someone's cash, first check if it wont go below zero:
Code: [Select]
if (Player[ID].cash >= Amount) then dec(Player[ID].cash, Amount) else WriteConsole(ID, "Not enough cash", someColor);
Suppose a player buys a weapon, you can store it like this: Player[ID].weapon[WeaponID] := true;
Of course you should check if a player doesn't already possesses that weapon, before you'll allow him to buy it.

Now there's one more thing you should know when using a 'buy wep'-system. There are basically two ways to disable all weapons. First one is to set them all to zero in Soldat.ini, but then you'll have to disable anti-cheat kick. Plus you'll get a lot of messages in Arsse saying 'player is cheating - not allowed weapon'. You can use a script to ignore that message (see DorkeyDear's post).
The second way is to put advanced mode as high as possible. It will be so high noone will ever get a weapon for free. I'm not sure if that will work though, never tested it.

Good Luck

Come join: EliteCTF
Listen to: My Music

Offline Boblekonvolutt

  • Soldier
  • **
  • Posts: 222
  • "YOU are a CAR."
Re: Cash Script
« Reply #2 on: May 20, 2008, 06:23:37 am »
Why not just use SetWeaponActive to disable the weapons for a player when he joins?

Offline BRADEN

  • Camper
  • ***
  • Posts: 319
Re: Cash Script
« Reply #3 on: May 20, 2008, 03:17:11 pm »
JFK, I specifically said I want no one to create a complete script. ;) All I wanted to know is the basic principles for creating a cash system. I'll check out your post when I have time.

Date Posted: May 20, 2008, 03:24:03 pm
OK I asked this multiple times, but where do you actually put that piece of code? In what file?

Death is the solution to all problems. No man; no problem.
-Joseph Stalin

Offline Boblekonvolutt

  • Soldier
  • **
  • Posts: 222
  • "YOU are a CAR."
Re: Cash Script
« Reply #4 on: May 21, 2008, 05:38:13 am »
Make a new folder in /scripts/,
make a .pas file called anything (anything.pas...),
Make a .txt file called Includes.txt

Write the name of the pas file ("anything.pas") in the Includes.txt file, recompile.

Offline rayanaga

  • Soldier
  • **
  • Posts: 143
  • ~Fur flying~
    • Kryonex
Re: Cash Script
« Reply #5 on: July 09, 2008, 11:23:59 am »
To give you a straight anwser, you could do:
Code: [Select]
var
  Cash: array[1..32] of integer;

which would set up a basic array to hold the cash for each player. then it could be accessed such as Cash[ID].

Then, for the OnPlayerCommand procedure, you could make it look like:

I made the script as simple to understand as i possiblly could.

Code: [Select]
function OnPlayerCommand(ID: Byte; Text: string): boolean;
begin

if Text = '/help' then
begin
WriteConsole(ID,'/mp5     : $300:  A fast and lethal weapon.',RGB(200,255,200));
WriteConsole(ID,'/barrett : $600:  One Hit Kill but slow reload.',RGB(200,255,200));
WriteConsole(ID,'/m79     : $800:  Explosive and very deadly.',RGB(200,255,200));
end;

if Text = '/mp5' then
begin
if Cash[ID] > 299 then
begin
dec(Cash[ID,300);
WriteConsole(ID,'You bought a mp5!',RGB(200,255,200));
ForceWeapon(ID,2,GetPlayerStat(ID,'Primary),0);
end else
WriteConsole(ID,'Not enough Cash!',RGB(200,255,200));
end;

//etc..
end;
you should notice how i checked if the player had enough money to begin with and that if he does, take it out of his 'account' and forcewep him the weapon.

To earn money, you could award on onPlayerKill
Code: [Select]
procedure OnPlayerKill(Killer, Victim: byte;Weapon: string);
begin
inc(Cash[Killer],random(0,20) + 60);
WriteConsole(Killer,'Cash: $' + inttostr(Cash[Killer]),RGB(200,255,200));
end;

Here, all i did was increase the person's cash by 60 + a random number between 0 and 20. Then i relayed the data back to the Killer.


Code: [Select]
procedure OnJoinGame(ID, Team: byte);
begin
Cash[ID] := 100;
end;
You can give them a little starting cash when they join.

Just trying to be of help and i hope these snippets of code really help you. :D
[kY] Kryonex - Your local zombie fanatics.
http://www.kryonex.com/