How to make a command affect all players?

Dragonary

Member
Modder
Jun 21, 2024
10
6
290
I have this command here which can change the number of coins needed for 100 coin star.
It works for the player running the command (the host for example), however when I use player 2 and collect some coins, the star doesn't appear.

LUA:
function coin(n)
    gLevelValues.coinsRequiredForCoinStar = tonumber(n)
    return true
end

hook_chat_command("coin", "[number] - Change number of coins needed for 100 coin star", coin)
 
I believe this is due to level values only being synced on join. To fix this, you can either create a gGlobalSyncTable that you edit, and then set the level value to that global sync table, or use the network packet system. The network packet system is overkill for this, so just create an entry in the gGlobalSyncTable.
 
Code:
gGlobalSyncTable.coinsRequiredForCoinStar = gLevelValues.coinsRequiredForCoinStar

function coin(n)
    gLevelValues.coinsRequiredForCoinStar = tonumber(n)
    return true
end

I have no idea how to use gGlobalSyncTable. I tried a bunch of things and nothing seems to work.
 
Sorry for the late response. So yea, gGlobalSyncTable.coinsRequiredForCoinStar should be set instead of gLevelValues.coinsRequiredForCoinStar in the coin function. Then, create a hook that hooks to, for this instance, update. In that hook, just set gLevelValues.coinsRequiredForCoinStar to gGlobalSyncTable.coinsRequiredForCoinStar, and it should sync up fine!
 

Users who are viewing this thread