
World Code
Tags:
Command
Creator:
_Ameer_Slow
Code:
// SAVE ROLE FIXED (WORKS)
let slot = api.getMoonstoneChestItemSlot(pid,0);
if(!slot || !slot.attributes){
let data = {role:null};
api.setMoonstoneChestItemSlot(pid,0,"Dirt",1,{
customAttributes:data
});
return data;
}
return slot.attributes.customAttributes || {role:null};
}
function saveData(pid,data){
api.setMoonstoneChestItemSlot(pid,0,"Dirt",1,{
customAttributes:data
});
}
function giveRole(pid){
let data = getData(pid);
// لو عنده دور لا تغيّره
if(data.role){
api.sendMessage(pid,"Role: "+data.role);
return;
}
const random = Math.random();
if(random < 0.3){
data.role = "cop";
api.sendMessage(pid,"You are a COP",{color:"#00BFFF"});
api.giveItem(pid,"Iron Sword",1);
} else {
data.role = "robber";
api.sendMessage(pid,"You are a ROBBER",{color:"#FF4444"});
api.giveItem(pid,"Wood Sword",1);
}
saveData(pid,data);
}
let checked = {};
function tick(){
const players = api.getPlayerIds();
for(let i=0;i<players.length;i++){
let pid = players[i];
if(api.playerIsInGame(pid)){
if(!checked[pid]){
checked[pid] = true;
giveRole(pid);
}
}
}
}Instructions:
The policeman and the thief: The policeman kills the thief.