Action Shop lever rand

Avios

New Member
Joined
Dec 26, 2009
Messages
8
Best answers
0
Reaction score
0
Hello.

Script is when you press the lever we buy a item but not as what we want just a random item.

Data/actions/script/NAME_SCRIPTS.lua
PHP:
function onUse(cid, item, frompos, item2, topos)
local item = {
      id = 2130,  -- id1 itemka
      id2 = XXXX,  -- id2 itemka
      id3 = XXXX  -- id3 itemka
}
local money = 4000
local rand = math.random(1, #item)
    if item.itemid == 1945 then
        if(doPlayerRemoveMoney(cid, money) == TRUE) then
            doPlayerAddItem(cid, item[rand])
            doPlayerSendTextMessage(cid, 22, "Brought ".. item.name ..".")
    elseif item.itemid == 1946 then
                if(doPlayerRemoveMoney(cid, money) == TRUE) then
                    doPlayerAddItem(cid, item[rand])
                    doPlayerSendTextMessage(cid, 22, "Brought ".. item.name ..".")
                end
        end
    end
    return TRUE
end
Data/actions.xml
PHP:
    <action uniqueid="1234" event="script" value="NAME_SCRIPTS.lua"/>
 
Last edited:
OP
A

Avios

New Member
Joined
Dec 26, 2009
Messages
8
Best answers
0
Reaction score
0
i don't know ;d
 

chojrak

Banned User
Joined
Oct 25, 2008
Messages
5,832
Best answers
2
Reaction score
158
You can use it as "lottery". ;d
 

Luciano

Member
Joined
Feb 18, 2010
Messages
998
Best answers
0
Reaction score
24
Whow to make it like... there are 2 slots (like this image)

1 g ingot = 100 golg nugets / 1 gold nuget = 100cc
And, if the player get X iten, he get a broadcast "Playername is to lucky to win itenX from lotery.
 

Luciano

Member
Joined
Feb 18, 2010
Messages
998
Best answers
0
Reaction score
24
he put 1 gold ingot OR 100 golden nugets in the lower basin, and use the switch and he win a random iten in the up one
 

Sir Shutter

Learning LUA
Joined
Nov 17, 2008
Messages
1,437
Best answers
0
Reaction score
10
Location
Egypt
The one who give him the script, its not a good idea for sharing other servers scripts, make your own server instead of taking other people ideas + requesting it, atleast make it your self.
 

dragonlorde

New Member
Joined
Jan 2, 2010
Messages
14
Best answers
0
Reaction score
0
There is some inecessary things like:
In your script:
function onUse(cid, item, frompos, item2, topos) = function onUse(cid, item) '-'
Obs:
if item.itemid == 1945 then
if(doPlayerRemoveMoney(cid, money) == TRUE) then

Second if is inecessary '-'
If your server is 8.54 you can use this...

if item.itemid == 1945 and getPlayerMoney(cid) >= money then
doPlayerRemoveMoney(cid, money)


You can reduce that script man...
Don't take it like a critic... just take it like little help to the evolution...
 

Ancores

Active Member
Joined
Jan 17, 2010
Messages
538
Best answers
0
Reaction score
27
There is some inecessary things like:
In your script:
function onUse(cid, item, frompos, item2, topos) = function onUse(cid, item) '-'
Obs:
if item.itemid == 1945 then
if(doPlayerRemoveMoney(cid, money) == TRUE) then

Second if is inecessary '-'
If your server is 8.54 you can use this...

if item.itemid == 1945 and getPlayerMoney(cid) >= money then
doPlayerRemoveMoney(cid, money)


You can reduce that script man...
Don't take it like a critic... just take it like little help to the evolution...
It works and it's shorter with if doPlayerRemoveMoney(cid, money).
 

calum69

New Member
Joined
Aug 12, 2007
Messages
346
Best answers
0
Reaction score
3
Location
Great Britain
On Call Of Duty 5 I bought random weapons on Zombie mode xD
Yeah ive recently mapped a custom replica of der reise with scripts for electrical fences and all mainframes, il use this for the random weapon box, so it is useful there are some screens of the map in map showoff on another site that people use
 

YugiNao

Banned User
Joined
Nov 22, 2008
Messages
211
Best answers
0
Reaction score
3
script not work D:

Code:
[29/04/2010 17:24:30] [Error - Action Interface] 
[29/04/2010 17:24:30] data/actions/scripts/other/random item.lua:onUse
[29/04/2010 17:24:30] Description: 
[29/04/2010 17:24:30] data/actions/scripts/other/random item.lua:8: bad argument #2 to 'random' (interval is empty)
[29/04/2010 17:24:30] stack traceback:
[29/04/2010 17:24:30] 	[C]: in function 'random'
Help please.
 
Last edited:
Top