SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 06/07/2012, 10:21 AM   #281
iggy1
High-roller
 
iggy1's Avatar
 
Join Date: Mar 2009
Location: One past the end.
Posts: 2,384
Reputation: 235
Default Re: General Reference

I recently read this thread http://forum.sa-mp.com/showthread.php?t=356637.

And i thought it might be useful to have a database with all valid objectids in it. You can also add your own ids to the database easily if you have created your own objects.

I created it from the valid_model array from the pastebin link in that thread. So credits go to whoever made that. It was posted by guest. http://pastebin.com/xgMrfNNK

Here's the database

Valid object database (should go in scriptfiles folder): https://dl.dropbox.com/u/76608104/valid_objects.db

So you can do normal sqlite queries with the database.

Eg,
pawn Code:
db_IsValidObject(objectid)
{

    new
        szBuffer[64],
        DBResult: dbrResult,
        DB: db_ValidObjects = db_open("valid_objects.db");
   
    format(szBuffer, sizeof(szBuffer), "SELECT null FROM objects WHERE objectid=%d", objectid);
   
    dbrResult = db_query(db_ValidObjects, szBuffer);
   
    if(db_num_rows(dbrResult))
    {
        db_free_result(dbrResult);
        db_close(db_ValidObjects);
        return 1;
    }
    db_free_result(dbrResult);
    db_close(db_ValidObjects);
    return 0;
}

EDIT: I posted the created database because it takes a while to generate. I think it took about 30 seconds on my PC.

This was how it was created.
pawn Code:
new
    szBuffer[64],
    DB: db_ValidObjects = db_open("valid_objects.db");

db_query(db_ValidObjects, "CREATE TABLE IF NOT EXISTS objects (objectid INTEGER)");

for(new i=0; i < sizeof(valid_model); ++i)
{
    format(szBuffer, sizeof(szBuffer), "INSERT INTO objects VALUES (%d)", valid_model[i]);
    db_query(db_ValidObjects, szBuffer);
}

db_close(db_ValidObjects);

Wasn't sure whether to post here or snippets, i thought here would be better because its a DB not code.
__________________
Quote:
Originally Posted by Y_Less
That code compiles perfectly, but I can tell you now it won't make me a cup of tea.
"No offense, but you are a stupid asshole." - Ron Burgundy

Last edited by iggy1; 06/07/2012 at 10:55 AM.
iggy1 is offline   Reply With Quote
Old 06/07/2012, 02:16 PM   #282
Stylock
Huge Clucker
 
Stylock's Avatar
 
Join Date: Dec 2010
Posts: 343
Reputation: 137
Default Re: General Reference

Why not use the compressed array by Slice? He wrote a PHP code, which you can run after every SA-MP update to fetch all valid object models from GTASA directory.
Stylock is offline   Reply With Quote
Old 06/07/2012, 02:25 PM   #283
iggy1
High-roller
 
iggy1's Avatar
 
Join Date: Mar 2009
Location: One past the end.
Posts: 2,384
Reputation: 235
Default Re: General Reference

Not sure how to use it TBH.
__________________
Quote:
Originally Posted by Y_Less
That code compiles perfectly, but I can tell you now it won't make me a cup of tea.
"No offense, but you are a stupid asshole." - Ron Burgundy
iggy1 is offline   Reply With Quote
Old 06/07/2012, 03:54 PM   #284
Stylock
Huge Clucker
 
Stylock's Avatar
 
Join Date: Dec 2010
Posts: 343
Reputation: 137
Default Re: General Reference

Quote:
Originally Posted by iggy1 View Post
Not sure how to use it TBH.
You can run it offline on WAMP Server. After you've installed it, open wamp folder, then open www folder and create a project folder. Paste php file in your project folder and run in the browser with localhost/project_folder/filename.php (URL). Though I'm not sure if Slice's code works as it gives me parse error on line 56 when I try to run it (I'm newbie in PHP).
Stylock is offline   Reply With Quote
Old 06/07/2012, 04:13 PM   #285
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 18,330
Reputation: 2584
Default Re: General Reference

That's got to be VASTLY slower than an O(1) bit check!
Y_Less is offline   Reply With Quote
Old 06/07/2012, 04:46 PM   #286
iggy1
High-roller
 
iggy1's Avatar
 
Join Date: Mar 2009
Location: One past the end.
Posts: 2,384
Reputation: 235
Default Re: General Reference

Quote:
Originally Posted by Y_Less View Post
That's got to be VASTLY slower than an O(1) bit check!
Definitely. I thought i might have been useful. (not so much now)

The thread i linked has been updated with a much better method to check if an object is valid. I don't understand how it works yet but i suppose i don't need to in order to use it.
__________________
Quote:
Originally Posted by Y_Less
That code compiles perfectly, but I can tell you now it won't make me a cup of tea.
"No offense, but you are a stupid asshole." - Ron Burgundy
iggy1 is offline   Reply With Quote
Old 07/07/2012, 12:03 AM   #287
JoBullet
Big Clucker
 
Join Date: Mar 2012
Posts: 66
Reputation: 65
Default Re: General Reference

To whom may it concern, note that these constructs are perfectly legal (though I do not know if it would be sane to use them, just general info, these are both deprecated and obsolete AFAIK):
Code:
if expression *then expression
if expression *then { expression }
// note that
// if ( expression ) *then expression
// is not valid
// --------------------------------
// you can also use *begin and *end instead of braces but then you must have *then preceeding them
if expression *then
*begin
    expression
*end
if expression *then *begin expression *end
// note that this kind of construct also can't make use of parentheses
// this is invalid: if ( expression ) *then *begin expression *end

Last edited by JoBullet; 07/07/2012 at 01:01 AM.
JoBullet is offline   Reply With Quote
Old 07/07/2012, 05:58 PM   #288
Kar
High-roller
 
Join Date: May 2010
Location: Black Asylum
Posts: 2,896
Reputation: 286
Default Re: General Reference

In vehicle Mouse Wheel Detection

pawn Code:
#define KEY_MOUSE_SCROLL_CLICK  (320) // VEHICLE ONLY

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newkeys == 320)
    {
        SendClientMessage(playerid, -1, "Mouse-click.");
    }
    return 1;
}

KEY_CTRL_BACK is used to detect mouse wheel scrolling backwards in vehicle
__________________

  • Twisted Metal's Website & Forums are up! http://tm.lvcnr.net

    Are you prepared to get your wish? Twisted Metal SA-MP is coming soon! Join the IRC Channel: #tm on irc.tl - @tmsamp_dev

server.lvcnr.net:7777 | samp://server.lvcnr.net:7777
www.lvcnr.net | @kcnrdev
Channel: #lvcnr on irc.tl
Kar is offline   Reply With Quote
Old 21/08/2012, 12:30 AM   #289
detter
Big Clucker
 
Join Date: Dec 2010
Posts: 154
Reputation: 10
Default Re: General Reference

Need time machine to go few hours back!
my whole RP mode ( i was still working on it) with 6k+ lines disapired
DAMN!!!!
days of scripting ,designing ,mapping :/

is there way to convert .amx to .pwn
detter is offline   Reply With Quote
Old 21/08/2012, 08:47 AM   #290
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 18,330
Reputation: 2584
Default Re: General Reference

Quote:
Originally Posted by Kar View Post
In vehicle Mouse Wheel Detection

pawn Code:
#define KEY_MOUSE_SCROLL_CLICK  (320) // VEHICLE ONLY

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newkeys == 320)
    {
        SendClientMessage(playerid, -1, "Mouse-click.");
    }
    return 1;
}

KEY_CTRL_BACK is used to detect mouse wheel scrolling backwards in vehicle
SA:MP doesn't use defined keys, so this will detect whatever function you have assigned to the mouse wheel, not the mouse wheel itself. This also seems odd because 320 is not a power of two like the other keys, it is a combination of 256 and 64.
Y_Less is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to make a soldier aotumaticly be general when the general dies ? AlbanianGuy Scripting Help 35 13/05/2012 03:35 PM
Help general [ZX]_Whitewolf Help Archive 0 15/06/2010 11:04 PM
A Full Pawn Reference Jonni8 General 4 20/05/2010 10:35 PM
Team Balancer -(Fixed but someone might want to read for reference) [HLF]Southclaw Help Archive 4 26/01/2010 08:24 AM
[SOLVED!] Strings as reference parameters... XPlatform Plugin Development 4 23/08/2009 10:40 PM


All times are GMT. The time now is 01:29 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.