• "Counting function" in the code
    1 replies, posted
I'm doing a script like the level system, I wrote a function, adding rewards for leveling, adding items is as follows: AddPointshopReward( 1, "models/props_wasteland/light_spotlight01_lamp.mdl", "Lamp Head") AddPointshopReward( 2, "models/props_lab/kennel_physics.mdl", "Cage") AddPointshopReward( 3, "models/food/hotdog.mdl", "Hotdog Hat") This is the function: function AddPointshopReward(level, Item, PS2) After obtaining a certain level, a button appears that sends NetMessage to the server: function SendReward() if (level <= PlayerLevel - 1) then RewardButton:SetEnabled( true ) RewardButton.DoClick = function() net.Start("give_reward") net.WriteString( level ) if PS2 then net.WriteString( PS2 ) end net.SendToServer() end end end And here is my problem, using the button causes sending the "level" value of only one function, for example: If I get level 3 and I have 2 rewards to receive, then for each reward I have to press a button, and I would like the button to send information about all levels acquired, not individually.
Don't send strings please, make them shared and assign integers to it (Unique ID) You want to know how many time was AddPointshopReward called, right ? Just add a static value in it, local AddPointshopRewardCounter = 0 function AddPointshopReward(level, Item, PS2) AddPointshopRewardCounter = AddPointshopRewardCounter + 1 ... end
Sorry, you need to Log In to post a reply to this thread.