Перейти к содержимому
View in the app

A better way to browse. Learn more.

Zloplay community

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[HELP] Shared cash on shop system

Опубликовано:

Hello, i'm making a shop script for my server but the cash seems to be shared to everyone in the server, how do i fix that?

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

using InfinityScript;

namespace HUD
{
   public class hud : BaseScript
   {
       private int cash;
       private HudElem cashtxt;

       public hud()
           : base()
       {
           PlayerConnected += new Action(entity =>
           {
               createPlayerHud(entity);
           });
       }

       private void createPlayerHud(Entity player)
       {
           HudElem wep = HudElem.CreateFontString(player, "hudSmall", 0.7f);
           wep.SetPoint("TOP CENTER", "TOP CENTER", 0, 0);
           wep.HideWhenInMenu = true;

           HudElem cashtxt = HudElem.CreateFontString(player, "hudSmall", 1f);
           cashtxt.SetPoint("BOTTOM", "BOTTOM", 0, 0);
           cashtxt.SetText("^1Cash: ^2" + cash);



           OnInterval(1000, () =>
           {
               wep.SetText("Weapon: " + player.CurrentWeapon);
               cashtxt.SetText("^1Cash: ^2" + cash);
               return true;
           });
       }
       public override void OnSay(Entity player, string playerName, string text)
       {
           string[] arrChatMsg = text.Split(' ');
           if (arrChatMsg[0] == "!buy")
           {
               if (arrChatMsg[1] == "ac130")
               {
                   if (cash >= 250)
                   {
                       player.Call("iprintlnbold", "^2Bought:^3 Walking AC130");
                       player.TakeAllWeapons();
                       player.GiveWeapon("ac130_25mm_mp");
                       player.SwitchToWeaponImmediate("ac130_25mm_mp");
                       cash -= 250;
                       return;
                   }
                   else { player.Call("iprintlnbold", "^1Not Enought Cash"); }
                   return;
               }
               if (arrChatMsg[1] == "wall")
               {
                   if (cash >= 100)
                   {
                       player.Call("iprintlnbold", "^2Bought:^3 Wallhack");
                       player.Call("thermalvisionfofoverlayon");
                       cash -= 100;
                       return;
                   }
                   else { player.Call("iprintlnbold", "^1Not Enought Cash"); }
                   return;
               }
               if (arrChatMsg[1] == "hp")
               {
                   if (cash >= 300)
                   {
                       player.Call("iprintlnbold", "^2Bought:^3 Super HP");
                       player.SetField("maxhealth", player.Health * 10);
                       player.Health = player.Health * 10;
                       cash -= 300;
                       return;
                   }
                   else { player.Call("iprintlnbold", "^1Not Enought Cash"); }
                   return;
               }
               return;
           }
           if (arrChatMsg[0] == "/rich")
           {
               cash += 1337;
               return;
           }
       }
       public override void OnPlayerKilled(Entity player, Entity inflictor, Entity attacker, int damage, string mod, string weapon, Vector3 dir, string hitLoc)
       {
           if (attacker != player) {
               cash += 50;
           }
           if (attacker == player)
           {
               cash -= 50;
           }
       }

   }
}

Featured Replies

Опубликовано:
your cash variable is a global variable.

Try setting it as a field under the player using:

player.setField("cash", cash);

and getting it with:

player.getField("cash");

 

I tried but player.getField gives me an error that its not on the context...

Опубликовано:
your cash variable is a global variable.

Try setting it as a field under the player using:

player.setField("cash", cash);

and getting it with:

player.getField("cash");

 

I tried but player.getField gives me an error that its not on the context...

 

It's player.GetField pay attention to the caps :P

Опубликовано:
Aalalex":3s4dw9g2]It's player.GetField pay attention to the caps :P

ty dude but still didnt work..

this time it was like cash didnt even exist

Опубликовано:
Aalalex":b5jham3m]It's player.GetField pay attention to the caps :P

ty dude but still didnt work..

this time it was like cash didnt even exist

 

player.GetField("cash"); //to get the amount of cash a certain player has
player.SetField("cash", 100); //to set the amount of cash a certain player has

 

Basically the same as TheApadayo said but with correct caps ;P

Опубликовано:

Well SetField and GetField just wont work...

aint any way around this using just variables?

 

EDIT: Wait, it was working all the time, the problem was with the creation of the HUD...

thanks everyone for the support

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Гость
Ответить в тему...

Сейчас на странице 0

  • Нет пользователей, просматривающих эту страницу

Важная информация

Используя этот сайт, вы соглашаетесь Условия использования.

Account

Navigation

Поиск

Поиск

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.