storage create

theduck

Member
Joined
Dec 6, 2018
Messages
114
Best answers
0
Reaction score
14
I'm trying to create something using global storage

global storage = between 1 to 100
print ('1')

global storage = between 100 and 200

print ('2')
global storage = between 200 and 300
print ('2')

My question is how do you use this between '1 to 100'
 

siusiaczek

Banned User
Joined
Jun 22, 2019
Messages
107
Best answers
1
Reaction score
37
math.random[a,b]

or
global variable = global.storage
if global.storage <= 100 then
print("1")
elseif global.storage <= 200 and global.storage >=101 then
print("2")
elseif global.storage <= 300 and global.storage >= 201 then
print("3")
end
 
OP
T

theduck

Member
Joined
Dec 6, 2018
Messages
114
Best answers
0
Reaction score
14
Code:
local normal = 1022
local um = 200
local dois = 300
local tres = 400
local quarto = 500
local cinco = 600
local seis = 7100
local sete = 11

function onThink(interval) 
 if  getGlobalStorageValue(Storage.aleatorio) <= normal  then 

print(' (boss aleatorio)')
    elseif getGlobalStorageValue(Storage.um) <= um and getGlobalStorageValue(Storage.aleatorio) >= normal +1 then  
 
print(' (um)')


    elseif  getGlobalStorageValue(Storage.dois) <= dois and getGlobalStorageValue(Storage.um) >= um +1 then  
 
print(' (dois)') 

    elseif getGlobalStorageValue(Storage.tres) <= tres and  getGlobalStorageValue(Storage.dois) >= dois +1 then   
print(' (tres)')
 
 elseif getGlobalStorageValue(Storage.quarto) <= quarto and  getGlobalStorageValue(Storage.tres) >= tres +1 then   
print(' (quarto)')

 elseif getGlobalStorageValue(Storage.cinco) <= cinco and  getGlobalStorageValue(Storage.quarto) >= quarto +1 then   
print(' (cinco)')

 elseif getGlobalStorageValue(Storage.seis) <= seis and  getGlobalStorageValue(Storage.cinco) >= cinco +1 then   
print(' (seis)')


 elseif getGlobalStorageValue(Storage.sete) <= sete and  getGlobalStorageValue(Storage.seis) >= seis +1 then   
print(' (sete)')
end
		    
		   
  
	return true
end
in case the 'seven' has 11 in the storage most even so the normal is running the correct would run the seven direct
 
OP
T

theduck

Member
Joined
Dec 6, 2018
Messages
114
Best answers
0
Reaction score
14
Can you msg why you need that? Im not sure if you should use that like you trying to
Do you think it can be done in another way?
my idea is the one I had the most storage will print in case it will be executed
 

Xikini

I whore myself out for likes
Premium User
Joined
Nov 17, 2010
Messages
4,172
Best answers
174
Reaction score
2,234
We don't know what your intent is for the script, so we can't tell you a better way to do it.
 
OP
T

theduck

Member
Joined
Dec 6, 2018
Messages
114
Best answers
0
Reaction score
14
We don't know what your intent is for the script, so we can't tell you a better way to do it.
So you have 3 storage
'"storage1 = 100
storage2 = 200
storage 3 = 300 "

when globalevents if enabled it will check
be the storage has the value to be executed
more will perform only one then
the storage1 was between 0 to 199 it is executed otherwise it goes to another and it will check if it was between 200 to 299 it executes the storage2
 
OP
T

theduck

Member
Joined
Dec 6, 2018
Messages
114
Best answers
0
Reaction score
14
Code:
local normal = 1022
local um = 200
local dois = 300
local tres = 400
local quarto = 500
local cinco = 600
local seis = 7100
local sete = 11

function onThink(interval)
if  getGlobalStorageValue(Storage.aleatorio) <= normal  then

print(' (boss aleatorio)')
    elseif getGlobalStorageValue(Storage.um) <= um and getGlobalStorageValue(Storage.aleatorio) >= normal +1 then

print(' (um)')


    elseif  getGlobalStorageValue(Storage.dois) <= dois and getGlobalStorageValue(Storage.um) >= um +1 then

print(' (dois)')

    elseif getGlobalStorageValue(Storage.tres) <= tres and  getGlobalStorageValue(Storage.dois) >= dois +1 then
print(' (tres)')

elseif getGlobalStorageValue(Storage.quarto) <= quarto and  getGlobalStorageValue(Storage.tres) >= tres +1 then
print(' (quarto)')

elseif getGlobalStorageValue(Storage.cinco) <= cinco and  getGlobalStorageValue(Storage.quarto) >= quarto +1 then
print(' (cinco)')

elseif getGlobalStorageValue(Storage.seis) <= seis and  getGlobalStorageValue(Storage.cinco) >= cinco +1 then
print(' (seis)')


elseif getGlobalStorageValue(Storage.sete) <= sete and  getGlobalStorageValue(Storage.seis) >= seis +1 then
print(' (sete)')
end
         
        

    return true
end
in case the 'seven' has 11 in the storage most even so the normal is running the correct would run the seven direct
I'm still breaking my head on this, someone has some idea

trying to make a voting system the one who had the most votes will be created

exemple
 
Last edited:

Xikini

I whore myself out for likes
Premium User
Joined
Nov 17, 2010
Messages
4,172
Best answers
174
Reaction score
2,234
This should be a good code block to start from.

You just need a way for people to cast a vote for the global storages.

I green texted it a bit, to help you along.
Lua:
local global_map_storages = {
    {45001, "thais"},
    {45002, "carlin"},
    {45003, "ab'dendriel"},
    {45004, "venore"},
    {45005, "kazordoon"}
}

function onThink(interval)
    local vote_count, maps = 0, "" -- will hold information to be used later in script.
    for i = 1, #global_map_storages do -- will loop through the main table above. (going down the list 1 by 1)
        local temp_count = getGlobalStorageValue(global_map_storages[i][1]) -- finds the current value of a global storage in the above table.
        if vote_count ~= 0 and temp_count == vote_count then -- if the global storage is equal to the current 'maximum' votes...
            if maps ~= "" then
                maps = maps .. ", " -- adds a comma to separate multiple cities
            end
            maps = maps .. global_map_storages[i][2] -- stores the city name for later use, along with previous city names.
        elseif temp_count > vote_count then -- if the global storage is greater then the current 'maximum' votes...
            vote_count = temp_count -- update the highest vote total
            maps = global_map_storages[i][2] -- update the current map 'selected'
        end
        setGlobalStorageValue(global_map_storages[i][1], -1) -- reset the global storage, so votes can be cast again
    end
    if maps == "" then -- if no votes were cast, then no city was selected, so update text to advise.
        maps = "not enough votes to choose a map"
    end
    print("vote_count = " .. vote_count .. " | maps = " .. maps .. "") -- print to console the highest vote found, and the city or cities that held the highest amount.
    return true
end
-- edit, here's a vote random talkaction for you to test with.
Lua:
-- <talkaction access="0" words="/voteRandom" event="script" value="voteRandom.lua" />

local global_map_storages = {
    {45001, "thais"},
    {45002, "carlin"},
    {45003, "ab'dendriel"},
    {45004, "venore"},
    {45005, "kazordoon"}
}

function onSay(cid, words, param, channel)
    local rand = math.random(#global_map_storages)
    local storage = getGlobalStorageValue(global_map_storages[rand][1])
    if storage < 1 then
        storage = 1
    else
        storage = storage + 1
    end
    setGlobalStorageValue(global_map_storages[rand][1], storage)
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You've voted for " .. global_map_storages[rand][2] .. ". The new vote total is " .. storage .. ".")
    return true
end
 
Last edited:
OP
T

theduck

Member
Joined
Dec 6, 2018
Messages
114
Best answers
0
Reaction score
14
This should be a good code block to start from.

You just need a way for people to cast a vote for the global storages.

I green texted it a bit, to help you along.
Lua:
local global_map_storages = {
    {45001, "thais"},
    {45002, "carlin"},
    {45003, "ab'dendriel"},
    {45004, "venore"},
    {45005, "kazordoon"}
}

function onThink(interval)
    local vote_count, maps = 0, "" -- will hold information to be used later in script.
    for i = 1, #global_map_storages do -- will loop through the main table above. (going down the list 1 by 1)
        local temp_count = getGlobalStorageValue(global_map_storages[i][1]) -- finds the current value of a global storage in the above table.
        if vote_count ~= 0 and temp_count == vote_count then -- if the global storage is equal to the current 'maximum' votes...
            if maps ~= "" then
                maps = maps .. ", " -- adds a comma to separate multiple cities
            end
            maps = maps .. global_map_storages[i][2] -- stores the city name for later use, along with previous city names.
        elseif temp_count > vote_count then -- if the global storage is greater then the current 'maximum' votes...
            vote_count = temp_count -- update the highest vote total
            maps = global_map_storages[i][2] -- update the current map 'selected'
        end
        setGlobalStorageValue(global_map_storages[i][1], -1) -- reset the global storage, so votes can be cast again
    end
    if maps == "" then -- if no votes were cast, then no city was selected, so update text to advise.
        maps = "not enough votes to choose a map"
    end
    print("vote_count = " .. vote_count .. " | maps = " .. maps .. "") -- print to console the highest vote found, and the city or cities that held the highest amount.
    return true
end
-- edit, here's a vote random talkaction for you to test with.
Lua:
-- <talkaction access="0" words="/voteRandom" event="script" value="voteRandom.lua" />

local global_map_storages = {
    {45001, "thais"},
    {45002, "carlin"},
    {45003, "ab'dendriel"},
    {45004, "venore"},
    {45005, "kazordoon"}
}

function onSay(cid, words, param, channel)
    local rand = math.random(#global_map_storages)
    local storage = getGlobalStorageValue(global_map_storages[rand][1])
    if storage < 1 then
        storage = 1
    else
        storage = storage + 1
    end
    setGlobalStorageValue(global_map_storages[rand][1], storage)
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You've voted for " .. global_map_storages[rand][2] .. ". The new vote total is " .. storage .. ".")
    return true
end
I can not mark your response as the best.
It helped me a lot.
 
OP
T

theduck

Member
Joined
Dec 6, 2018
Messages
114
Best answers
0
Reaction score
14
This should be a good code block to start from.

You just need a way for people to cast a vote for the global storages.

I green texted it a bit, to help you along.
Lua:
local global_map_storages = {
    {45001, "thais"},
    {45002, "carlin"},
    {45003, "ab'dendriel"},
    {45004, "venore"},
    {45005, "kazordoon"}
}

function onThink(interval)
    local vote_count, maps = 0, "" -- will hold information to be used later in script.
    for i = 1, #global_map_storages do -- will loop through the main table above. (going down the list 1 by 1)
        local temp_count = getGlobalStorageValue(global_map_storages[i][1]) -- finds the current value of a global storage in the above table.
        if vote_count ~= 0 and temp_count == vote_count then -- if the global storage is equal to the current 'maximum' votes...
            if maps ~= "" then
                maps = maps .. ", " -- adds a comma to separate multiple cities
            end
            maps = maps .. global_map_storages[i][2] -- stores the city name for later use, along with previous city names.
        elseif temp_count > vote_count then -- if the global storage is greater then the current 'maximum' votes...
            vote_count = temp_count -- update the highest vote total
            maps = global_map_storages[i][2] -- update the current map 'selected'
        end
        setGlobalStorageValue(global_map_storages[i][1], -1) -- reset the global storage, so votes can be cast again
    end
    if maps == "" then -- if no votes were cast, then no city was selected, so update text to advise.
        maps = "not enough votes to choose a map"
    end
    print("vote_count = " .. vote_count .. " | maps = " .. maps .. "") -- print to console the highest vote found, and the city or cities that held the highest amount.
    return true
end
-- edit, here's a vote random talkaction for you to test with.
Lua:
-- <talkaction access="0" words="/voteRandom" event="script" value="voteRandom.lua" />

local global_map_storages = {
    {45001, "thais"},
    {45002, "carlin"},
    {45003, "ab'dendriel"},
    {45004, "venore"},
    {45005, "kazordoon"}
}

function onSay(cid, words, param, channel)
    local rand = math.random(#global_map_storages)
    local storage = getGlobalStorageValue(global_map_storages[rand][1])
    if storage < 1 then
        storage = 1
    else
        storage = storage + 1
    end
    setGlobalStorageValue(global_map_storages[rand][1], storage)
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You've voted for " .. global_map_storages[rand][2] .. ". The new vote total is " .. storage .. ".")
    return true
end
another thing is that it is possible to put a minimum amount of votes for each storage

exemple
{45001, "thais"}, 100 votes
{45002, "carlin"}, 50 votes
{45003, "ab'dendriel"}, 10 votes
{45004, "venore"}, 15 votes
{45005, "kazordoon"} 5 votes
 

Xikini

I whore myself out for likes
Premium User
Joined
Nov 17, 2010
Messages
4,172
Best answers
174
Reaction score
2,234
another thing is that it is possible to put a minimum amount of votes for each storage

exemple
{45001, "thais"}, 100 votes
{45002, "carlin"}, 50 votes
{45003, "ab'dendriel"}, 10 votes
{45004, "venore"}, 15 votes
{45005, "kazordoon"} 5 votes
Yeah just change
{45001, "thais", 100}
And line 17
storage = storage + global_map_storages[rand][3]
 

Xikini

I whore myself out for likes
Premium User
Joined
Nov 17, 2010
Messages
4,172
Best answers
174
Reaction score
2,234
OP
T

theduck

Member
Joined
Dec 6, 2018
Messages
114
Best answers
0
Reaction score
14
lua:19: attempt to compare number with string
stack traceback:

elseif temp_count > vote_count then -- if the global storage is greater then the current 'maximum' votes...

---

storage = storage + global_map_storages[rand][3]
put in the place of the line
maps = maps .. global_map_storages[2] -- stores the city name for later use, along with previous city names.
 
Top