Booo

تحت التطوير :كود - Useful Arab functions

Recommended Posts

Posted (edited)

setTableReverse
 

function setTableReverse(_table_,nim)
    local t = {}
    for i , v in pairs(_table_)do
        if nim then
            t[nim[i]] = i
        else
            t[v] = i
        end
    end
    return t
end

example :
@Live اذا مامنعت تعديل بسيط على الوظيفة

local skinsTable = {
[0] = "CJ", [1] = "Truth", [2] = "Maccer", [7] = "Casual JeanJacket", [9] = "Business Lady",
[10] = "Old Fat Lady", [11] = "Card Dealer 1", [12] = "Classy Gold Hooker", [13] = "Homegirl", [14] = "Floral Shirt",
[15] = "Plaid Baldy", [16] = "Earmuff Worker", [17] = "Black suit", [18] = "Black Beachguy", [19] = "Beach Gangsta",
[20] = "Fresh Prince", [21] = "Striped Gangsta", [22] = "Orange Sportsman", [23] = "Skater Kid", [24] = "LS Coach",
[25] = "Varsity jacket", [26] = "Hiker", [27] = "Construction 1", [28] = "Black Dealer", [29] = "White Dealer",
[30] = "Religious Essey", [31] = "Fat Cowgirl", [32] = "Eyepatch", [33] = "Bounty Hunter", [34] = "Marlboro Man",
[35] = "Fisherman", [36] = "Mailman", [37] = "Baseball Dad", [38] = "Old Golf Lady", [39] = "Old Maid",
[40] = "Classy Dark Hooker", [41] = "Tracksuit Girl", [43] = "Porn Producer", [44] = "Tatooed Plaid", [45] = "Beach Mustache",
[46] = "Dark Romeo", [47] = "Top Button Essey", [49] = "Ninja Sensei", [50] = "Mechanic", [51] = "Black Bicyclist",
[52] = "White Bicyclist", [53] = "Golf Lady", [54] = "Hispanic Woman", [55] = "Rich Bitch", [56] = "Legwarmers 1",
[57] = "Chinese Businessman", [58] = "Chinese Plaid", [59] = "Chinese Romeo", [60] = "Chinese Casual", [61] = "Pilot",
[62] = "Pajama Man 1", [63] = "Trashy Hooker", [64] = "Transvestite", [66] = "Varsity Bandits", [67] = "Red Bandana",
[68] = "Preist", [69] = "Denim Girl", [70] = "Scientist", [71] = "Security Guard", [72] = "Bearded Hippie",
[73] = "Flag Bandana", [75] = "Skanky Hooker", [76] = "Businesswoman 1", [77] = "Bag Lady", [78] = "Homeless Scarf",
[79] = "Fat Homeless", [80] = "Red Boxer", [81] = "Blue Boxer", [82] = "Fatty Elvis", [83] = "Whitesuit Elvis",
[84] = "Bluesuit Elvis", [85] = "Furrcoat Hooker", [87] = "Firecrotch", [88] = "Casual Old Lady", [89] = "Cleaning Lady",
[90] = "Barely Covered", [91] = "Sharon Stone", [92] = "Rollergirl", [93] = "Hoop Earrings 1", [94] = "Andy Capp",
[95] = "Poor Old Man", [96] = "Soccer Player", [97] = "Baywatch Dude", [99] = "Rollerguy", [100] = "Biker Blackshirt",
[101] = "Jacker Hippie", [102] = "Baller Shirt", [103] = "Baller Jacket", [104] = "Baller Sweater", [105] = "Grove Sweater",
[106] = "Grove Tropbutton", [107] = "Grove Jersey", [108] = "Vagos Topless", [109] = "Vagos Pants", [110] = "Vagos Shorts",
[111] = "Russian Muscle", [112] = "Russian Hitman", [113] = "Russian Boss", [114] = "Aztecas Stripes", [115] = "Aztecas Jacket",
[116] = "Aztecas Shorts", [117] = "Triad 1", [118] = "Triad 2", [119] = "Triad 3", [120] = "Sinacco Suit",
[121] = "Da Nang Army", [122] = "Da Nang Bandana", [123] = "Da Nang Shades", [124] = "Sinacco Muscle", [125] = "Mafia Enforcer",
[126] = "Mafia Wiseguy", [127] = "Mafia Hitman", [128] = "Native Rancher", [129] = "Native Librarian", [130] = "Native Ugly",
[131] = "Native Sexy", [132] = "Native Geezer", [133] = "Furys Trucker", [134] = "Homeless Smoker", [135] = "Skullcap Hobo",
[136] = "Old Rasta", [137] = "Boxhead", [138] = "Bikini Tattoo", [139] = "Yellow Bikini", [140] = "Buxom Bikini",
[141] = "Cute Librarian", [142] = "African 1", [143] = "Sam Jackson", [144] = "Drug Worker 1", [145] = "Drug Worker 2",
[146] = "Drug Worker 3", [147] = "Sigmund Freud", [148] = "Businesswoman 2", [149] = "Businesswoman 2 b", [150] = "Businesswoman 3",
[151] = "Melanie", [152] = "Schoolgirl 1", [153] = "Foreman", [154] = "Beach Blonde", [155] = "Pizza Guy",
[156] = "Old Reece", [157] = "Farmer Girl", [158] = "Farmer", [159] = "Farmer Redneck", [160] = "Bald Redneck",
[161] = "Smoking Cowboy", [162] = "Inbred", [163] = "Casino Bouncer 1", [164] = "Casino Bouncer 2", [165] = "Agent Kay",
[166] = "Agent Jay", [167] = "Chicken", [168] = "Hotdog Vender", [169] = "Asian Escort", [170] = "PubeStache Tshirt",
[171] = "Card Dealer 2", [172] = "Card Dealer 3", [173] = "Rifa Hat", [174] = "Rifa Vest", [175] = "Rifa Suspenders",
[176] = "Style Barber", [177] = "Vanilla Ice Barber", [178] = "Masked Stripper", [179] = "War Vet", [180] = "Bball Player",
[181] = "Punk", [182] = "Pajama Man 2", [183] = "Klingon", [184] = "Neckbeard", [185] = "Nervous Guy",
[186] = "Teacher", [187] = "Japanese Businessman 1", [188] = "Green Shirt", [189] = "Valet", [190] = "Barbara Schternvart",
[191] = "Helena Wankstein", [192] = "Michelle Cannes", [193] = "Katie Zhan", [194] = "Millie Perkins", [195] = "Denise Robinson",
[196] = "Aunt May", [197] = "Smoking Maid", [198] = "Ranch Cowgirl", [199] = "Heidi", [200] = "Hairy Redneck",
[201] = "Trucker Girl", [202] = "Beer Trucker", [203] = "Ninja 1", [204] = "Ninja 2", [205] = "Burger Girl",
[206] = "Money Trucker", [207] = "Grove Booty", [209] = "Noodle Vender", [210] = "Sloppy Tourist", [211] = "Staff Girl",
[212] = "Tin Foil Hat", [213] = "Hobo Elvis", [214] = "Caligula Waitress", [215] = "Explorer", [216] = "Turtleneck",
[217] = "Staff Guy", [218] = "Old Woman", [219] = "Lady In Red", [220] = "African 2", [221] = "Beardo Casual",
[222] = "Beardo Clubbing", [223] = "Greasy Nightclubber", [224] = "Elderly Asian 1", [225] = "Elderly Asian 2", [226] = "Legwarmers 2",
[227] = "Japanese Businessman 2", [228] = "Japanese Businessman 3", [229] = "Asian Tourist", [230] = "Hooded Hobo", [231] = "Grannie",
[232] = "Grouchy lady", [233] = "Hoop Earrings 2", [234] = "Buzzcut", [235] = "Retired Tourist", [236] = "Happy Old Man",
[237] = "Leopard Hooker", [238] = "Amazon", [240] = "Hugh Grant", [241] = "Afro Brother", [242] = "Dreadlock Brother",
[243] = "Ghetto Booty", [244] = "Lace Stripper", [245] = "Ghetto Ho", [246] = "Cop Stripper", [247] = "Biker Vest",
[248] = "Biker Headband", [249] = "Pimp", [250] = "Green Tshirt", [251] = "Lifeguard", [252] = "Naked Freak",
[253] = "Bus Driver", [254] = "Biker Vest b", [255] = "Limo Driver", [256] = "Shoolgirl 2", [257] = "Bondage Girl",
[258] = "Joe Pesci", [259] = "Chris Penn", [260] = "Construction 2", [261] = "Southerner", [262] = "Pajama Man 2 b",
[263] = "Asian Hostess", [264] = "Whoopee the Clown", [265] = "Tenpenny", [266] = "Pulaski", [267] = "Hern",
[268] = "Dwayne", [269] = "Big Smoke", [270] = "Sweet", [271] = "Ryder", [272] = "Forelli Guy",
[274] = "Medic 1", [275] = "Medic 2", [276] = "Medic 3", [277] = "Fireman LS", [278] = "Fireman LV",
[279] = "Fireman SF", [280] = "Cop 1", [281] = "Cop 2", [282] = "Cop 3", [283] = "Cop 4",
[284] = "Cop 5", [285] = "SWAT", [286] = "FBI", [287] = "Army", [288] = "Cop 6",
[290] = "Rose", [291] = "Kent Paul", [292] = "Cesar", [293] = "OG Loc", [294] = "Wuzi Mu",
[295] = "Mike Toreno", [296] = "Jizzy", [297] = "Madd Dogg", [298] = "Catalina", [299] = "Claude from GTA 3",
[300] = "Ryder", [301] = "Ryder Robber", [302] = "Emmet", [303] = "Andre", [304] = "Kendl",
[305] = "Jethro", [306] = "Zero", [307] = "T-bone Mendez", [308] = "Sindaco Guy", [309] = "Janitor",
[310] = "Big Bear", [311] = "Big Smoke with Vest", [312] = "Physco", 
}
function getSkinNameFromID(i)
    local id = tonumber (i)
        assert(id, "Bad argument 1 @ getSkinNameFromID [Number expected, got "..type(i).."]")
    local name = skinsTable[id]
        assert(name,"Bad argument 1 @ getSkinNameFromID [Invaild skin ID]")
    return name 
end

function getSkinIDFromName(name)
    assert( type(name) == "string","Bad argument 1 @ getSkinIDFromName [String expected, got " .. type(name) .. "]")
    return setTableReverse(skinsTable)[name:lower()] or false 
end

example 2 :

local t1 = { ['pop'] = 'admin',['issam'] = 'player',['sld'] = 'mod'}
  
  
  
function getPlayerRank(player)
      return t1[player]
end

function getRankPlayer(rank)
    return   setTableReverse(t1)[rank]
end
  

print(getPlayerRank('pop'),getRankPlayer('admin')) --- OUTPUT : admin     pop

 

Edited by #Mr.Pop

Share this post


Link to post
23 minutes ago, #Mr.Pop said:

@Live اذا مامنعت تعديل بسيط على الوظيفة

جميل

لكن يلي مخليني اعدل جدول حق الفنكشن الثاني عشان احوله كله سمول
 عشان يوم تجيب ايدي السكن من اسمه مايكون حساس للكبتل والسمول

 

Share this post


Link to post
2 minutes ago, Live said:

حق الفنكشن الثاني عشان احوله كله سمول
 عشان يوم تجيب ايدي السكن من اسمه مايكون حساس للكبتل والسمول

  1. return setTableReverse(skinsTable)[name:lower()] or false
    يب كودوك موجود نفسه  بس ضفت فكشن الي يعكس
    يعني الحين نفس الشيئ يجبيب سكين حتى لو كان كلو كابتلو اوسمول

Share this post


Link to post
51 minutes ago, #Mr.Pop said:
  1. 
    return setTableReverse(skinsTable)[name:lower()] or false
    يب كودوك موجود نفسه  بس ضفت فكشن الي يعكس
    يعني الحين نفس الشيئ يجبيب سكين حتى لو كان كلو كابتلو اوسمول

مافهمت قصدي

الكود يحول الارقمنت لسمول لكن الجدول لازم يكون ايضًا سمول ولا ماراح يقدر يجيب

الحين لو استعملت الفنكشن بتعديلك

وحاولت تجيب "CJ"

ارقمنت نيم بالكود راح يحوله لسمول

بيصير "cj"

["CJ"]  بيبحث بالجدول ماراح يلقاه لان اسمه بالجدول يلي دامجه

عشان كذا الفنكشن الثاني الجدول كله محوله لسمول ومختلف عن الجدول حق الفنكشن الأول

 

Share this post


Link to post
2 hours ago, Live said:

عشان

eazy 

just use this

3 hours ago, #Mr.Pop said:

الحين

    
function sFUpper(s)
  if s:lower == "cj" then return "CJ" end
  local ta = {}
  for word in s:gmatch("%w+") do
	 table.insert( ta , word:gsub("^%l", string.upper).." " )
  end
  return table.concat(ta)
end

print(sFUpper("my Frist char upper"))
-- My First Char Upper

جربوه لاني ما جربته صراحة

لكن توقعي انه بيظبط بيختصر الموضوع مره عليكم

Share this post


Link to post
8 hours ago, Master_MTA said:

eazy 

just use this


    function sFUpper(s)  if s:lower == "cj" then return "CJ" end  local ta = {}  for word in s:gmatch("%w+") do	 table.insert( ta , word:gsub("^%l", string.upper).." " )  end  return table.concat(ta)endprint(sFUpper("my Frist char upper"))-- My First Char Upper

جربوه لاني ما جربته صراحة

لكن توقعي انه بيظبط بيختصر الموضوع مره عليكم

تـصحيح بسيط 
OLD

if s:lower == "cj" then return "CJ" end

NEW  :  lower() --- > '(  )'

if s:lower() == "cj" then return "CJ" end

 

Share this post


Link to post
1 hour ago, #Mr.Pop said:

if s:lower() == "cj" then return "CJ" end

 

جيد

لكن الفكره كلها اني ما حطيته كذا من الاول لاجل ان الفنكشن ذا خاص

للفنكشن حقك تمام ممتاز التعديل

  • Like 1

Share this post


Link to post
Posted (edited)
function getPositionBackOfElement(element, meters)
    if (not element or not isElement(element)) then return false end
    local meters = (type(meters) == "number" and meters) or 3
    local posX, posY, posZ = getElementPosition(element)
    local _, _, rotation = getElementRotation(element)
    posX = posX + math.sin(math.rad(rotation)) * meters
    posY = posY - math.cos(math.rad(rotation)) * meters
    rot = rotation - math.cos(math.rad(rotation))
    return posX, posY, posZ , rot
end
function getPositionFrontOfElement(element, meters)
    if (not element or not isElement(element)) then return false end
    local meters = (type(meters) == "number" and meters) or 3
    local posX, posY, posZ = getElementPosition(element)
    local _, _, rotation = getElementRotation(element)
    posX = posX - math.sin(math.rad(rotation)) * meters
    posY = posY + math.cos(math.rad(rotation)) * meters
    rot = rotation + math.cos(math.rad(rotation))
    return posX, posY, posZ , rot
end
function isPlayerBehindPlayer( source,player )
    local x,y,z = getElementPosition( source )
    local x1,y1,z1 = getElementPosition( player )
    local cx,cy,cz=getPositionBackOfElement(source, 500)
    local dist = getDistanceBetweenPoints3D( x,y,z,cx,cy,cz )
    local dist1 = getDistanceBetweenPoints3D( x1,y1,z1,cx,cy,cz )
    if dist1<dist then return true end
    return false
end
function isPlayerInFrontPlayer( source,player )
    local x,y,z = getElementPosition( source )
    local x1,y1,z1 = getElementPosition( player )
    local cx,cy,cz=getPositionFrontOfElement(source, 500)
    local dist = getDistanceBetweenPoints3D( x,y,z,cx,cy,cz )
    local dist1 = getDistanceBetweenPoints3D( x1,y1,z1,cx,cy,cz )
    if dist1<dist then return true end
    return false
end

يتحقق اذا كان اللاعب اللي تبي قدام او ورا اللاعب اللي تبي

Edited by Master_MTA
  • Thanks 2

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.